diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-01-25 09:59:40 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-01-25 09:59:40 -0800 |
commit | 11173ced6d65339869fe74fbc9c4452a75e3fe26 (patch) | |
tree | 6c7e21fa0f7ebab6d5b4af9dc960fd96660682be /parser.y | |
parent | 8b4578f295cc022e8bf0bb62d1a8cf8673636f27 (diff) | |
download | txr-11173ced6d65339869fe74fbc9c4452a75e3fe26.tar.gz txr-11173ced6d65339869fe74fbc9c4452a75e3fe26.tar.bz2 txr-11173ced6d65339869fe74fbc9c4452a75e3fe26.zip |
* eval.c (dwim_s): New symbol variable.
(dwim_loc, op_dwim): New static functions.
(op_modplace): Support assignment to dwim forms
with the help of dwim_loc.
(expand_place): Handle dwim places.
(eval_init): Initialize dwim_s. Register dwim operator
in op_table.
* eval.h (dwim_s): Declared.
* lib.c (chr_str, chr_str_set): Allow negative indices to index
backwards from end of string.
(vecref, vecref_l): Allow negative indices to index from
rear of array.
(obj_print, obj_pprint): Render (dwim ...) forms as [...].
* parser.l: Peoduce new METABKT token type for @[,
and '[', ']' tokens.
* parser.y (METABKT): New token. %type declaration for '['.
(list): Support square-bracket style of list, translated
into dwim form.
(meta_expr): Support @[...] variant.
(yybadtoken): Handle METABKT in switch.
* txr.1: Documented [...] syntax and dwim operator.
* txr.vim: Updated.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -77,7 +77,7 @@ static val parsed_spec; %token <val> NUMBER %token <chr> REGCHAR LITCHAR -%token <chr> METAPAR SPLICE +%token <chr> METAPAR METABKT SPLICE %type <val> spec clauses clauses_opt clause %type <val> all_clause some_clause none_clause maybe_clause @@ -93,7 +93,7 @@ static val parsed_spec; %type <val> regterm regclass regclassterm regrange %type <val> strlit chrlit quasilit quasi_items quasi_item litchars %type <chr> regchar -%type <lineno> '(' +%type <lineno> '(' '[' %nonassoc LOW /* used for precedence assertion */ %right IDENT '{' '}' @@ -656,6 +656,8 @@ vector : '#' list { $$ = rlcp(vector_list($2), $2); } list : '(' exprs ')' { $$ = rl($2, num($1)); } | '(' ')' { $$ = nil; } + | '[' exprs ']' { $$ = rl(cons(dwim_s, $2), num($1)); } + | '[' ']' { $$ = rl(cons(dwim_s, nil), num($1)); } | ',' expr { val expr = $2; if (consp(expr) && first(expr) == qquote_s) expr = cons(quote_s, rest(expr)); @@ -668,10 +670,17 @@ list : '(' exprs ')' { $$ = rl($2, num($1)); } $$ = rlcp(list(splice_s, expr, nao), $2); } | '(' error { $$ = nil; yybadtoken(yychar, lit("list expression")); } + | '[' error { $$ = nil; + yybadtoken(yychar, lit("DWIM expression")); } ; meta_expr : METAPAR exprs ')' { $$ = rlcp(cons(expr_s, expand($2)), $2); } + | METABKT exprs ']' { $$ = rlcp(cons(expr_s, + cons(dwim_s, + expand($2))), $2); } | METAPAR ')' { $$ = rl(cons(expr_s, nil), num(lineno)); } + | METABKT ']' { $$ = rl(cons(expr_s, cons(dwim_s, nil)), + num(lineno)); } | METAPAR error { $$ = nil; yybadtoken(yychar, lit("meta expression")); } ; @@ -1054,6 +1063,7 @@ void yybadtoken(int tok, val context) case REGCHAR: problem = lit("regular expression character"); break; case LITCHAR: problem = lit("string literal character"); break; case METAPAR: problem = lit("@("); break; + case METABKT: problem = lit("@["); break; } if (problem != 0) |