summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y119
1 files changed, 56 insertions, 63 deletions
diff --git a/parse.y b/parse.y
index 3bbb935f0e..4d494b4b7b 100644
--- a/parse.y
+++ b/parse.y
@@ -97,8 +97,8 @@ static struct RVarmap *dyna_push();
static void dyna_pop();
static int dyna_in_block();
-#define crerb_f_push() NEW_CREF()
-static void crerb_f_pop();
+#define cref_push() NEW_CREF()
+static void cref_pop();
static NODE *cur_cref;
static void top_local_init();
@@ -170,9 +170,9 @@ static void top_local_setup();
%type <node> aref_args opt_block_arg block_arg
%type <node> mrhs opt_list superclass iterator var_ref
%type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg
-%type <node> array assoc_list assocs assoc undef_list
+%type <node> array assoc_list assocs assoc undef_list backref
%type <node> iter_var opt_iter_var iter_block iter_do_block
-%type <node> mlhs mlhs_head mlhs_tail mlhs_basic mlhs_item lhs backref
+%type <node> mlhs mlhs_head mlhs_tail mlhs_basic mlhs_entry mlhs_item lhs
%type <id> variable symbol operation
%type <id> cname fname op f_rest_arg
%type <num> f_arg
@@ -372,7 +372,7 @@ expr : mlhs '=' mrhs
value_expr($2);
if (!cur_mid && !in_single)
yyerror("return appeared outside of method");
- $$ = NEW_RET($2);
+ $$ = NEW_RETURN($2);
}
| kYIELD ret_args
{
@@ -426,13 +426,13 @@ command_call : operation call_args
}
mlhs : mlhs_basic
- | tLPAREN mlhs_item ')'
+ | tLPAREN mlhs_entry ')'
{
$$ = $2;
}
-mlhs_item : mlhs_basic
- | tLPAREN mlhs_item ')'
+mlhs_entry : mlhs_basic
+ | tLPAREN mlhs_entry ')'
{
$$ = NEW_MASGN(NEW_LIST($2), 0);
}
@@ -458,21 +458,22 @@ mlhs_basic : mlhs_head
$$ = NEW_MASGN(0, $2);
}
-mlhs_head : lhs ','
- | tLPAREN mlhs_item ')' ','
+mlhs_item : lhs
+ | tLPAREN mlhs_entry ')'
{
$$ = $2;
}
-mlhs_tail : lhs
+mlhs_head : mlhs_item ','
{
- $$ = NEW_LIST($1);
+ $$ = $1;
}
- | tLPAREN mlhs_item ')'
+
+mlhs_tail : mlhs_item
{
- $$ = NEW_LIST($2);
+ $$ = NEW_LIST($1);
}
- | mlhs_tail ',' lhs
+ | mlhs_tail ',' mlhs_item
{
$$ = list_append($1, $3);
}
@@ -956,19 +957,19 @@ primary : literal
if (!cur_mid && !in_single)
yyerror("return appeared outside of method");
value_expr($3);
- $$ = NEW_RET($3);
+ $$ = NEW_RETURN($3);
}
| kRETURN '(' ')'
{
if (!cur_mid && !in_single)
yyerror("return appeared outside of method");
- $$ = NEW_RET(0);
+ $$ = NEW_RETURN(0);
}
| kRETURN
{
if (!cur_mid && !in_single)
yyerror("return appeared outside of method");
- $$ = NEW_RET(0);
+ $$ = NEW_RETURN(0);
}
| kYIELD '(' ret_args ')'
{
@@ -1082,7 +1083,7 @@ primary : literal
yyerror("class definition in method body");
class_nest++;
- crerb_f_push();
+ cref_push();
local_push();
}
compstmt
@@ -1091,13 +1092,13 @@ primary : literal
$$ = NEW_CLASS($2, $5, $3);
fixpos($$, $3);
local_pop();
- crerb_f_pop();
+ cref_pop();
class_nest--;
}
| kCLASS tLSHFT expr term
{
class_nest++;
- crerb_f_push();
+ cref_push();
local_push();
}
compstmt
@@ -1106,7 +1107,7 @@ primary : literal
$$ = NEW_SCLASS($3, $6);
fixpos($$, $3);
local_pop();
- crerb_f_pop();
+ cref_pop();
class_nest--;
}
| kMODULE cname
@@ -1114,7 +1115,7 @@ primary : literal
if (cur_mid || in_single)
yyerror("module definition in method body");
class_nest++;
- crerb_f_push();
+ cref_push();
local_push();
}
compstmt
@@ -1123,7 +1124,7 @@ primary : literal
$$ = NEW_MODULE($2, $4);
fixpos($$, $4);
local_pop();
- crerb_f_pop();
+ cref_pop();
class_nest--;
}
| kDEF fname
@@ -3004,7 +3005,7 @@ retry:
}
c = nextc();
}
- if (c == '!' || c == '?') {
+ if ((c == '!' || c == '?') && is_identchar(tok()[0])) {
tokadd(c);
}
else {
@@ -3038,23 +3039,6 @@ retry:
}
}
- if (lex_state == EXPR_FNAME) {
- lex_state = EXPR_END;
- if ((c = nextc()) == '=') {
- tokadd(c);
- }
- else {
- pushback(c);
- }
- }
- else if (lex_state == EXPR_BEG ||
- lex_state == EXPR_DOT ||
- lex_state == EXPR_ARG){
- lex_state = EXPR_ARG;
- }
- else {
- lex_state = EXPR_END;
- }
if (ISUPPER(tok()[0])) {
result = tCONSTANT;
}
@@ -3062,6 +3046,23 @@ retry:
result = tFID;
} else {
result = tIDENTIFIER;
+ if (lex_state == EXPR_FNAME) {
+ lex_state = EXPR_END;
+ if ((c = nextc()) == '=') {
+ tokadd(c);
+ }
+ else {
+ pushback(c);
+ }
+ }
+ }
+ if (lex_state == EXPR_BEG ||
+ lex_state == EXPR_DOT ||
+ lex_state == EXPR_ARG){
+ lex_state = EXPR_ARG;
+ }
+ else {
+ lex_state = EXPR_END;
}
}
tokfix();
@@ -3544,10 +3545,7 @@ attrset(recv, id, val)
value_expr(recv);
value_expr(val);
- id &= ~ID_SCOPE_MASK;
- id |= ID_ATTRSET;
-
- return NEW_CALL(recv, id, NEW_LIST(val));
+ return NEW_CALL(recv, rb_id_attrset(id), NEW_LIST(val));
}
static void
@@ -3556,10 +3554,10 @@ rb_backref_error(node)
{
switch (nd_type(node)) {
case NODE_NTH_REF:
- yyerror("Can't set variable $%d", node->nd_nth);
+ rb_compile_error("Can't set variable $%d", node->nd_nth);
break;
case NODE_BACK_REF:
- yyerror("Can't set variable $%c", node->nd_nth);
+ rb_compile_error("Can't set variable $%c", node->nd_nth);
break;
}
}
@@ -3721,7 +3719,7 @@ logop(type, left, right)
NODE *left, *right;
{
value_expr(left);
- return rb_node_newnode(type, cond(left), cond(right));
+ return rb_node_newnode(type, cond(left), cond(right), 0);
}
static NODE *
@@ -3925,7 +3923,7 @@ dyna_in_block()
}
static void
-crerb_f_pop()
+cref_pop()
{
cur_cref = cur_cref->nd_next;
}
@@ -4030,8 +4028,7 @@ rb_intern(name)
if (st_lookup(sym_tbl, name, &id))
return id;
- id = ++last_id;
- id <<= ID_SCOPE_SHIFT;
+ id = 0;
switch (name[0]) {
case '$':
id |= ID_GLOBAL;
@@ -4044,18 +4041,13 @@ rb_intern(name)
/* operator */
int i;
- id = 0;
for (i=0; op_tbl[i].token; i++) {
if (*op_tbl[i].name == *name &&
strcmp(op_tbl[i].name, name) == 0) {
id = op_tbl[i].token;
- break;
+ goto id_regist;
}
}
- if (id == 0) {
- rb_raise(rb_eNameError, "Unknown operator `%s'", name);
- }
- break;
}
last = strlen(name)-1;
@@ -4065,18 +4057,19 @@ rb_intern(name)
strncpy(buf, name, last);
buf[last] = '\0';
- id = rb_intern(buf);
- id &= ~ID_SCOPE_MASK;
- id |= ID_ATTRSET;
+ id = rb_id_attrset(rb_intern(buf));
+ goto id_regist;
}
else if (ISUPPER(name[0])) {
- id |= ID_CONST;
+ id = ID_CONST;
}
else {
- id |= ID_LOCAL;
+ id = ID_LOCAL;
}
break;
}
+ id |= ++last_id << ID_SCOPE_SHIFT;
+ id_regist:
name = strdup(name);
st_add_direct(sym_tbl, name, id);
st_add_direct(sym_rev_tbl, id, name);