ref: b8b34577b7f5e7c4fa13f927103c80dc417c64d9
parent: a31dc19339a6f62ed08b8dba8cffe889350c858c
author: Ori Bernstein <[email protected]>
date: Sat Jun 30 15:29:11 EDT 2012
Parse sequence literals.
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -69,6 +69,7 @@
%token<tok> Tcsqbrac /* ] */
%token<tok> Tat /* @ */
%token<tok> Ttick /* ` */
+%token<tok> Thash /* # */
%token<tok> Ttype /* type */
%token<tok> Tfor /* for */
@@ -125,7 +126,7 @@
%type <node> exprln retexpr expr atomicexpr littok literal asnexpr lorexpr landexpr borexpr
%type <node> bandexpr cmpexpr unionexpr addexpr mulexpr shiftexpr prefixexpr postfixexpr
-%type <node> funclit arraylit name block blockbody stmt label use
+%type <node> funclit seqlit name block blockbody stmt label use
%type <node> decl declbody declcore structelt
%type <node> ifstmt forstmt whilestmt matchstmt elifs optexprln
%type <node> pat unionpat match
@@ -492,7 +493,7 @@
;
literal : funclit {$$ = $1;}
- | arraylit {$$ = $1;}
+ | seqlit {$$ = $1;}
| littok {$$ = $1;}
;
@@ -517,13 +518,19 @@
{$$.nl = NULL; $$.nn = 0;}
;
-arraylit : Tosqbrac arraybody Tcsqbrac
- {$$ = NULL; die("Unimpl arraylit");}
- ;
+seqlit : Tosqbrac seqbody Tcsqbrac
+ {$$ = NULL; die("Unimpl seqlit");}
+ ;
-arraybody
- : expr
- | arraybody Tcomma expr
+seqbody : seqelt
+ | seqbody Tcomma seqelt
+ ;
+
+seqelt : Tdot Tident Tasn expr
+ | Thash atomicexpr Tasn expr
+ | expr
+ | Tendln seqelt
+ | seqelt Tendln
;
stmt : decl
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -260,6 +260,7 @@
case ']': tt = Tcsqbrac; break;
case ',': tt = Tcomma; break;
case '`': tt = Ttick; break;
+ case '#': tt = Thash; break;
case ':':
if (match(':'))
tt = Tcoloncolon;