summaryrefslogtreecommitdiff
path: root/perly.y
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2010-10-04 10:26:42 +0200
committerRafael Garcia-Suarez <rgs@consttype.org>2010-10-04 10:26:42 +0200
commit07ffcb738e9467df21e3d33604cf09c125e7ff52 (patch)
tree4d9f19d1b037c0559de25681d55a3a2f7569e2ce /perly.y
parentad97526782cdd5392f99d55127e22a7eb5ea9851 (diff)
downloadperl-07ffcb738e9467df21e3d33604cf09c125e7ff52.tar.gz
[PATCH] function to parse Perl statement sequence
New API function parse_stmtseq() parses a sequence of statements, up to closing brace or EOF.
Diffstat (limited to 'perly.y')
-rw-r--r--perly.y29
1 files changed, 27 insertions, 2 deletions
diff --git a/perly.y b/perly.y
index c1ea3b8457..0b7c068a75 100644
--- a/perly.y
+++ b/perly.y
@@ -69,7 +69,7 @@
#endif
}
-%token <ival> GRAMPROG GRAMFULLSTMT
+%token <ival> GRAMPROG GRAMFULLSTMT GRAMSTMTSEQ
%token <i_tkval> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';'
@@ -89,7 +89,7 @@
%type <i_tkval> lpar_or_qw
-%type <ival> grammar prog progstart remember mremember
+%type <ival> grammar closebrace_or_eof prog progstart remember mremember
%type <ival> startsub startanonsub startformsub
/* FIXME for MAD - are these two ival? */
%type <ival> mydefsv mintro
@@ -150,6 +150,31 @@ grammar : GRAMPROG prog
yyunlex();
parser->yychar = YYEOF;
}
+ | GRAMSTMTSEQ
+ {
+ parser->expect = XSTATE;
+ }
+ lineseq closebrace_or_eof
+ {
+ PL_eval_root = $3;
+ $$ = 0;
+ }
+ ;
+
+closebrace_or_eof: '}'
+ {
+ assert(parser->yychar == YYEMPTY);
+ assert(parser->bufptr != SvPVX(parser->linestr));
+ assert(parser->bufptr[-1] == '}');
+ parser->bufptr--;
+ parser->lex_brackstack[parser->lex_brackets++] =
+ XSTATE;
+ parser->expect = XSTATE;
+ parser->yychar = YYEOF;
+ $$ = 0;
+ }
+ | /* NULL */
+ { $$ = 0; }
;
/* The whole program */