summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-20 03:35:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-20 03:35:44 +0000
commitd88376b1352ad96e35bfc08f2bfce885ed6d72ca (patch)
tree0cd9c4945bf199c8173a37a39407288b31cb342f /parse.y
parentafca4f0cfd0bcc769451d5160320c7a33b3c4ed1 (diff)
* parse.y (clhs): allow "Foo::Bar = x".
* parse.y (primary): "self[n]=x" can be legal even when "[]=" is private. changes submitted in [ruby-talk:63982] * parse.y (aryset): ditto. * parse.y (attrset): "self.foo=x" can be legal even when "foo=" is private. * eval.c (is_defined): private "[]=" and "foo=" support. * eval.c (rb_eval): ditto. * eval.c (assign): ditto. * eval.c (rb_eval): "foo=" should not always be public. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y60
1 files changed, 42 insertions, 18 deletions
diff --git a/parse.y b/parse.y
index 2d0682f..b848fe7 100644
--- a/parse.y
+++ b/parse.y
@@ -240,7 +240,7 @@ static void top_local_setup();
%type <node> singleton strings string string1 xstring regexp
%type <node> string_contents xstring_contents string_content
%type <node> words qwords word_list qword_list word
-%type <node> literal numeric dsym cbase cpath
+%type <node> literal numeric dsym cpath clhs
%type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
%type <node> expr_value arg_value primary_value
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
@@ -483,6 +483,10 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
$1->nd_value = NEW_RESTARY($3);
$$ = $1;
}
+ | clhs '=' command_call
+ {
+ $$ = node_assign($1, $3);
+ }
| var_lhs tOP_ASGN command_call
{
value_expr($3);
@@ -570,6 +574,10 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
{
$$ = node_assign($1, NEW_SVALUE($3));
}
+ | clhs '=' mrhs
+ {
+ $$ = node_assign($1, NEW_SVALUE($3));
+ }
| mlhs '=' arg_value
{
$1->nd_value = $3;
@@ -580,6 +588,10 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
$1->nd_value = $3;
$$ = $1;
}
+ | clhs '=' arg
+ {
+ $$ = node_assign($1, $3);
+ }
| expr
;
@@ -830,6 +842,14 @@ lhs : variable
}
;
+clhs : primary_value tCOLON2 tCONSTANT
+ {
+ if (in_def || in_single)
+ yyerror("dynamic constant assignment");
+ $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
+ }
+ ;
+
cname : tIDENTIFIER
{
yyerror("class/module name must be CONSTANT");
@@ -837,27 +857,20 @@ cname : tIDENTIFIER
| tCONSTANT
;
-cbase : tCOLON3 cname
+cpath : tCOLON3 cname
{
$$ = NEW_COLON3($2);
}
| cname
{
- $$ = NEW_CONST($1);
+ $$ = NEW_COLON2(0, $$);
}
- | cbase tCOLON2 cname
+ | primary_value tCOLON2 cname
{
$$ = NEW_COLON2($1, $3);
}
;
-cpath : cbase
- {
- if (nd_type($$ = $1) == NODE_CONST)
- $$ = NEW_COLON2(0, $$->nd_vid);
- }
- ;
-
fname : tIDENTIFIER
| tCONSTANT
| tFID
@@ -1423,7 +1436,10 @@ primary : literal
}
| primary_value '[' aref_args ']'
{
- $$ = NEW_CALL($1, tAREF, $3);
+ if (nd_type($1) == NODE_SELF)
+ $$ = NEW_FCALL(tAREF, $3);
+ else
+ $$ = NEW_CALL($1, tAREF, $3);
}
| tLBRACK aref_args ']'
{
@@ -1612,7 +1628,6 @@ primary : literal
kEND
{
$$ = NEW_DEFN($2, $4, $5, NOEX_PRIVATE);
- if (is_attrset_id($2)) $$->nd_noex = NOEX_PUBLIC;
fixpos($$, $4);
local_pop();
in_def--;
@@ -4648,9 +4663,12 @@ call_op(recv, id, narg, arg1)
value_expr(recv);
if (narg == 1) {
value_expr(arg1);
+ arg1 = NEW_LIST(arg1);
}
-
- return NEW_CALL(recv, id, narg==1?NEW_LIST(arg1):0);
+ else {
+ arg1 = 0;
+ }
+ return NEW_CALL(recv, id, arg1);
}
static NODE*
@@ -4788,7 +4806,7 @@ assignable(id, val)
else if (is_const_id(id)) {
if (in_def || in_single)
yyerror("dynamic constant assignment");
- return NEW_CDECL(id, val);
+ return NEW_CDECL(id, val, 0);
}
else if (is_class_id(id)) {
if (in_def || in_single) return NEW_CVASGN(id, val);
@@ -4804,7 +4822,10 @@ static NODE *
aryset(recv, idx)
NODE *recv, *idx;
{
- value_expr(recv);
+ if (recv && nd_type(recv) == NODE_SELF)
+ recv = (NODE *)1;
+ else
+ value_expr(recv);
return NEW_ATTRASGN(recv, tASET, idx);
}
@@ -4822,7 +4843,10 @@ attrset(recv, id)
NODE *recv;
ID id;
{
- value_expr(recv);
+ if (recv && nd_type(recv) == NODE_SELF)
+ recv = (NODE *)1;
+ else
+ value_expr(recv);
return NEW_ATTRASGN(recv, rb_id_attrset(id), 0);
}