diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-02-03 00:28:01 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-02-03 00:28:01 -0800 |
commit | 442c9efa4b176ff2c4c89a43beac3ea3fad247d4 (patch) | |
tree | 20f0d8545174ed466d2825ea0315a0a7fdb57c50 /parser.y | |
parent | a7d3edcff56ee0faa8355ceaea7bc23c2f2e2aa7 (diff) | |
download | txr-442c9efa4b176ff2c4c89a43beac3ea3fad247d4.tar.gz txr-442c9efa4b176ff2c4c89a43beac3ea3fad247d4.tar.bz2 txr-442c9efa4b176ff2c4c89a43beac3ea3fad247d4.zip |
* eval.c (rest_s, op_s): New variables.
(do_eval_args): Allow calls specified by improper lists
like (x y . z) where the z expression must evaluate to a list
that turns into addition arguments to be applied.
(transform_op, expand_op): New static functions.
(expand): Call expand_op.
(eval_init): Initialize rest_s and op_s. Use rest_s
to register rest function.
* lib.c (gensym): New function based on gensymv.
(gensymv): Now calls gensym.
* lib.h (gensym): Declared.
* parser.l: Parse @ followed by digits as a new kind of token,
METANUM.
* parser.y (METANUM): New token.
(meta_expr, exprs): Missing rlcp's added.
(expr): METANUM variant introduced.
(yybadtoken): Handle METANUM.
* txr.1: Documented one-symbol argument list of lambda.
Documented op. Closed some unbalanced parentheses.
* txr.vim: Highlight op.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -74,7 +74,7 @@ static val parsed_spec; %token <lineno> ERRTOK /* deliberately not used in grammar */ %token <lineno> HASH_BACKSLASH DOTDOT -%token <val> NUMBER +%token <val> NUMBER METANUM %token <chr> REGCHAR LITCHAR %token <chr> METAPAR METABKT SPLICE @@ -677,17 +677,19 @@ list : '(' exprs ')' { $$ = rl($2, num($1)); } meta_expr : METAPAR exprs ')' { $$ = rlcp(cons(expr_s, expand($2)), $2); } | METABKT exprs ']' { $$ = rlcp(cons(expr_s, - expand(cons(dwim_s, $2))), - $2); } + rlcp(expand(cons(dwim_s, $2)), + $2)), + $2); } | METAPAR ')' { $$ = rl(cons(expr_s, nil), num(lineno)); } - | METABKT ']' { $$ = rl(cons(expr_s, cons(dwim_s, nil)), - num(lineno)); } + | METABKT ']' { $$ = rl(cons(expr_s, rl(cons(dwim_s, nil), + num(lineno))), + num(lineno)); } | METAPAR error { $$ = nil; yybadtoken(yychar, lit("meta expression")); } ; -exprs : expr { $$ = cons($1, nil); } - | expr exprs { $$ = cons($1, $2); } - | expr '.' expr { $$ = cons($1, $3); } +exprs : expr { $$ = rlcp(cons($1, nil), $1); } + | expr exprs { $$ = rlcp(cons($1, $2), $1); } + | expr '.' expr { $$ = rlcp(cons($1, $3), $1); } ; exprs_opt : exprs { $$ = $1; } @@ -702,6 +704,8 @@ expr : IDENT { $$ = rl(intern(string_own($1), nil), | METAVAR { $$ = list(var_s, intern(string_own($1), nil), nao); rl($$, num(lineno)); } + | METANUM { $$ = cons(var_s, cons($1, nil)); + rl($$, num(lineno)); } | NUMBER { $$ = $1; } | list { $$ = $1; } | vector { $$ = $1; } @@ -1038,6 +1042,7 @@ void yybadtoken(int tok, val context) case IDENT: problem = lit("identifier"); break; case KEYWORD: problem = lit("keyword"); break; case METAVAR: problem = lit("metavar"); break; + case METANUM: problem = lit("metanum"); break; case ALL: problem = lit("\"all\""); break; case SOME: problem = lit("\"some\""); break; case NONE: problem = lit("\"none\""); break; |