summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y37
1 files changed, 27 insertions, 10 deletions
diff --git a/parse.y b/parse.y
index 1e560f109e..9ea1fb1622 100644
--- a/parse.y
+++ b/parse.y
@@ -6,7 +6,7 @@
$Date: 1995/01/12 08:54:50 $
created at: Fri May 28 18:02:42 JST 1993
- Copyright (C) 1994 Yukihiro Matsumoto
+ Copyright (C) 1993-1995 Yukihiro Matsumoto
************************************************/
@@ -19,6 +19,11 @@
#include "st.h"
#include <stdio.h>
+/* hack for bison */
+#ifdef const
+# undef const
+#endif
+
#include "ident.h"
#define is_id_nonop(id) ((id)>LAST_TOKEN)
#define is_local_id(id) (is_id_nonop(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
@@ -137,7 +142,7 @@ static void top_local_setup();
%type <node> f_arglist f_args array assoc_list assocs assoc
%type <node> mlhs mlhs_head mlhs_tail lhs iter_var opt_iter_var
%type <id> superclass variable symbol
-%type <id> fname op rest_arg
+%type <id> cname fname op rest_arg
%type <num> f_arg
%token UPLUS /* unary+ */
%token UMINUS /* unary- */
@@ -163,8 +168,7 @@ static void top_local_setup();
*/
%left IF_MOD WHILE_MOD
-%left OR
-%left AND
+%left OR AND
%left YIELD RETURN FAIL
%right '=' OP_ASGN
%right COLON2
@@ -324,6 +328,12 @@ lhs : variable
$$ = attrset($1, $3, Qnil);
}
+cname : IDENTIFIER
+ {
+ Error("class/module name must be CONSTANT");
+ }
+ | CONSTANT
+
fname : IDENTIFIER
| CONSTANT
| op
@@ -700,14 +710,14 @@ primary : literal
{
$$ = NEW_YIELD(Qnil);
}
- | primary '{' opt_iter_var '|' compexpr rbrace
+ | primary '{' opt_iter_var compexpr rbrace
{
if (nd_type($1) == NODE_LVAR
|| nd_type($1) == NODE_LVAR2
|| nd_type($1) == NODE_CVAR) {
$1 = NEW_FCALL($1->nd_vid, Qnil);
}
- $$ = NEW_ITER($3, $1, $5);
+ $$ = NEW_ITER($3, $1, $4);
}
| IDENTIFIER '(' call_args rparen
{
@@ -767,7 +777,7 @@ primary : literal
{
$$ = $2;
}
- | CLASS CONSTANT superclass
+ | CLASS cname superclass
{
if (cur_mid || in_single)
Error("class definition in method body");
@@ -784,7 +794,7 @@ primary : literal
cref_pop();
class_nest--;
}
- | MODULE CONSTANT
+ | MODULE cname
{
if (cur_mid || in_single)
Error("module definition in method body");
@@ -854,11 +864,18 @@ opt_else : /* none */
iter_var : lhs
| mlhs
-opt_iter_var : /* none */
+opt_iter_var : '|' /* none */ '|'
{
$$ = Qnil;
}
- | iter_var
+ | OROP
+ {
+ $$ = Qnil;
+ }
+ | '|' iter_var '|'
+ {
+ $$ = $2;
+ }
case_body : WHEN args then
compexpr