lib/ruby3_parser.yy in ruby_parser-3.18.1 vs lib/ruby3_parser.yy in ruby_parser-3.19.0
- old
+ new
@@ -1,9 +1,11 @@
# -*- racc -*-
#if V == 30
class Ruby30Parser
+#elif V == 31
+class Ruby31Parser
#else
fail "version not specified or supported on code generation"
#endif
token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
@@ -82,11 +84,11 @@
top_stmt: stmt
| klBEGIN
{
if (self.in_def || self.in_single > 0) then
- debug 11
+ debug 1
yyerror "BEGIN in method"
end
self.env.extend
}
begin_block
@@ -137,11 +139,11 @@
result = self.block_append val[0], val[2]
}
| error stmt
{
result = val[1]
- debug 12
+ debug 2
}
stmt_or_begin: stmt
| klBEGIN
{
@@ -209,11 +211,11 @@
| klEND tLCURLY compstmt tRCURLY
{
(_, line), _, stmt, _ = val
if (self.in_def || self.in_single > 0) then
- debug 13
+ debug 3
yyerror "END in method; use at_exit"
end
result = new_iter s(:postexe).line(line), 0, stmt
}
@@ -284,10 +286,28 @@
{
lhs1, _, (lhs2, line), (id, _), rhs = val
result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
}
+#if V > 30
+ | defn_head f_opt_paren_args tEQL command
+ {
+ result = new_endless_defn val
+ }
+ | defn_head f_opt_paren_args tEQL command kRESCUE_MOD arg
+ {
+ result = new_endless_defn val
+ }
+ | defs_head f_opt_paren_args tEQL command
+ {
+ result = new_endless_defs val
+ }
+ | defs_head f_opt_paren_args tEQL command kRESCUE_MOD arg
+ {
+ result = new_endless_defs val
+ }
+#endif
| backref tOP_ASGN command_rhs
{
self.backref_assign_error val[0]
}
@@ -337,11 +357,15 @@
self.lexer.command_start = false
result = self.in_kwarg
self.in_kwarg = true
self.env.extend
}
+#if V == 30
p_expr
+#else
+ p_top_expr_body
+#endif
{
lhs, _, in_kwarg, rhs = val
self.env.unextend
self.in_kwarg = in_kwarg
@@ -357,11 +381,15 @@
self.lexer.command_start = false
result = self.in_kwarg
self.in_kwarg = true
self.env.extend
}
+#if V == 30
p_expr
+#else
+ p_top_expr_body
+#endif
{
self.env.unextend
expr, _, old_kwarg, pat = val
@@ -677,11 +705,11 @@
result = new_attrasgn lhs, id, call_op
}
| primary_value tCOLON2 tCONSTANT
{
if (self.in_def || self.in_single > 0) then
- debug 14
+ debug 4
yyerror "dynamic constant assignment"
end
expr, _, (id, _line) = val
l = expr.line
@@ -689,11 +717,11 @@
result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
}
| tCOLON3 tCONSTANT
{
if (self.in_def || self.in_single > 0) then
- debug 15
+ debug 5
yyerror "dynamic constant assignment"
end
_, (id, l) = val
@@ -716,11 +744,11 @@
{
var, = val
result = self.assignable var
- debug 16
+ debug 6
}
| primary_value tLBRACK2 opt_call_args rbracket
{
lhs, _, args, _ = val
@@ -747,11 +775,11 @@
| primary_value tCOLON2 tCONSTANT
{
expr, _, (id, _line) = val
if (self.in_def || self.in_single > 0) then
- debug 17
+ debug 7
yyerror "dynamic constant assignment"
end
l = expr.line
result = s(:const, s(:colon2, expr, id.to_sym).line(l)).line l
@@ -759,11 +787,11 @@
| tCOLON3 tCONSTANT
{
_, (id, l) = val
if (self.in_def || self.in_single > 0) then
- debug 18
+ debug 8
yyerror "dynamic constant assignment"
end
result = s(:const, s(:colon3, id.to_sym).line(l)).line l
}
@@ -778,12 +806,11 @@
}
| tCONSTANT
cpath: tCOLON3 cname
{
- _, (name, line) = val
- result = s(:colon3, name.to_sym).line line
+ result = wrap :colon3, val[1]
}
| cname
{
(id, line), = val
result = [id.to_sym, line] # TODO: sexp?
@@ -804,13 +831,11 @@
| reswords
fitem: fname
{
- (id, line), = val
-
- result = s(:lit, id.to_sym).line line
+ result = wrap :lit, val[0]
}
| symbol
undef_list: fitem
{
@@ -875,13 +900,13 @@
lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
result = new_const_op_asgn [lhs, op, rhs]
}
| tCOLON3 tCONSTANT tOP_ASGN arg_rhs
{
- _, (lhs, line), op, rhs = val
+ _, lhs, op, rhs = val
- lhs = s(:colon3, lhs.to_sym).line line
+ lhs = wrap :colon3, lhs
result = new_const_op_asgn [lhs, op, rhs]
}
| backref tOP_ASGN arg_rhs
{
# TODO: lhs = var_field val[0]
@@ -960,12 +985,12 @@
{
result = new_call val[0], :**, argl(val[2])
}
| tUMINUS_NUM simple_numeric tPOW arg
{
- _, (num, line), _, arg = val
- lit = s(:lit, num).line line
+ _, num, _, arg = val
+ lit = wrap :lit, num
result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
}
| tUPLUS arg
{
@@ -1054,50 +1079,23 @@
c, _, t, _, _, f = val
result = s(:if, c, t, f).line c.line
}
| defn_head f_opt_paren_args tEQL arg
{
- (name, line, in_def), args, _, body = val
-
- result = s(:defn, name, args, body).line line
-
- local_pop in_def
- endless_method_name result
+ result = new_endless_defn val
}
| defn_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
{
- (name, line, in_def), args, _, body, _, resbody = val
-
- result = s(:defn, name, args,
- new_rescue(body,
- new_resbody(s(:array).line(line),
- resbody))).line line
-
- local_pop in_def
- endless_method_name result
+ result = new_endless_defn val
}
| defs_head f_opt_paren_args tEQL arg
{
- (recv, (name, line, in_def)), args, _, body = val
-
- result = s(:defs, recv, name, args, body).line(line)
-
- self.in_single -= 1
- local_pop in_def
- endless_method_name result
+ result = new_endless_defs val
}
| defs_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
{
- (recv, (name, line, in_def)), args, _, body, _, resbody = val
-
- result = s(:defs, recv, name, args,
- new_rescue(body,
- new_resbody(s(:array).line(line),
- resbody))).line line
-
- local_pop in_def
- endless_method_name result
+ result = new_endless_defs val
}
| primary
relop: tGT
| tLT
@@ -1249,10 +1247,17 @@
block_arg: tAMPER arg_value
{
_, arg = val
result = s(:block_pass, arg).line arg.line
}
+#if V > 30
+ | tAMPER
+ {
+ (_, line), = val
+ result = s(:block_pass).line line
+ }
+#endif
opt_block_arg: tCOMMA block_arg
{
result = val[1]
}
@@ -1368,13 +1373,11 @@
result = s(:colon2, expr, id.to_sym).line expr.line
}
| tCOLON3 tCONSTANT
{
- _, (id, line) = val
-
- result = s(:colon3, id.to_sym).line line
+ result = wrap :colon3, val[1]
}
| tLBRACK { result = lexer.lineno } aref_args tRBRACK
{
_, line, args, _ = val
result = args || s(:array)
@@ -1423,11 +1426,11 @@
_, _, lhs, _ = val
result = new_call lhs, :"!"
}
| kNOT tLPAREN2 rparen
{
- debug 19
+ debug 9
}
| fcall brace_block
{
call, iter = val
@@ -1733,10 +1736,14 @@
}
f_any_kwrest: f_kwrest
| f_no_kwarg
+#if V > 30
+ f_eq: tEQL # TODO: self.in_argdef = false
+#endif
+
block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
{
result = call_args val
}
| f_block_kwarg opt_f_block_arg
@@ -1863,12 +1870,11 @@
result = args val
}
bvar: tIDENTIFIER
{
- (id, line), = val
- result = s(:shadow, id.to_sym).line line
+ result = wrap :shadow, val[0]
}
| f_bad_arg
lambda: tLAMBDA
{
@@ -2203,10 +2209,13 @@
p_lparen: tLPAREN2 { push_pktbl }
p_lbracket: tLBRACK2 { push_pktbl }
p_expr_basic: p_value
+#if V > 30
+ | p_variable
+#endif
| p_const p_lparen p_args tRPAREN
{
lhs, _, args, _ = val
pop_pktbl
@@ -2478,23 +2487,28 @@
case lhs.sexp_type
when :lit then
assignable [lhs.value, lhs.line]
else
# TODO or done?
- debug 666
+ debug 10
end
# TODO PAIR -> LIST ?
result = s(:PAIR, lhs, nil).line lhs.line
}
p_kw_label: tLABEL
{
- (id, line), = val
-
- result = s(:lit, id.to_sym).line line
+ result = wrap :lit, val[0]
}
+#if V > 30
+ | tSTRING_BEG string_contents tLABEL_END
+ {
+ # you can't actually get here the way I lex labels
+ debug 11
+ }
+#endif
p_kwrest: kwrest_mark tIDENTIFIER
{
_, (id, line) = val
@@ -2549,12 +2563,17 @@
{
v1, _ = val
result = s(:dot3, v1, nil).line v1.line
}
+#if V == 30
| p_variable
+#endif
| p_var_ref
+#if V > 30
+ | p_expr_ref
+#endif
| p_const
| tBDOT2 p_primitive
{
_, v1 = val
@@ -2584,30 +2603,39 @@
}
| lambda
p_variable: tIDENTIFIER
{
- (id, line), = val
-
# TODO: error_duplicate_pattern_variable(p, $1, &@1);
# TODO: assignable(p, $1, 0, &@$);
- result = s(:lvar, id.to_sym).line line
+ result = wrap :lvar, val[0]
}
p_var_ref: tCARET tIDENTIFIER
{
- _, (id, line) = val
-
# TODO: check id against env for lvar or dvar
+ result = wrap :lvar, val[1]
+ }
+#if V > 30
+ | tCARET nonlocal_var
+ {
+ _, var = val
+ result = var
+ }
+#endif
- result = s(:lvar, id.to_sym).line line
+#if V > 30
+ p_expr_ref: tCARET tLPAREN expr_value rparen
+ {
+ _, _, expr, _ = val
+ result = expr # TODO? s(:begin, expr).line expr.line
}
+#endif
p_const: tCOLON3 cname
{
- _, (id, line) = val
- result = s(:colon3, id.to_sym).line line
+ result = wrap :colon3, val[1]
}
| p_const tCOLON2 cname
{
lhs, _, (id, _line) = val
@@ -2615,12 +2643,11 @@
result = s(:const, s(:colon2, lhs, id.to_sym).line(l)).line l
}
| tCONSTANT
{
# TODO $$ = gettable(p, $1, &@$);
- (id, line), = val
- result = s(:const, id.to_sym).line line
+ result = wrap :const, val[0]
}
######################################################################
opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
{
@@ -2674,11 +2701,11 @@
result = str
}
string: tCHAR
{
- debug 36
+ debug 12
}
| string1
| string string1
{
result = self.literal_concat val[0], val[1]
@@ -2895,48 +2922,41 @@
result = s(:evstr, stmt).line line
end
when nil then
result = s(:evstr).line line
else
- debug 37
+ debug 13
raise "unknown string body: #{stmt.inspect}"
end
}
string_dvar: tGVAR
{
- (id, line), = val
- result = s(:gvar, id.to_sym).line line
+ result = wrap :gvar, val[0]
}
| tIVAR
{
- (id, line), = val
- result = s(:ivar, id.to_sym).line line
+ result = wrap :ivar, val[0]
}
| tCVAR
{
- (id, line), = val
- result = s(:cvar, id.to_sym).line line
+ result = wrap :cvar, val[0]
}
| backref
symbol: ssym
| dsym
ssym: tSYMBEG sym
{
- _, (id, line) = val
-
lexer.lex_state = EXPR_END
- result = s(:lit, id.to_sym).line line
+ result = wrap :lit, val[1]
}
| tSYMBOL
{
- (id, line), = val
-
lexer.lex_state = EXPR_END
- result = s(:lit, id.to_sym).line line
+ result = wrap :lit, val[0]
}
sym: fname | tIVAR | tGVAR | tCVAR
dsym: tSYMBEG string_contents tSTRING_END
@@ -2953,11 +2973,11 @@
when :str then
result = s(:lit, result.last.to_sym).line result.line
when :evstr then
result = s(:dsym, "", result).line result.line
else
- debug 38
+ debug 14
end
}
numeric: simple_numeric
| tUMINUS_NUM simple_numeric =tLOWEST
@@ -2969,10 +2989,16 @@
simple_numeric: tINTEGER
| tFLOAT
| tRATIONAL
| tIMAGINARY
+#if V > 30
+ nonlocal_var: tIVAR { result = wrap :ivar, val[0] }
+ | tGVAR { result = wrap :gvar, val[0] }
+ | tCVAR { result = wrap :cvar, val[0] }
+#endif
+
user_variable: tIDENTIFIER
| tIVAR
| tGVAR
| tCONSTANT
| tCVAR
@@ -3013,11 +3039,11 @@
result = self.assignable val[0]
}
| keyword_variable
{
result = self.assignable val[0]
- debug 39
+ debug 15
}
backref: tNTH_REF
{
(ref, line), = val
@@ -3051,18 +3077,20 @@
f_paren_args: tLPAREN2 f_args rparen
{
result = end_args val
}
+#if V == 30
| tLPAREN2 f_arg tCOMMA args_forward rparen
{
result = end_args val
}
| tLPAREN2 args_forward rparen
{
result = end_args val
}
+#endif
f_arglist: f_paren_args
| {
result = self.in_kwarg
self.in_kwarg = true
@@ -3084,10 +3112,13 @@
| f_any_kwrest opt_f_block_arg
{
result = args val
}
| f_block_arg
+#if V > 30
+ | args_forward
+#endif
opt_args_tail: tCOMMA args_tail
{
result = val[1]
}
@@ -3294,21 +3325,37 @@
id = :"**"
self.env[id] = :lvar # TODO: needed?!?
result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
}
- f_opt: f_arg_asgn tEQL arg_value
+ f_opt: f_arg_asgn
+#if V > 30
+ f_eq
+#else
+ tEQL
+#endif
+ arg_value
{
lhs, _, rhs = val
result = self.assignable lhs, rhs
# TODO: detect duplicate names
+ # TODO? p->cur_arg = 0;
+ # TODO? p->ctxt.in_argdef = 1;
}
- f_block_opt: f_arg_asgn tEQL primary_value
+ f_block_opt: f_arg_asgn
+#if V > 30
+ f_eq
+#else
+ tEQL
+#endif
+ primary_value
{
lhs, _, rhs = val
result = self.assignable lhs, rhs
+ # TODO? p->cur_arg = 0;
+ # TODO? p->ctxt.in_argdef = 1;
}
f_block_optarg: f_block_opt
{
optblk, = val
@@ -3356,11 +3403,17 @@
identifier = id.to_sym
self.env[identifier] = :lvar
result = ["&#{identifier}".to_sym, line]
}
+ | blkarg_mark
+ {
+ (_, line), = val
+ result = [:&, line]
+ }
+
opt_f_block_arg: tCOMMA f_block_arg
{
_, arg = val
result = arg
}
@@ -3402,13 +3455,20 @@
v1, _, v2 = val
result = s(:array, v1, v2).line v1.line
}
| tLABEL arg_value
{
- (label, line), arg = val
+ label, arg = val
- lit = s(:lit, label.to_sym).line line
- result = s(:array, lit, arg).line line
+ lit = wrap :lit, label
+ result = s(:array, lit, arg).line lit.line
+ }
+ | tLABEL
+ {
+ lit = wrap :lit, val[0]
+ arg = nil
+
+ result = s(:array, lit, arg).line lit.line
}
| tSTRING_BEG string_contents tLABEL_END arg_value
{
(_, line), sym, _, value = val