summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-16 05:32:47 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-16 05:32:47 -0800
commitcf0ac2826bc7dc06d3c63e956ec8922a358f4f80 (patch)
tree50063036810b493a2bca9d5892ea992f02d82360 /parser.y
parent704664e60d7d548d9ce5c44b34d0d2b60db1e31c (diff)
downloadtxr-cf0ac2826bc7dc06d3c63e956ec8922a358f4f80.tar.gz
txr-cf0ac2826bc7dc06d3c63e956ec8922a358f4f80.tar.bz2
txr-cf0ac2826bc7dc06d3c63e956ec8922a358f4f80.zip
Start of fallback package list implementation.
* eval.c (eval_init): Register package-fallback-list and set-package-fallback-list intrinsics. * lib.c (package_fallback_list, set_package_fallback_list, intern_fallback): New functions * lib.h (package_fallback_list, set_package_fallback_list, intern_fallback): Declared. * parser.y (sym_helper): Slightly restructure function so that the symbol interning is done separately in the various cases. In the unqualified symbol case, use intern_fallback to search the fallback list of the current package. * share/txr/stdlib/package.tl (defpackage): Implement :fallback clause.
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y20
1 files changed, 10 insertions, 10 deletions
diff --git a/parser.y b/parser.y
index 2c1c31c7..e26214a4 100644
--- a/parser.y
+++ b/parser.y
@@ -1249,7 +1249,7 @@ static val sym_helper(parser_t *parser, wchar_t *lexeme, val meta_allowed)
int leading_at = *lexeme == L'@';
wchar_t *tokfree = lexeme;
wchar_t *colon = wcschr(lexeme, L':');
- val sym_name = nil, pkg_name = nil, package = cur_package, sym;
+ val sym;
if (leading_at) {
if (!meta_allowed) {
@@ -1264,32 +1264,32 @@ static val sym_helper(parser_t *parser, wchar_t *lexeme, val meta_allowed)
*colon = 0;
if (colon == lexeme) {
- package = keyword_package_var;
- sym_name = string(colon + 1);
+ val sym_name = string(colon + 1);
scrub_scanner(parser->scanner, SYMTOK, tokfree);
free(tokfree);
+ sym = intern(sym_name, keyword_package_var);
} else if (colon != 0) {
- pkg_name = string(lexeme);
- sym_name = string(colon + 1);
+ val pkg_name = string(lexeme);
+ val sym_name = string(colon + 1);
scrub_scanner(parser->scanner, SYMTOK, tokfree);
free(tokfree);
if (equal(pkg_name, lit("#"))) {
- package = nil;
+ sym = make_sym(sym_name);
} else {
- package = find_package(pkg_name);
+ val package = find_package(pkg_name);
if (!package) {
yyerrorf(scnr, lit("~a:~a: package ~a not found"), pkg_name, sym_name, pkg_name, nao);
return nil;
}
+ sym = intern(sym_name, package);
}
} else {
- sym_name = string(lexeme);
+ val sym_name = string(lexeme);
scrub_scanner(parser->scanner, SYMTOK, tokfree);
free(tokfree);
+ sym = intern_fallback(sym_name, cur_package);
}
- sym = package ? intern(sym_name, package) : make_sym(sym_name);
-
return leading_at ? rl(list(var_s, sym, nao), num(parser->lineno)) : sym;
}