summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-compiler')
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c16
-rw-r--r--mrbgems/mruby-compiler/core/parse.y32
2 files changed, 40 insertions, 8 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index efdd77888..9b064b867 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -1645,7 +1645,7 @@ codegen(codegen_scope *s, node *tree, int val)
node *t = tree->cdr, *p;
int rhs = cursp();
- if ((intptr_t)t->car == NODE_ARRAY && nosplat(t->cdr)) {
+ if ((intptr_t)t->car == NODE_ARRAY && t->cdr && nosplat(t->cdr)) {
/* fixed rhs */
t = t->cdr;
while (t) {
@@ -1655,11 +1655,21 @@ codegen(codegen_scope *s, node *tree, int val)
}
tree = tree->car;
if (tree->car) { /* pre */
+ int first = TRUE;
t = tree->car;
n = 0;
while (t) {
- gen_assignment(s, t->car, rhs+n, NOVAL);
- n++;
+ if (n < len) {
+ gen_assignment(s, t->car, rhs+n, NOVAL);
+ n++;
+ }
+ else {
+ if (first) {
+ genop(s, MKOP_A(OP_LOADNIL, rhs+n));
+ first = FALSE;
+ }
+ gen_assignment(s, t->car, rhs+n, NOVAL);
+ }
t = t->cdr;
}
}
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 22d31a390..90b8812b9 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -1089,7 +1089,7 @@ heredoc_end(parser_state *p)
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
%token <nd> tINTEGER tFLOAT tCHAR tXSTRING tREGEXP
-%token <nd> tSTRING tSTRING_PART tSTRING_MID
+%token <nd> tSTRING tSTRING_PART tSTRING_MID tLABEL_END
%token <nd> tNTH_REF tBACK_REF
%token <num> tREGEXP_END
@@ -2972,7 +2972,7 @@ superclass : /* term */
expr_value term
{
$$ = $3;
- } /*
+ } /*
| error term
{
yyerrok;
@@ -3241,6 +3241,18 @@ assoc : arg_value tASSOC arg_value
{
$$ = cons(new_sym(p, $1), $2);
}
+ | tLABEL_END arg_value
+ {
+ $$ = cons(new_sym(p, new_strsym(p, $1)), $2);
+ }
+ | tSTRING_BEG tLABEL_END arg_value
+ {
+ $$ = cons(new_sym(p, new_strsym(p, $2)), $3);
+ }
+ | tSTRING_BEG string_rep tLABEL_END arg_value
+ {
+ $$ = cons(new_dsym(p, push($2, $3)), $4);
+ }
;
operation : tIDENTIFIER
@@ -3895,6 +3907,8 @@ parse_string(parser_state *p)
int end = (intptr_t)p->lex_strterm->cdr->cdr->cdr;
parser_heredoc_info *hinf = (type & STR_FUNC_HEREDOC) ? parsing_heredoc_inf(p) : NULL;
+ if (beg == 0) beg = -3; /* should never happen */
+ if (end == 0) end = -3;
newtok(p);
while ((c = nextc(p)) != end || nest_level != 0) {
if (hinf && (c == '\n' || c < 0)) {
@@ -4080,8 +4094,13 @@ parse_string(parser_state *p)
return tREGEXP;
}
-
yylval.nd = new_str(p, tok(p), toklen(p));
+ if (IS_LABEL_SUFFIX(0)) {
+ p->lstate = EXPR_BEG;
+ nextc(p);
+ return tLABEL_END;
+ }
+
return tSTRING;
}
@@ -5460,7 +5479,10 @@ mrb_parser_parse(parser_state *p, mrbc_context *c)
p->lex_strterm = NULL;
parser_init_cxt(p, c);
- yyparse(p);
+ if (yyparse(p) != 0 || p->nerr > 0) {
+ p->tree = 0;
+ return;
+ }
if (!p->tree) {
p->tree = new_nil(p);
}
@@ -6487,7 +6509,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
break;
case NODE_HEREDOC:
- printf("NODE_HEREDOC:\n");
+ printf("NODE_HEREDOC (<<%s):\n", ((parser_heredoc_info*)tree)->term);
mrb_parser_dump(mrb, ((parser_heredoc_info*)tree)->doc, offset+1);
break;