From df70e45dae4adccca01441e0911d2f5e114e8e7f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 17 Nov 2011 21:12:08 -0800 Subject: Adding quote and unquote read syntax to list forms, resembling Lisp. The difference is that splice is spelled ,* because @ already means something, and that there is only one quote operator. None of this does anything; it is only syntax. * lib.c (quote_s, qquote_s, unquote_s, splice_s): New variables. (obj_init): New variables initialized. * lib.h (quote_s, qquote_s, unquote_s, splice_s): Declared. * parser.l: Added recognition rules. * parser.y (SPLICE): New symbolic token. (list): Added new syntax for quote and splicing. --- parser.y | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'parser.y') diff --git a/parser.y b/parser.y index b8ee0659..e80c7756 100644 --- a/parser.y +++ b/parser.y @@ -71,7 +71,7 @@ static val parsed_spec; %token NUMBER %token REGCHAR LITCHAR -%token METAPAR +%token METAPAR SPLICE %type spec clauses clauses_opt clause %type all_clause some_clause none_clause maybe_clause @@ -96,7 +96,7 @@ static val parsed_spec; %right OUTPUT REPEAT REP FIRST LAST EMPTY DEFINE %right SPACE TEXT NUMBER %nonassoc '[' ']' '(' ')' -%left '-' +%left '-' ',' '\'' SPLICE %left '|' '/' %left '&' %right '~' '*' '?' '+' '%' @@ -587,6 +587,9 @@ var_op : '*' { $$ = list(t, nao); } list : '(' exprs ')' { $$ = rl($2, num($1)); } | '(' ')' { $$ = nil; } + | ',' expr { $$ = rlcp(list(unquote_s, $2, nao), $2); } + | '\'' expr { $$ = rlcp(list(qquote_s, $2, nao), $2); } + | SPLICE expr { $$ = rlcp(list(splice_s, $2, nao), $2); } | '(' error { $$ = nil; yybadtoken(yychar, lit("list expression")); } ; -- cgit v1.2.3