Commit dec6751d authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

remove BEGIN/END from syntax

parent e5dde46c
...@@ -89,7 +89,7 @@ struct mrb_parser_state { ...@@ -89,7 +89,7 @@ struct mrb_parser_state {
int nerr; int nerr;
int nwarn; int nwarn;
mrb_ast_node *tree, *begin_tree; mrb_ast_node *tree;
int capture_errors; int capture_errors;
struct mrb_parser_message error_buffer[10]; struct mrb_parser_message error_buffer[10];
......
...@@ -1026,14 +1026,11 @@ top_stmts : none ...@@ -1026,14 +1026,11 @@ top_stmts : none
top_stmt : stmt top_stmt : stmt
| keyword_BEGIN | keyword_BEGIN
{ {
if (p->in_def || p->in_single) {
yyerror(p, "BEGIN in method");
}
$<nd>$ = local_switch(p); $<nd>$ = local_switch(p);
} }
'{' top_compstmt '}' '{' top_compstmt '}'
{ {
p->begin_tree = push(p->begin_tree, $4); yyerror(p, "BEGIN not supported");
local_resume(p, $<nd>2); local_resume(p, $<nd>2);
$$ = 0; $$ = 0;
} }
...@@ -1119,9 +1116,7 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym ...@@ -1119,9 +1116,7 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym
} }
| keyword_END '{' compstmt '}' | keyword_END '{' compstmt '}'
{ {
if (p->in_def || p->in_single) { yyerror(p, "END not suported");
yywarn(p, "END in method; use at_exit");
}
$$ = new_postexe(p, $3); $$ = new_postexe(p, $3);
} }
| command_asgn | command_asgn
...@@ -4714,12 +4709,10 @@ void parser_dump(mrb_state *mrb, node *tree, int offset); ...@@ -4714,12 +4709,10 @@ void parser_dump(mrb_state *mrb, node *tree, int offset);
void void
mrb_parser_parse(parser_state *p, mrbc_context *c) mrb_parser_parse(parser_state *p, mrbc_context *c)
{ {
node *tree;
if (setjmp(p->jmp) != 0) { if (setjmp(p->jmp) != 0) {
yyerror(p, "memory allocation error"); yyerror(p, "memory allocation error");
p->nerr++; p->nerr++;
p->tree = p->begin_tree = 0; p->tree = 0;
return; return;
} }
...@@ -4730,22 +4723,10 @@ mrb_parser_parse(parser_state *p, mrbc_context *c) ...@@ -4730,22 +4723,10 @@ mrb_parser_parse(parser_state *p, mrbc_context *c)
parser_init_cxt(p, c); parser_init_cxt(p, c);
yyparse(p); yyparse(p);
tree = p->tree; if (!p->tree) {
if (!tree) { p->tree = new_nil(p);
if (p->begin_tree) {
tree = p->begin_tree;
}
else {
tree = new_nil(p);
}
}
else {
parser_update_cxt(p, c);
if (p->begin_tree) {
tree = new_begin(p, p->begin_tree);
append(tree, p->tree);
}
} }
parser_update_cxt(p, c);
if (c && c->dump_result) { if (c && c->dump_result) {
parser_dump(p->mrb, p->tree, 0); parser_dump(p->mrb, p->tree, 0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment