diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-03-25 06:57:25 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-03-25 06:57:25 -0700 |
commit | c60f5a54deed7064cb8aa32fb91c684ad049d2d3 (patch) | |
tree | 7f49a16663477c67910e53aae3475e97613e2274 /parser.y | |
parent | 8707c5ecbfc4ceeb1ceb2eb3015ce492bf99636a (diff) | |
download | txr-c60f5a54deed7064cb8aa32fb91c684ad049d2d3.tar.gz txr-c60f5a54deed7064cb8aa32fb91c684ad049d2d3.tar.bz2 txr-c60f5a54deed7064cb8aa32fb91c684ad049d2d3.zip |
Introducing word list literals.
* parser.l (WLIT): New exclusive start state.
Extend lexical grammar to transition to WLIT state upon
the #" or #*" sequence which kicks off a word literal,
and in that state, piecewise lexically analyze the literal,
mostly by borrowing rules from other literals.
* parser.y (WORDS, WSPLICE): New tokens.
(n_exprs): Integrate splicing form of word list literal syntax.
(n_expr): Integrate non-splicit for of word list literal syntax.
(litchars): Propagate line number info.
(wordslit): New grammar rule.
* txr.1: Updated.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -79,6 +79,7 @@ static val parsed_spec; %token <lineno> MOD MODLAST DEFINE TRY CATCH FINALLY %token <lineno> ERRTOK /* deliberately not used in grammar */ %token <lineno> HASH_BACKSLASH HASH_SLASH DOTDOT HASH_H +%token <lineno> WORDS WSPLICE %token <lineno> SECRET_ESCAPE_R SECRET_ESCAPE_E %token <val> NUMBER METANUM @@ -100,7 +101,7 @@ static val parsed_spec; %type <val> o_elems_opt o_elems o_elem o_var rep_elem rep_parts_opt %type <val> regex lisp_regex regexpr regbranch %type <val> regterm regtoken regclass regclassterm regrange -%type <val> strlit chrlit quasilit quasi_items quasi_item litchars +%type <val> strlit chrlit quasilit quasi_items quasi_item litchars wordslit %type <val> not_a_clause %type <chr> regchar %type <lineno> '(' '[' '@' @@ -753,6 +754,9 @@ n_exprs : n_expr { $$ = rlcp(cons($1, nil), $1); } $$ = rlcp(cons(list(cons_s, $1, car($3), nao), cdr($3)), or2($1, $3)); } + | WSPLICE wordslit { $$ = rl($2, num($1)); } + | WSPLICE wordslit + n_exprs { $$ = nappend2(rl($2, num($1)), $3); } ; n_expr : SYMTOK { $$ = sym_helper($1, t); } @@ -768,6 +772,7 @@ n_expr : SYMTOK { $$ = sym_helper($1, t); } | chrlit { $$ = $1; } | strlit { $$ = $1; } | quasilit { $$ = $1; } + | WORDS wordslit { $$ = rl($2, num($1)); } | '\'' n_expr { $$ = rlcp(list(quote_s, $2, nao), $2); } | '^' n_expr { $$ = rlcp(list(sys_qquote_s, $2, nao), $2); } | ',' n_expr { $$ = rlcp(list(sys_unquote_s, $2, nao), $2); } @@ -923,8 +928,17 @@ quasi_item : litchars { $$ = lit_char_helper($1); } | list { $$ = rlcp(cons(expr_s, $1), $1); } ; -litchars : LITCHAR { $$ = cons(chr($1), nil); } - | LITCHAR litchars { $$ = cons(chr($1), $2); } +litchars : LITCHAR { $$ = rl(cons(chr($1), nil), num(lineno)); } + | LITCHAR litchars { $$ = rl(cons(chr($1), $2), num(lineno)); } + ; + +wordslit : '"' { $$ = nil; } + | ' ' wordslit { $$ = $2; } + | '\n' wordslit { $$ = $2; } + | litchars wordslit { val word = lit_char_helper($1); + $$ = rlcp(cons(word, $2), $1); } + | error { $$ = nil; + yybadtoken(yychar, lit("word literal")); } ; not_a_clause : ALL { $$ = make_expr(all_s, nil, num(lineno)); } |