ruby_parser 3.20.3 → 3.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +32 -0
- data/Manifest.txt +14 -24
- data/README.rdoc +3 -3
- data/Rakefile +113 -115
- data/compare/normalize.rb +2 -0
- data/lib/ruby_lexer.rb +9 -16
- data/lib/ruby_lexer.rex.rb +1 -2
- data/lib/ruby_parser.rb +15 -13
- data/lib/{ruby_parser.yy → ruby_parser2.yy} +3 -10
- data/lib/{ruby20_parser.rb → ruby_parser20.rb} +9 -12
- data/lib/{ruby21_parser.rb → ruby_parser21.rb} +9 -12
- data/lib/{ruby22_parser.rb → ruby_parser22.rb} +9 -12
- data/lib/{ruby23_parser.rb → ruby_parser23.rb} +9 -12
- data/lib/{ruby24_parser.rb → ruby_parser24.rb} +9 -12
- data/lib/{ruby25_parser.rb → ruby_parser25.rb} +9 -12
- data/lib/{ruby26_parser.rb → ruby_parser26.rb} +9 -12
- data/lib/{ruby27_parser.rb → ruby_parser27.rb} +9 -12
- data/lib/{ruby3_parser.yy → ruby_parser3.yy} +7 -33
- data/lib/{ruby30_parser.rb → ruby_parser30.rb} +11 -35
- data/lib/{ruby31_parser.rb → ruby_parser31.rb} +11 -35
- data/lib/{ruby32_parser.rb → ruby_parser32.rb} +11 -35
- data/lib/ruby_parser33.rb +13577 -0
- data/lib/ruby_parser_extras.rb +34 -17
- data/test/test_ruby_lexer.rb +5 -5
- data/test/test_ruby_parser.rb +21 -19
- data.tar.gz.sig +0 -0
- metadata +41 -51
- metadata.gz.sig +0 -0
- data/lib/ruby20_parser.y +0 -2707
- data/lib/ruby21_parser.y +0 -2724
- data/lib/ruby22_parser.y +0 -2735
- data/lib/ruby23_parser.y +0 -2737
- data/lib/ruby24_parser.y +0 -2745
- data/lib/ruby25_parser.y +0 -2745
- data/lib/ruby26_parser.y +0 -2760
- data/lib/ruby27_parser.y +0 -3360
- data/lib/ruby30_parser.y +0 -3508
- data/lib/ruby31_parser.y +0 -3542
- data/lib/ruby32_parser.y +0 -3543
data/lib/ruby26_parser.y
DELETED
@@ -1,2760 +0,0 @@
|
|
1
|
-
# -*- racc -*-
|
2
|
-
|
3
|
-
class Ruby26Parser
|
4
|
-
|
5
|
-
token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
|
6
|
-
kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
|
7
|
-
kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kDO_LAMBDA kRETURN kYIELD kSUPER
|
8
|
-
kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
|
9
|
-
kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
|
10
|
-
k__FILE__ k__ENCODING__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT
|
11
|
-
tLABEL tCVAR tNTH_REF tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT
|
12
|
-
tREGEXP_END tUPLUS tUMINUS tUMINUS_NUM tPOW tCMP tEQ tEQQ tNEQ
|
13
|
-
tGEQ tLEQ tANDOP tOROP tMATCH tNMATCH tDOT tDOT2 tDOT3 tAREF
|
14
|
-
tASET tLSHFT tRSHFT tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN
|
15
|
-
tLPAREN2 tRPAREN tLPAREN_ARG tLBRACK tLBRACK2 tRBRACK tLBRACE
|
16
|
-
tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2 tTILDE tPERCENT tDIVIDE
|
17
|
-
tPLUS tMINUS tLT tGT tPIPE tBANG tCARET tLCURLY tRCURLY
|
18
|
-
tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
|
19
|
-
tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END
|
20
|
-
tSTRING tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA
|
21
|
-
tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND
|
22
|
-
tRATIONAL tIMAGINARY
|
23
|
-
tLABEL_END
|
24
|
-
tLONELY
|
25
|
-
tBDOT2 tBDOT3
|
26
|
-
|
27
|
-
preclow
|
28
|
-
nonassoc tLOWEST
|
29
|
-
nonassoc tLBRACE_ARG
|
30
|
-
nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
|
31
|
-
left kOR kAND
|
32
|
-
right kNOT
|
33
|
-
nonassoc kDEFINED
|
34
|
-
right tEQL tOP_ASGN
|
35
|
-
left kRESCUE_MOD
|
36
|
-
right tEH tCOLON
|
37
|
-
nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
|
38
|
-
left tOROP
|
39
|
-
left tANDOP
|
40
|
-
nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
|
41
|
-
left tGT tGEQ tLT tLEQ
|
42
|
-
left tPIPE tCARET
|
43
|
-
left tAMPER2
|
44
|
-
left tLSHFT tRSHFT
|
45
|
-
left tPLUS tMINUS
|
46
|
-
left tSTAR2 tDIVIDE tPERCENT # TODO: tSTAR2 -> tMULT
|
47
|
-
right tUMINUS_NUM tUMINUS
|
48
|
-
right tPOW
|
49
|
-
right tBANG tTILDE tUPLUS
|
50
|
-
prechigh
|
51
|
-
|
52
|
-
rule
|
53
|
-
|
54
|
-
program: {
|
55
|
-
self.lexer.lex_state = EXPR_BEG
|
56
|
-
}
|
57
|
-
top_compstmt
|
58
|
-
{
|
59
|
-
result = new_compstmt val
|
60
|
-
|
61
|
-
lexer.cond.pop # local_pop
|
62
|
-
lexer.cmdarg.pop
|
63
|
-
}
|
64
|
-
|
65
|
-
top_compstmt: top_stmts opt_terms
|
66
|
-
{
|
67
|
-
stmt, _ = val
|
68
|
-
result = stmt
|
69
|
-
}
|
70
|
-
|
71
|
-
top_stmts: none
|
72
|
-
| top_stmt
|
73
|
-
| top_stmts terms top_stmt
|
74
|
-
{
|
75
|
-
result = self.block_append val[0], val[2]
|
76
|
-
}
|
77
|
-
| error top_stmt
|
78
|
-
|
79
|
-
top_stmt: stmt
|
80
|
-
| klBEGIN
|
81
|
-
{
|
82
|
-
if (self.in_def || self.in_single > 0) then
|
83
|
-
debug 11
|
84
|
-
yyerror "BEGIN in method"
|
85
|
-
end
|
86
|
-
self.env.extend
|
87
|
-
}
|
88
|
-
begin_block
|
89
|
-
{
|
90
|
-
(_, lineno), _, iter = val
|
91
|
-
iter.line lineno
|
92
|
-
|
93
|
-
(_, preexe,) = iter
|
94
|
-
preexe.line lineno
|
95
|
-
|
96
|
-
result = iter
|
97
|
-
}
|
98
|
-
|
99
|
-
begin_block: tLCURLY { result = lexer.lineno } top_compstmt tRCURLY
|
100
|
-
{
|
101
|
-
_, line, stmt, _ = val
|
102
|
-
result = new_iter s(:preexe).line(line), 0, stmt
|
103
|
-
}
|
104
|
-
|
105
|
-
bodystmt: compstmt opt_rescue k_else
|
106
|
-
{
|
107
|
-
res = _values[-2]
|
108
|
-
# TODO: move down to main match so I can just use val
|
109
|
-
|
110
|
-
yyerror "else without rescue is useless" unless res
|
111
|
-
}
|
112
|
-
compstmt
|
113
|
-
opt_ensure
|
114
|
-
{
|
115
|
-
body, resc, _, _, els, ens = val
|
116
|
-
|
117
|
-
result = new_body [body, resc, els, ens]
|
118
|
-
}
|
119
|
-
| compstmt opt_rescue opt_ensure
|
120
|
-
{
|
121
|
-
body, resc, ens = val
|
122
|
-
|
123
|
-
result = new_body [body, resc, nil, ens]
|
124
|
-
}
|
125
|
-
|
126
|
-
compstmt: stmts opt_terms
|
127
|
-
{
|
128
|
-
result = new_compstmt val
|
129
|
-
}
|
130
|
-
|
131
|
-
stmts: none
|
132
|
-
| stmt_or_begin # TODO: newline_node ?
|
133
|
-
| stmts terms stmt_or_begin
|
134
|
-
{
|
135
|
-
result = self.block_append val[0], val[2]
|
136
|
-
}
|
137
|
-
| error stmt
|
138
|
-
{
|
139
|
-
result = val[1]
|
140
|
-
debug 12
|
141
|
-
}
|
142
|
-
|
143
|
-
stmt_or_begin: stmt
|
144
|
-
| klBEGIN
|
145
|
-
{
|
146
|
-
yyerror "BEGIN is permitted only at toplevel"
|
147
|
-
}
|
148
|
-
begin_block
|
149
|
-
{
|
150
|
-
result = val[2] # wtf?
|
151
|
-
}
|
152
|
-
|
153
|
-
stmt: kALIAS fitem
|
154
|
-
{
|
155
|
-
lexer.lex_state = EXPR_FNAME
|
156
|
-
}
|
157
|
-
fitem
|
158
|
-
{
|
159
|
-
(_, line), lhs, _, rhs = val
|
160
|
-
result = s(:alias, lhs, rhs).line(line).line line
|
161
|
-
}
|
162
|
-
| kALIAS tGVAR tGVAR
|
163
|
-
{
|
164
|
-
(_, line), (lhs, _), (rhs, _) = val
|
165
|
-
result = s(:valias, lhs.to_sym, rhs.to_sym).line line
|
166
|
-
}
|
167
|
-
| kALIAS tGVAR tBACK_REF
|
168
|
-
{
|
169
|
-
(_, line), (lhs, _), (rhs, _) = val
|
170
|
-
result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
|
171
|
-
}
|
172
|
-
| kALIAS tGVAR tNTH_REF
|
173
|
-
{
|
174
|
-
yyerror "can't make alias for the number variables"
|
175
|
-
}
|
176
|
-
| kUNDEF undef_list
|
177
|
-
{
|
178
|
-
result = val[1]
|
179
|
-
}
|
180
|
-
| stmt kIF_MOD expr_value
|
181
|
-
{
|
182
|
-
t, _, c = val
|
183
|
-
result = new_if c, t, nil
|
184
|
-
}
|
185
|
-
| stmt kUNLESS_MOD expr_value
|
186
|
-
{
|
187
|
-
f, _, c = val
|
188
|
-
result = new_if c, nil, f
|
189
|
-
}
|
190
|
-
| stmt kWHILE_MOD expr_value
|
191
|
-
{
|
192
|
-
e, _, c = val
|
193
|
-
result = new_while e, c, true
|
194
|
-
}
|
195
|
-
| stmt kUNTIL_MOD expr_value
|
196
|
-
{
|
197
|
-
e, _, c = val
|
198
|
-
result = new_until e, c, true
|
199
|
-
}
|
200
|
-
| stmt kRESCUE_MOD stmt
|
201
|
-
{
|
202
|
-
body, _, resbody = val
|
203
|
-
|
204
|
-
resbody = new_resbody s(:array).line(resbody.line), resbody
|
205
|
-
result = new_rescue body, resbody
|
206
|
-
}
|
207
|
-
| klEND tLCURLY compstmt tRCURLY
|
208
|
-
{
|
209
|
-
(_, line), _, stmt, _ = val
|
210
|
-
|
211
|
-
if (self.in_def || self.in_single > 0) then
|
212
|
-
debug 13
|
213
|
-
yyerror "END in method; use at_exit"
|
214
|
-
end
|
215
|
-
|
216
|
-
result = new_iter s(:postexe).line(line), 0, stmt
|
217
|
-
}
|
218
|
-
| command_asgn
|
219
|
-
| mlhs tEQL command_call
|
220
|
-
{
|
221
|
-
result = new_masgn val[0], val[2], :wrap
|
222
|
-
}
|
223
|
-
| lhs tEQL mrhs
|
224
|
-
{
|
225
|
-
lhs, _, rhs = val
|
226
|
-
|
227
|
-
result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
|
228
|
-
}
|
229
|
-
| mlhs tEQL mrhs_arg
|
230
|
-
{
|
231
|
-
result = new_masgn val[0], val[2]
|
232
|
-
}
|
233
|
-
| expr
|
234
|
-
|
235
|
-
command_asgn: lhs tEQL command_rhs
|
236
|
-
{
|
237
|
-
result = new_assign val[0], val[2]
|
238
|
-
}
|
239
|
-
# | lhs tEQL command_asgn
|
240
|
-
# {
|
241
|
-
# result = new_assign val[0], val[2]
|
242
|
-
# }
|
243
|
-
| var_lhs tOP_ASGN command_rhs
|
244
|
-
{
|
245
|
-
result = new_op_asgn val
|
246
|
-
}
|
247
|
-
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_rhs
|
248
|
-
{
|
249
|
-
result = new_op_asgn1 val
|
250
|
-
}
|
251
|
-
| primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
|
252
|
-
{
|
253
|
-
prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
|
254
|
-
|
255
|
-
result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
|
256
|
-
result.sexp_type = :safe_op_asgn if call_op == '&.'
|
257
|
-
result.line prim.line
|
258
|
-
}
|
259
|
-
| primary_value call_op tCONSTANT tOP_ASGN command_rhs
|
260
|
-
{
|
261
|
-
prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
|
262
|
-
|
263
|
-
result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
|
264
|
-
result.sexp_type = :safe_op_asgn if call_op == '&.'
|
265
|
-
result.line prim.line
|
266
|
-
}
|
267
|
-
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
|
268
|
-
{
|
269
|
-
lhs1, _, (lhs2, line), (id, _), rhs = val
|
270
|
-
|
271
|
-
result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
|
272
|
-
}
|
273
|
-
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
|
274
|
-
{
|
275
|
-
lhs1, _, (lhs2, line), (id, _), rhs = val
|
276
|
-
|
277
|
-
result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
|
278
|
-
}
|
279
|
-
| backref tOP_ASGN command_rhs
|
280
|
-
{
|
281
|
-
self.backref_assign_error val[0]
|
282
|
-
}
|
283
|
-
|
284
|
-
command_rhs: command_call =tOP_ASGN
|
285
|
-
{
|
286
|
-
expr, = val
|
287
|
-
result = value_expr expr
|
288
|
-
}
|
289
|
-
| command_call kRESCUE_MOD stmt
|
290
|
-
{
|
291
|
-
expr, (_, line), resbody = val
|
292
|
-
|
293
|
-
expr = value_expr expr
|
294
|
-
ary = s(:array).line line
|
295
|
-
result = new_rescue(expr, new_resbody(ary, resbody))
|
296
|
-
}
|
297
|
-
| command_asgn
|
298
|
-
|
299
|
-
expr: command_call
|
300
|
-
| expr kAND expr
|
301
|
-
{
|
302
|
-
lhs, _, rhs = val
|
303
|
-
result = logical_op :and, lhs, rhs
|
304
|
-
}
|
305
|
-
| expr kOR expr
|
306
|
-
{
|
307
|
-
lhs, _, rhs = val
|
308
|
-
result = logical_op :or, lhs, rhs
|
309
|
-
}
|
310
|
-
| kNOT opt_nl expr
|
311
|
-
{
|
312
|
-
(_, line), _, expr = val
|
313
|
-
result = new_call(expr, :"!").line line
|
314
|
-
# REFACTOR: call_uni_op
|
315
|
-
}
|
316
|
-
| tBANG command_call
|
317
|
-
{
|
318
|
-
_, cmd = val
|
319
|
-
result = new_call(cmd, :"!").line cmd.line
|
320
|
-
# TODO: fix line number to tBANG... but causes BAD shift/reduce conflict
|
321
|
-
# REFACTOR: call_uni_op -- see parse26.y
|
322
|
-
}
|
323
|
-
| arg =tLBRACE_ARG
|
324
|
-
|
325
|
-
expr_value: expr
|
326
|
-
{
|
327
|
-
result = value_expr(val[0])
|
328
|
-
}
|
329
|
-
|
330
|
-
expr_value_do: {
|
331
|
-
lexer.cond.push true
|
332
|
-
}
|
333
|
-
expr_value do
|
334
|
-
{
|
335
|
-
lexer.cond.pop
|
336
|
-
}
|
337
|
-
{
|
338
|
-
_, expr, _, _ = val
|
339
|
-
result = expr
|
340
|
-
}
|
341
|
-
|
342
|
-
command_call: command
|
343
|
-
| block_command
|
344
|
-
|
345
|
-
block_command: block_call
|
346
|
-
| block_call call_op2 operation2 command_args
|
347
|
-
{
|
348
|
-
blk, _, (msg, _line), args = val
|
349
|
-
result = new_call(blk, msg.to_sym, args).line blk.line
|
350
|
-
}
|
351
|
-
|
352
|
-
cmd_brace_block: tLBRACE_ARG
|
353
|
-
{
|
354
|
-
# self.env.extend(:dynamic)
|
355
|
-
result = self.lexer.lineno
|
356
|
-
}
|
357
|
-
brace_body tRCURLY
|
358
|
-
{
|
359
|
-
_, line, body, _ = val
|
360
|
-
|
361
|
-
result = body
|
362
|
-
result.line line
|
363
|
-
|
364
|
-
# self.env.unextend
|
365
|
-
}
|
366
|
-
|
367
|
-
fcall: operation
|
368
|
-
{
|
369
|
-
(msg, line), = val
|
370
|
-
result = new_call(nil, msg.to_sym).line line
|
371
|
-
}
|
372
|
-
|
373
|
-
command: fcall command_args =tLOWEST
|
374
|
-
{
|
375
|
-
call, args = val
|
376
|
-
result = call.concat args.sexp_body
|
377
|
-
}
|
378
|
-
| fcall command_args cmd_brace_block
|
379
|
-
{
|
380
|
-
call, args, block = val
|
381
|
-
|
382
|
-
result = call.concat args.sexp_body
|
383
|
-
|
384
|
-
if block then
|
385
|
-
block_dup_check result, block
|
386
|
-
|
387
|
-
result, operation = block, result
|
388
|
-
result.insert 1, operation
|
389
|
-
end
|
390
|
-
}
|
391
|
-
| primary_value call_op operation2 command_args =tLOWEST
|
392
|
-
{
|
393
|
-
lhs, callop, (op, _), args = val
|
394
|
-
|
395
|
-
result = new_call lhs, op.to_sym, args, callop
|
396
|
-
result.line lhs.line
|
397
|
-
}
|
398
|
-
| primary_value call_op operation2 command_args cmd_brace_block
|
399
|
-
{
|
400
|
-
recv, _, (msg, _line), args, block = val
|
401
|
-
call = new_call recv, msg.to_sym, args, val[1]
|
402
|
-
|
403
|
-
block_dup_check call, block
|
404
|
-
|
405
|
-
block.insert 1, call
|
406
|
-
result = block
|
407
|
-
}
|
408
|
-
| primary_value tCOLON2 operation2 command_args =tLOWEST
|
409
|
-
{
|
410
|
-
lhs, _, (id, line), args = val
|
411
|
-
|
412
|
-
result = new_call lhs, id.to_sym, args
|
413
|
-
result.line line
|
414
|
-
}
|
415
|
-
| primary_value tCOLON2 operation2 command_args cmd_brace_block
|
416
|
-
{
|
417
|
-
recv, _, (msg, _line), args, block = val
|
418
|
-
call = new_call recv, msg.to_sym, args
|
419
|
-
|
420
|
-
block_dup_check call, block
|
421
|
-
|
422
|
-
block.insert 1, call
|
423
|
-
result = block
|
424
|
-
}
|
425
|
-
| kSUPER command_args
|
426
|
-
{
|
427
|
-
result = new_super val[1]
|
428
|
-
}
|
429
|
-
| kYIELD command_args
|
430
|
-
{
|
431
|
-
(_, line), args = val
|
432
|
-
result = new_yield args
|
433
|
-
result.line line # TODO: push to new_yield
|
434
|
-
}
|
435
|
-
| k_return call_args
|
436
|
-
{
|
437
|
-
line = val[0].last
|
438
|
-
result = s(:return, ret_args(val[1])).line(line)
|
439
|
-
}
|
440
|
-
| kBREAK call_args
|
441
|
-
{
|
442
|
-
(_, line), args = val
|
443
|
-
result = s(:break, ret_args(args)).line line
|
444
|
-
}
|
445
|
-
| kNEXT call_args
|
446
|
-
{
|
447
|
-
line = val[0].last
|
448
|
-
result = s(:next, ret_args(val[1])).line(line)
|
449
|
-
}
|
450
|
-
|
451
|
-
mlhs: mlhs_basic
|
452
|
-
| tLPAREN mlhs_inner rparen
|
453
|
-
{
|
454
|
-
result = val[1]
|
455
|
-
}
|
456
|
-
|
457
|
-
mlhs_inner: mlhs_basic
|
458
|
-
| tLPAREN mlhs_inner rparen
|
459
|
-
{
|
460
|
-
_, arg, _ = val
|
461
|
-
l = arg.line
|
462
|
-
|
463
|
-
result = s(:masgn, s(:array, arg).line(l)).line l
|
464
|
-
}
|
465
|
-
|
466
|
-
mlhs_basic: mlhs_head
|
467
|
-
{
|
468
|
-
head, = val
|
469
|
-
result = s(:masgn, head).line head.line
|
470
|
-
}
|
471
|
-
| mlhs_head mlhs_item
|
472
|
-
{
|
473
|
-
lhs, rhs = val
|
474
|
-
result = s(:masgn, lhs << rhs.compact).line lhs.line
|
475
|
-
}
|
476
|
-
| mlhs_head tSTAR mlhs_node
|
477
|
-
{
|
478
|
-
head, _, tail = val
|
479
|
-
head << s(:splat, tail).line(tail.line)
|
480
|
-
result = s(:masgn, head).line head.line
|
481
|
-
}
|
482
|
-
| mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
|
483
|
-
{
|
484
|
-
ary1, _, splat, _, ary2 = val
|
485
|
-
|
486
|
-
result = list_append ary1, s(:splat, splat).line(splat.line)
|
487
|
-
result.concat ary2.sexp_body
|
488
|
-
result = s(:masgn, result).line result.line
|
489
|
-
}
|
490
|
-
| mlhs_head tSTAR
|
491
|
-
{
|
492
|
-
head, _ = val
|
493
|
-
l = head.line
|
494
|
-
result = s(:masgn, head << s(:splat).line(l)).line l
|
495
|
-
}
|
496
|
-
| mlhs_head tSTAR tCOMMA mlhs_post
|
497
|
-
{
|
498
|
-
head, _, _, post = val
|
499
|
-
ary = list_append head, s(:splat).line(head.line)
|
500
|
-
ary.concat post.sexp_body
|
501
|
-
result = s(:masgn, ary).line ary.line
|
502
|
-
}
|
503
|
-
| tSTAR mlhs_node
|
504
|
-
{
|
505
|
-
_, node = val
|
506
|
-
l = node.line
|
507
|
-
splat = s(:splat, node).line l
|
508
|
-
ary = s(:array, splat).line l
|
509
|
-
result = s(:masgn, ary).line l
|
510
|
-
}
|
511
|
-
| tSTAR mlhs_node tCOMMA mlhs_post
|
512
|
-
{
|
513
|
-
_, node, _, post = val
|
514
|
-
|
515
|
-
splat = s(:splat, node).line node.line
|
516
|
-
ary = s(:array, splat).line splat.line
|
517
|
-
ary.concat post.sexp_body
|
518
|
-
result = s(:masgn, ary).line ary.line
|
519
|
-
}
|
520
|
-
| tSTAR
|
521
|
-
{
|
522
|
-
l = lexer.lineno
|
523
|
-
result = s(:masgn, s(:array, s(:splat).line(l)).line(l)).line l
|
524
|
-
}
|
525
|
-
| tSTAR tCOMMA mlhs_post
|
526
|
-
{
|
527
|
-
_, _, post = val
|
528
|
-
l = post.line
|
529
|
-
|
530
|
-
splat = s(:splat).line l
|
531
|
-
ary = s(:array, splat, *post.sexp_body).line l
|
532
|
-
result = s(:masgn, ary).line l
|
533
|
-
}
|
534
|
-
|
535
|
-
mlhs_item: mlhs_node
|
536
|
-
| tLPAREN mlhs_inner rparen
|
537
|
-
{
|
538
|
-
result = val[1]
|
539
|
-
}
|
540
|
-
|
541
|
-
mlhs_head: mlhs_item tCOMMA
|
542
|
-
{
|
543
|
-
lhs, _ = val
|
544
|
-
result = s(:array, lhs).line lhs.line
|
545
|
-
}
|
546
|
-
| mlhs_head mlhs_item tCOMMA
|
547
|
-
{
|
548
|
-
result = val[0] << val[1].compact
|
549
|
-
}
|
550
|
-
|
551
|
-
mlhs_post: mlhs_item
|
552
|
-
{
|
553
|
-
item, = val
|
554
|
-
result = s(:array, item).line item.line
|
555
|
-
}
|
556
|
-
| mlhs_post tCOMMA mlhs_item
|
557
|
-
{
|
558
|
-
result = list_append val[0], val[2]
|
559
|
-
}
|
560
|
-
|
561
|
-
mlhs_node: user_variable
|
562
|
-
{
|
563
|
-
result = self.assignable val[0]
|
564
|
-
}
|
565
|
-
| keyword_variable
|
566
|
-
{
|
567
|
-
result = self.assignable val[0]
|
568
|
-
}
|
569
|
-
| primary_value tLBRACK2 opt_call_args rbracket
|
570
|
-
{
|
571
|
-
result = self.aryset val[0], val[2]
|
572
|
-
}
|
573
|
-
| primary_value call_op tIDENTIFIER
|
574
|
-
{
|
575
|
-
lhs, call_op, (id, _line) = val
|
576
|
-
|
577
|
-
result = new_attrasgn lhs, id, call_op
|
578
|
-
}
|
579
|
-
| primary_value tCOLON2 tIDENTIFIER
|
580
|
-
{
|
581
|
-
recv, _, (id, _line) = val
|
582
|
-
result = new_attrasgn recv, id
|
583
|
-
}
|
584
|
-
| primary_value call_op tCONSTANT
|
585
|
-
{
|
586
|
-
lhs, call_op, (id, _line) = val
|
587
|
-
|
588
|
-
result = new_attrasgn lhs, id, call_op
|
589
|
-
}
|
590
|
-
| primary_value tCOLON2 tCONSTANT
|
591
|
-
{
|
592
|
-
if (self.in_def || self.in_single > 0) then
|
593
|
-
debug 14
|
594
|
-
yyerror "dynamic constant assignment"
|
595
|
-
end
|
596
|
-
|
597
|
-
expr, _, (id, _line) = val
|
598
|
-
l = expr.line
|
599
|
-
|
600
|
-
result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
|
601
|
-
}
|
602
|
-
| tCOLON3 tCONSTANT
|
603
|
-
{
|
604
|
-
if (self.in_def || self.in_single > 0) then
|
605
|
-
debug 15
|
606
|
-
yyerror "dynamic constant assignment"
|
607
|
-
end
|
608
|
-
|
609
|
-
_, (id, l) = val
|
610
|
-
|
611
|
-
result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
|
612
|
-
}
|
613
|
-
| backref
|
614
|
-
{
|
615
|
-
ref, = val
|
616
|
-
|
617
|
-
self.backref_assign_error ref
|
618
|
-
}
|
619
|
-
|
620
|
-
lhs: user_variable
|
621
|
-
{
|
622
|
-
var, = val
|
623
|
-
|
624
|
-
result = self.assignable var
|
625
|
-
}
|
626
|
-
| keyword_variable
|
627
|
-
{
|
628
|
-
var, = val
|
629
|
-
|
630
|
-
result = self.assignable var
|
631
|
-
|
632
|
-
debug 16
|
633
|
-
}
|
634
|
-
| primary_value tLBRACK2 opt_call_args rbracket
|
635
|
-
{
|
636
|
-
lhs, _, args, _ = val
|
637
|
-
|
638
|
-
result = self.aryset lhs, args
|
639
|
-
}
|
640
|
-
| primary_value call_op tIDENTIFIER # REFACTOR
|
641
|
-
{
|
642
|
-
lhs, op, (id, _line) = val
|
643
|
-
|
644
|
-
result = new_attrasgn lhs, id, op
|
645
|
-
}
|
646
|
-
| primary_value tCOLON2 tIDENTIFIER
|
647
|
-
{
|
648
|
-
lhs, _, (id, _line) = val
|
649
|
-
|
650
|
-
result = new_attrasgn lhs, id
|
651
|
-
}
|
652
|
-
| primary_value call_op tCONSTANT # REFACTOR?
|
653
|
-
{
|
654
|
-
lhs, call_op, (id, _line) = val
|
655
|
-
|
656
|
-
result = new_attrasgn lhs, id, call_op
|
657
|
-
}
|
658
|
-
| primary_value tCOLON2 tCONSTANT
|
659
|
-
{
|
660
|
-
expr, _, (id, _line) = val
|
661
|
-
|
662
|
-
if (self.in_def || self.in_single > 0) then
|
663
|
-
debug 17
|
664
|
-
yyerror "dynamic constant assignment"
|
665
|
-
end
|
666
|
-
|
667
|
-
l = expr.line
|
668
|
-
result = s(:const, s(:colon2, expr, id.to_sym).line(l)).line l
|
669
|
-
}
|
670
|
-
| tCOLON3 tCONSTANT
|
671
|
-
{
|
672
|
-
_, (id, l) = val
|
673
|
-
|
674
|
-
if (self.in_def || self.in_single > 0) then
|
675
|
-
debug 18
|
676
|
-
yyerror "dynamic constant assignment"
|
677
|
-
end
|
678
|
-
|
679
|
-
result = s(:const, s(:colon3, id.to_sym).line(l)).line l
|
680
|
-
}
|
681
|
-
| backref
|
682
|
-
{
|
683
|
-
self.backref_assign_error val[0]
|
684
|
-
}
|
685
|
-
|
686
|
-
cname: tIDENTIFIER
|
687
|
-
{
|
688
|
-
yyerror "class/module name must be CONSTANT"
|
689
|
-
}
|
690
|
-
| tCONSTANT
|
691
|
-
|
692
|
-
cpath: tCOLON3 cname
|
693
|
-
{
|
694
|
-
result = wrap :colon3, val[1]
|
695
|
-
}
|
696
|
-
| cname
|
697
|
-
{
|
698
|
-
(id, line), = val
|
699
|
-
result = [id.to_sym, line] # TODO: sexp?
|
700
|
-
}
|
701
|
-
| primary_value tCOLON2 cname
|
702
|
-
{
|
703
|
-
pval, _, (name, _line) = val
|
704
|
-
|
705
|
-
result = s(:colon2, pval, name.to_sym)
|
706
|
-
result.line pval.line
|
707
|
-
}
|
708
|
-
|
709
|
-
fname: tIDENTIFIER | tCONSTANT | tFID
|
710
|
-
| op
|
711
|
-
{
|
712
|
-
lexer.lex_state = EXPR_END
|
713
|
-
}
|
714
|
-
|
715
|
-
| reswords
|
716
|
-
|
717
|
-
fitem: fname
|
718
|
-
{
|
719
|
-
result = wrap :lit, val[0]
|
720
|
-
}
|
721
|
-
| symbol
|
722
|
-
|
723
|
-
undef_list: fitem
|
724
|
-
{
|
725
|
-
result = new_undef val[0]
|
726
|
-
}
|
727
|
-
|
|
728
|
-
undef_list tCOMMA
|
729
|
-
{
|
730
|
-
lexer.lex_state = EXPR_FNAME
|
731
|
-
}
|
732
|
-
fitem
|
733
|
-
{
|
734
|
-
result = new_undef val[0], val[3]
|
735
|
-
}
|
736
|
-
|
737
|
-
op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
|
738
|
-
| tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
|
739
|
-
| tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
|
740
|
-
| tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
|
741
|
-
| tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
|
742
|
-
|
743
|
-
reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
|
744
|
-
| kALIAS | kAND | kBEGIN | kBREAK | kCASE
|
745
|
-
| kCLASS | kDEF | kDEFINED | kDO | kELSE
|
746
|
-
| kELSIF | kEND | kENSURE | kFALSE | kFOR
|
747
|
-
| kIN | kMODULE | kNEXT | kNIL | kNOT
|
748
|
-
| kOR | kREDO | kRESCUE | kRETRY | kRETURN
|
749
|
-
| kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
|
750
|
-
| kWHEN | kYIELD | kIF | kUNLESS | kWHILE
|
751
|
-
| kUNTIL
|
752
|
-
|
753
|
-
arg: lhs tEQL arg_rhs
|
754
|
-
{
|
755
|
-
result = new_assign val[0], val[2]
|
756
|
-
}
|
757
|
-
| var_lhs tOP_ASGN arg_rhs
|
758
|
-
{
|
759
|
-
result = new_op_asgn val
|
760
|
-
}
|
761
|
-
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg_rhs
|
762
|
-
{
|
763
|
-
result = new_op_asgn1 val
|
764
|
-
}
|
765
|
-
| primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
|
766
|
-
{
|
767
|
-
result = new_op_asgn2 val
|
768
|
-
}
|
769
|
-
| primary_value call_op tCONSTANT tOP_ASGN arg_rhs
|
770
|
-
{
|
771
|
-
result = new_op_asgn2 val
|
772
|
-
}
|
773
|
-
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
|
774
|
-
{
|
775
|
-
lhs, _, (id, _line), (op, _), rhs = val
|
776
|
-
|
777
|
-
result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
|
778
|
-
}
|
779
|
-
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
|
780
|
-
{
|
781
|
-
lhs1, _, (lhs2, _line), op, rhs = val
|
782
|
-
|
783
|
-
lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
|
784
|
-
result = new_const_op_asgn [lhs, op, rhs]
|
785
|
-
}
|
786
|
-
| tCOLON3 tCONSTANT tOP_ASGN arg_rhs
|
787
|
-
{
|
788
|
-
_, lhs, op, rhs = val
|
789
|
-
|
790
|
-
lhs = wrap :colon3, lhs
|
791
|
-
result = new_const_op_asgn [lhs, op, rhs]
|
792
|
-
}
|
793
|
-
| backref tOP_ASGN arg_rhs
|
794
|
-
{
|
795
|
-
# TODO: lhs = var_field val[0]
|
796
|
-
asgn = new_op_asgn val
|
797
|
-
result = self.backref_assign_error asgn
|
798
|
-
}
|
799
|
-
| arg tDOT2 arg
|
800
|
-
{
|
801
|
-
v1, v2 = val[0], val[2]
|
802
|
-
if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
|
803
|
-
result = s(:lit, (v1.last)..(v2.last)).line v1.line
|
804
|
-
else
|
805
|
-
result = s(:dot2, v1, v2).line v1.line
|
806
|
-
end
|
807
|
-
}
|
808
|
-
| arg tDOT3 arg
|
809
|
-
{
|
810
|
-
v1, v2 = val[0], val[2]
|
811
|
-
if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
|
812
|
-
result = s(:lit, (v1.last)...(v2.last)).line v1.line
|
813
|
-
else
|
814
|
-
result = s(:dot3, v1, v2).line v1.line
|
815
|
-
end
|
816
|
-
}
|
817
|
-
| arg tDOT2
|
818
|
-
{
|
819
|
-
v1, _ = val
|
820
|
-
v2 = nil
|
821
|
-
|
822
|
-
result = s(:dot2, v1, v2).line v1.line
|
823
|
-
}
|
824
|
-
| arg tDOT3
|
825
|
-
{
|
826
|
-
v1, _ = val
|
827
|
-
v2 = nil
|
828
|
-
|
829
|
-
result = s(:dot3, v1, v2).line v1.line
|
830
|
-
}
|
831
|
-
|
832
|
-
|
833
|
-
| arg tPLUS arg
|
834
|
-
{
|
835
|
-
result = new_call val[0], :+, argl(val[2])
|
836
|
-
}
|
837
|
-
| arg tMINUS arg
|
838
|
-
{
|
839
|
-
result = new_call val[0], :-, argl(val[2])
|
840
|
-
}
|
841
|
-
| arg tSTAR2 arg # TODO: rename
|
842
|
-
{
|
843
|
-
result = new_call val[0], :*, argl(val[2])
|
844
|
-
}
|
845
|
-
| arg tDIVIDE arg
|
846
|
-
{
|
847
|
-
result = new_call val[0], :"/", argl(val[2])
|
848
|
-
}
|
849
|
-
| arg tPERCENT arg
|
850
|
-
{
|
851
|
-
result = new_call val[0], :"%", argl(val[2])
|
852
|
-
}
|
853
|
-
| arg tPOW arg
|
854
|
-
{
|
855
|
-
result = new_call val[0], :**, argl(val[2])
|
856
|
-
}
|
857
|
-
| tUMINUS_NUM simple_numeric tPOW arg
|
858
|
-
{
|
859
|
-
_, (num, line), _, arg = val
|
860
|
-
lit = s(:lit, num).line line
|
861
|
-
result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
|
862
|
-
|
863
|
-
}
|
864
|
-
| tUPLUS arg
|
865
|
-
{
|
866
|
-
result = new_call val[1], :"+@"
|
867
|
-
}
|
868
|
-
| tUMINUS arg
|
869
|
-
{
|
870
|
-
result = new_call val[1], :"-@"
|
871
|
-
}
|
872
|
-
| arg tPIPE arg
|
873
|
-
{
|
874
|
-
result = new_call val[0], :"|", argl(val[2])
|
875
|
-
}
|
876
|
-
| arg tCARET arg
|
877
|
-
{
|
878
|
-
result = new_call val[0], :"^", argl(val[2])
|
879
|
-
}
|
880
|
-
| arg tAMPER2 arg
|
881
|
-
{
|
882
|
-
result = new_call val[0], :"&", argl(val[2])
|
883
|
-
}
|
884
|
-
| arg tCMP arg
|
885
|
-
{
|
886
|
-
result = new_call val[0], :"<=>", argl(val[2])
|
887
|
-
}
|
888
|
-
| rel_expr =tCMP
|
889
|
-
| arg tEQ arg
|
890
|
-
{
|
891
|
-
result = new_call val[0], :"==", argl(val[2])
|
892
|
-
}
|
893
|
-
| arg tEQQ arg
|
894
|
-
{
|
895
|
-
result = new_call val[0], :"===", argl(val[2])
|
896
|
-
}
|
897
|
-
| arg tNEQ arg
|
898
|
-
{
|
899
|
-
result = new_call val[0], :"!=", argl(val[2])
|
900
|
-
}
|
901
|
-
| arg tMATCH arg
|
902
|
-
{
|
903
|
-
lhs, _, rhs = val
|
904
|
-
result = new_match lhs, rhs
|
905
|
-
}
|
906
|
-
| arg tNMATCH arg
|
907
|
-
{
|
908
|
-
lhs, _, rhs = val
|
909
|
-
result = s(:not, new_match(lhs, rhs)).line lhs.line
|
910
|
-
}
|
911
|
-
| tBANG arg
|
912
|
-
{
|
913
|
-
_, arg = val
|
914
|
-
result = new_call arg, :"!"
|
915
|
-
result.line arg.line
|
916
|
-
}
|
917
|
-
| tTILDE arg
|
918
|
-
{
|
919
|
-
result = new_call value_expr(val[1]), :"~"
|
920
|
-
}
|
921
|
-
| arg tLSHFT arg
|
922
|
-
{
|
923
|
-
val[0] = value_expr val[0]
|
924
|
-
val[2] = value_expr val[2]
|
925
|
-
result = new_call val[0], :"\<\<", argl(val[2])
|
926
|
-
}
|
927
|
-
| arg tRSHFT arg
|
928
|
-
{
|
929
|
-
val[0] = value_expr val[0]
|
930
|
-
val[2] = value_expr val[2]
|
931
|
-
result = new_call val[0], :">>", argl(val[2])
|
932
|
-
}
|
933
|
-
| arg tANDOP arg
|
934
|
-
{
|
935
|
-
result = logical_op :and, val[0], val[2]
|
936
|
-
}
|
937
|
-
| arg tOROP arg
|
938
|
-
{
|
939
|
-
result = logical_op :or, val[0], val[2]
|
940
|
-
}
|
941
|
-
| kDEFINED opt_nl arg
|
942
|
-
{
|
943
|
-
(_, line), _, arg = val
|
944
|
-
result = s(:defined, arg).line line
|
945
|
-
}
|
946
|
-
| arg tEH arg opt_nl tCOLON arg
|
947
|
-
{
|
948
|
-
c, _, t, _, _, f = val
|
949
|
-
result = s(:if, c, t, f).line c.line
|
950
|
-
}
|
951
|
-
| primary
|
952
|
-
|
953
|
-
relop: tGT
|
954
|
-
| tLT
|
955
|
-
| tGEQ
|
956
|
-
| tLEQ
|
957
|
-
|
958
|
-
rel_expr: arg relop arg =tGT
|
959
|
-
{
|
960
|
-
lhs, (op, _), rhs = val
|
961
|
-
result = new_call lhs, op.to_sym, argl(rhs)
|
962
|
-
}
|
963
|
-
| rel_expr relop arg =tGT
|
964
|
-
{
|
965
|
-
lhs, (op, _), rhs = val
|
966
|
-
warn "comparison '%s' after comparison", op
|
967
|
-
result = new_call lhs, op.to_sym, argl(rhs)
|
968
|
-
}
|
969
|
-
|
970
|
-
arg_value: arg
|
971
|
-
{
|
972
|
-
result = value_expr(val[0])
|
973
|
-
}
|
974
|
-
|
975
|
-
aref_args: none
|
976
|
-
| args trailer
|
977
|
-
{
|
978
|
-
result = args [val[0]]
|
979
|
-
}
|
980
|
-
| args tCOMMA assocs trailer
|
981
|
-
{
|
982
|
-
result = args [val[0], array_to_hash(val[2])]
|
983
|
-
}
|
984
|
-
| assocs trailer
|
985
|
-
{
|
986
|
-
result = args [array_to_hash(val[0])]
|
987
|
-
}
|
988
|
-
|
989
|
-
arg_rhs: arg =tOP_ASGN
|
990
|
-
| arg kRESCUE_MOD arg
|
991
|
-
{
|
992
|
-
body, (_, line), resbody = val
|
993
|
-
body = value_expr body
|
994
|
-
resbody = remove_begin resbody
|
995
|
-
|
996
|
-
ary = s(:array).line line
|
997
|
-
result = new_rescue(body, new_resbody(ary, resbody))
|
998
|
-
}
|
999
|
-
|
1000
|
-
paren_args: tLPAREN2 opt_call_args rparen
|
1001
|
-
{
|
1002
|
-
_, args, (_, line_max) = val
|
1003
|
-
|
1004
|
-
result = args
|
1005
|
-
result.line_max = line_max if args
|
1006
|
-
}
|
1007
|
-
|
1008
|
-
opt_paren_args: none
|
1009
|
-
| paren_args
|
1010
|
-
|
1011
|
-
opt_call_args: none
|
1012
|
-
| call_args
|
1013
|
-
| args tCOMMA
|
1014
|
-
{
|
1015
|
-
result = args val
|
1016
|
-
}
|
1017
|
-
| args tCOMMA assocs tCOMMA
|
1018
|
-
{
|
1019
|
-
result = args [val[0], array_to_hash(val[2])]
|
1020
|
-
}
|
1021
|
-
| assocs tCOMMA
|
1022
|
-
{
|
1023
|
-
result = args [array_to_hash(val[0])]
|
1024
|
-
}
|
1025
|
-
|
1026
|
-
call_args: command
|
1027
|
-
{
|
1028
|
-
warning "parenthesize argument(s) for future version"
|
1029
|
-
result = call_args val
|
1030
|
-
}
|
1031
|
-
| args opt_block_arg
|
1032
|
-
{
|
1033
|
-
result = call_args val
|
1034
|
-
}
|
1035
|
-
| assocs opt_block_arg
|
1036
|
-
{
|
1037
|
-
result = call_args [array_to_hash(val[0]), val[1]]
|
1038
|
-
}
|
1039
|
-
| args tCOMMA assocs opt_block_arg
|
1040
|
-
{
|
1041
|
-
result = call_args [val[0], array_to_hash(val[2]), val[3]]
|
1042
|
-
}
|
1043
|
-
| block_arg
|
1044
|
-
{
|
1045
|
-
result = call_args val
|
1046
|
-
}
|
1047
|
-
|
1048
|
-
command_args: {
|
1049
|
-
# parse26.y line 2200
|
1050
|
-
|
1051
|
-
# If call_args starts with a open paren '(' or
|
1052
|
-
# '[', look-ahead reading of the letters calls
|
1053
|
-
# CMDARG_PUSH(0), but the push must be done
|
1054
|
-
# after CMDARG_PUSH(1). So this code makes them
|
1055
|
-
# consistent by first cancelling the premature
|
1056
|
-
# CMDARG_PUSH(0), doing CMDARG_PUSH(1), and
|
1057
|
-
# finally redoing CMDARG_PUSH(0).
|
1058
|
-
|
1059
|
-
result = yychar = self.last_token_type.first
|
1060
|
-
lookahead = [:tLPAREN, :tLPAREN_ARG, :tLPAREN2, :tLBRACK, :tLBRACK2].include?(yychar)
|
1061
|
-
lexer.cmdarg.pop if lookahead
|
1062
|
-
lexer.cmdarg.push true
|
1063
|
-
lexer.cmdarg.push false if lookahead
|
1064
|
-
}
|
1065
|
-
call_args
|
1066
|
-
{
|
1067
|
-
yychar, args = val
|
1068
|
-
|
1069
|
-
# call_args can be followed by tLBRACE_ARG (that
|
1070
|
-
# does CMDARG_PUSH(0) in the lexer) but the push
|
1071
|
-
# must be done after CMDARG_POP() in the parser.
|
1072
|
-
# So this code does CMDARG_POP() to pop 0 pushed
|
1073
|
-
# by tLBRACE_ARG, CMDARG_POP() to pop 1 pushed
|
1074
|
-
# by command_args, and CMDARG_PUSH(0) to restore
|
1075
|
-
# back the flag set by tLBRACE_ARG.
|
1076
|
-
|
1077
|
-
lookahead = [:tLBRACE_ARG].include?(yychar)
|
1078
|
-
lexer.cmdarg.pop if lookahead
|
1079
|
-
lexer.cmdarg.pop
|
1080
|
-
lexer.cmdarg.push false if lookahead
|
1081
|
-
result = args
|
1082
|
-
}
|
1083
|
-
|
1084
|
-
block_arg: tAMPER arg_value
|
1085
|
-
{
|
1086
|
-
_, arg = val
|
1087
|
-
result = s(:block_pass, arg).line arg.line
|
1088
|
-
}
|
1089
|
-
|
1090
|
-
opt_block_arg: tCOMMA block_arg
|
1091
|
-
{
|
1092
|
-
result = val[1]
|
1093
|
-
}
|
1094
|
-
| none
|
1095
|
-
|
1096
|
-
args: arg_value
|
1097
|
-
{
|
1098
|
-
arg, = val
|
1099
|
-
lineno = arg.line || lexer.lineno # HACK
|
1100
|
-
|
1101
|
-
result = s(:array, arg).line lineno
|
1102
|
-
}
|
1103
|
-
| tSTAR arg_value
|
1104
|
-
{
|
1105
|
-
_, arg = val
|
1106
|
-
result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
|
1107
|
-
}
|
1108
|
-
| args tCOMMA arg_value
|
1109
|
-
{
|
1110
|
-
args, _, id = val
|
1111
|
-
result = self.list_append args, id
|
1112
|
-
}
|
1113
|
-
| args tCOMMA tSTAR arg_value
|
1114
|
-
{
|
1115
|
-
# TODO: the line number from tSTAR has been dropped
|
1116
|
-
args, _, _, id = val
|
1117
|
-
line = lexer.lineno
|
1118
|
-
result = self.list_append args, s(:splat, id).line(line)
|
1119
|
-
}
|
1120
|
-
|
1121
|
-
mrhs_arg: mrhs
|
1122
|
-
{
|
1123
|
-
result = new_masgn_arg val[0]
|
1124
|
-
}
|
1125
|
-
| arg_value
|
1126
|
-
{
|
1127
|
-
result = new_masgn_arg val[0], :wrap
|
1128
|
-
}
|
1129
|
-
|
1130
|
-
mrhs: args tCOMMA arg_value
|
1131
|
-
{
|
1132
|
-
result = val[0] << val[2]
|
1133
|
-
}
|
1134
|
-
| args tCOMMA tSTAR arg_value
|
1135
|
-
{
|
1136
|
-
# TODO: make all tXXXX terminals include lexer.lineno
|
1137
|
-
arg, _, _, splat = val
|
1138
|
-
result = self.arg_concat arg, splat
|
1139
|
-
}
|
1140
|
-
| tSTAR arg_value
|
1141
|
-
{
|
1142
|
-
_, arg = val
|
1143
|
-
result = s(:splat, arg).line arg.line
|
1144
|
-
}
|
1145
|
-
|
1146
|
-
primary: literal
|
1147
|
-
| strings
|
1148
|
-
| xstring
|
1149
|
-
| regexp
|
1150
|
-
| words
|
1151
|
-
| qwords
|
1152
|
-
| symbols
|
1153
|
-
| qsymbols
|
1154
|
-
| var_ref
|
1155
|
-
| backref
|
1156
|
-
| tFID
|
1157
|
-
{
|
1158
|
-
(msg, line), = val
|
1159
|
-
result = new_call nil, msg.to_sym
|
1160
|
-
result.line line
|
1161
|
-
}
|
1162
|
-
| k_begin
|
1163
|
-
{
|
1164
|
-
lexer.cmdarg.push false
|
1165
|
-
}
|
1166
|
-
bodystmt k_end
|
1167
|
-
{
|
1168
|
-
lexer.cmdarg.pop
|
1169
|
-
result = new_begin val
|
1170
|
-
}
|
1171
|
-
| tLPAREN_ARG
|
1172
|
-
{
|
1173
|
-
lexer.lex_state = EXPR_ENDARG
|
1174
|
-
result = lexer.lineno
|
1175
|
-
}
|
1176
|
-
rparen
|
1177
|
-
{
|
1178
|
-
_, line, _ = val
|
1179
|
-
result = s(:begin).line line
|
1180
|
-
}
|
1181
|
-
| tLPAREN_ARG
|
1182
|
-
stmt
|
1183
|
-
{
|
1184
|
-
lexer.lex_state = EXPR_ENDARG
|
1185
|
-
}
|
1186
|
-
rparen
|
1187
|
-
{
|
1188
|
-
_, stmt, _, _, = val
|
1189
|
-
# warning "(...) interpreted as grouped expression"
|
1190
|
-
result = stmt
|
1191
|
-
}
|
1192
|
-
| tLPAREN compstmt tRPAREN
|
1193
|
-
{
|
1194
|
-
_, stmt, _ = val
|
1195
|
-
result = stmt
|
1196
|
-
result ||= s(:nil).line lexer.lineno
|
1197
|
-
result.paren = true
|
1198
|
-
}
|
1199
|
-
| primary_value tCOLON2 tCONSTANT
|
1200
|
-
{
|
1201
|
-
expr, _, (id, _line) = val
|
1202
|
-
|
1203
|
-
result = s(:colon2, expr, id.to_sym).line expr.line
|
1204
|
-
}
|
1205
|
-
| tCOLON3 tCONSTANT
|
1206
|
-
{
|
1207
|
-
result = wrap :colon3, val[1]
|
1208
|
-
}
|
1209
|
-
| tLBRACK { result = lexer.lineno } aref_args rbracket
|
1210
|
-
{
|
1211
|
-
_, line, args, (_, line_max) = val
|
1212
|
-
|
1213
|
-
result = args || s(:array)
|
1214
|
-
result.sexp_type = :array # aref_args is :args
|
1215
|
-
result.line line
|
1216
|
-
result.line_max = line_max
|
1217
|
-
}
|
1218
|
-
| tLBRACE
|
1219
|
-
{
|
1220
|
-
result = self.lexer.lineno
|
1221
|
-
}
|
1222
|
-
assoc_list tRCURLY
|
1223
|
-
{
|
1224
|
-
result = new_hash val
|
1225
|
-
}
|
1226
|
-
| k_return
|
1227
|
-
{
|
1228
|
-
(_, line), = val
|
1229
|
-
result = s(:return).line line
|
1230
|
-
}
|
1231
|
-
| kYIELD tLPAREN2 call_args rparen
|
1232
|
-
{
|
1233
|
-
(_, line), _, args, _ = val
|
1234
|
-
|
1235
|
-
result = new_yield(args).line line
|
1236
|
-
}
|
1237
|
-
| kYIELD tLPAREN2 rparen
|
1238
|
-
{
|
1239
|
-
(_, line), _, _ = val
|
1240
|
-
|
1241
|
-
result = new_yield.line line
|
1242
|
-
}
|
1243
|
-
| kYIELD
|
1244
|
-
{
|
1245
|
-
(_, line), = val
|
1246
|
-
|
1247
|
-
result = new_yield.line line
|
1248
|
-
}
|
1249
|
-
| kDEFINED opt_nl tLPAREN2 expr rparen
|
1250
|
-
{
|
1251
|
-
(_, line), _, _, arg, _ = val
|
1252
|
-
|
1253
|
-
result = s(:defined, arg).line line
|
1254
|
-
}
|
1255
|
-
| kNOT tLPAREN2 expr rparen
|
1256
|
-
{
|
1257
|
-
_, _, lhs, _ = val
|
1258
|
-
result = new_call lhs, :"!"
|
1259
|
-
}
|
1260
|
-
| kNOT tLPAREN2 rparen
|
1261
|
-
{
|
1262
|
-
debug 20
|
1263
|
-
}
|
1264
|
-
| fcall brace_block
|
1265
|
-
{
|
1266
|
-
call, iter = val
|
1267
|
-
|
1268
|
-
iter.insert 1, call
|
1269
|
-
result = iter
|
1270
|
-
# FIX: probably not: call.line = iter.line
|
1271
|
-
}
|
1272
|
-
| method_call
|
1273
|
-
| method_call brace_block
|
1274
|
-
{
|
1275
|
-
call, iter = val[0], val[1]
|
1276
|
-
block_dup_check call, iter
|
1277
|
-
iter.insert 1, call # FIX
|
1278
|
-
result = iter
|
1279
|
-
}
|
1280
|
-
| lambda
|
1281
|
-
{
|
1282
|
-
expr, = val
|
1283
|
-
result = expr
|
1284
|
-
}
|
1285
|
-
| k_if expr_value then compstmt if_tail k_end
|
1286
|
-
{
|
1287
|
-
_, c, _, t, f, _ = val
|
1288
|
-
result = new_if c, t, f
|
1289
|
-
}
|
1290
|
-
| k_unless expr_value then compstmt opt_else k_end
|
1291
|
-
{
|
1292
|
-
_, c, _, t, f, _ = val
|
1293
|
-
result = new_if c, f, t
|
1294
|
-
}
|
1295
|
-
| k_while expr_value_do compstmt k_end
|
1296
|
-
{
|
1297
|
-
_, cond, body, _ = val
|
1298
|
-
result = new_while body, cond, true
|
1299
|
-
}
|
1300
|
-
| k_until expr_value_do compstmt k_end
|
1301
|
-
{
|
1302
|
-
_, cond, body, _ = val
|
1303
|
-
result = new_until body, cond, true
|
1304
|
-
}
|
1305
|
-
| k_case expr_value opt_terms case_body k_end
|
1306
|
-
{
|
1307
|
-
(_, line), expr, _, body, _ = val
|
1308
|
-
result = new_case expr, body, line
|
1309
|
-
}
|
1310
|
-
| k_case opt_terms case_body k_end
|
1311
|
-
{
|
1312
|
-
(_, line), _, body, _ = val
|
1313
|
-
result = new_case nil, body, line
|
1314
|
-
}
|
1315
|
-
| k_for for_var kIN expr_value_do compstmt k_end
|
1316
|
-
{
|
1317
|
-
_, var, _, iter, body, _ = val
|
1318
|
-
result = new_for iter, var, body
|
1319
|
-
}
|
1320
|
-
| k_class
|
1321
|
-
cpath superclass
|
1322
|
-
{
|
1323
|
-
if (self.in_def || self.in_single > 0) then
|
1324
|
-
yyerror "class definition in method body"
|
1325
|
-
end
|
1326
|
-
self.env.extend
|
1327
|
-
}
|
1328
|
-
bodystmt k_end
|
1329
|
-
{
|
1330
|
-
result = new_class val
|
1331
|
-
self.env.unextend
|
1332
|
-
self.lexer.ignore_body_comments
|
1333
|
-
}
|
1334
|
-
| k_class tLSHFT
|
1335
|
-
expr
|
1336
|
-
{
|
1337
|
-
result = self.in_def
|
1338
|
-
self.in_def = false
|
1339
|
-
}
|
1340
|
-
term
|
1341
|
-
{
|
1342
|
-
result = self.in_single
|
1343
|
-
self.in_single = 0
|
1344
|
-
self.env.extend
|
1345
|
-
}
|
1346
|
-
bodystmt k_end
|
1347
|
-
{
|
1348
|
-
result = new_sclass val
|
1349
|
-
self.env.unextend
|
1350
|
-
self.lexer.ignore_body_comments
|
1351
|
-
}
|
1352
|
-
| k_module
|
1353
|
-
cpath
|
1354
|
-
{
|
1355
|
-
yyerror "module definition in method body" if
|
1356
|
-
self.in_def or self.in_single > 0
|
1357
|
-
|
1358
|
-
self.env.extend
|
1359
|
-
}
|
1360
|
-
bodystmt k_end
|
1361
|
-
{
|
1362
|
-
result = new_module val
|
1363
|
-
self.env.unextend
|
1364
|
-
self.lexer.ignore_body_comments
|
1365
|
-
}
|
1366
|
-
| k_def fname
|
1367
|
-
{
|
1368
|
-
result = self.in_def
|
1369
|
-
|
1370
|
-
self.in_def = true # group = local_push
|
1371
|
-
self.env.extend
|
1372
|
-
lexer.cmdarg.push false
|
1373
|
-
lexer.cond.push false
|
1374
|
-
}
|
1375
|
-
f_arglist bodystmt k_end
|
1376
|
-
{
|
1377
|
-
result, in_def = new_defn val
|
1378
|
-
|
1379
|
-
lexer.cond.pop # group = local_pop
|
1380
|
-
lexer.cmdarg.pop
|
1381
|
-
self.env.unextend
|
1382
|
-
self.in_def = in_def
|
1383
|
-
|
1384
|
-
self.lexer.ignore_body_comments
|
1385
|
-
}
|
1386
|
-
| k_def singleton dot_or_colon
|
1387
|
-
{
|
1388
|
-
lexer.lex_state = EXPR_FNAME
|
1389
|
-
}
|
1390
|
-
fname
|
1391
|
-
{
|
1392
|
-
result = self.in_def
|
1393
|
-
|
1394
|
-
self.in_single += 1 # TODO: remove?
|
1395
|
-
|
1396
|
-
self.in_def = true # local_push
|
1397
|
-
self.env.extend
|
1398
|
-
lexer.cmdarg.push false
|
1399
|
-
lexer.cond.push false
|
1400
|
-
|
1401
|
-
lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
|
1402
|
-
}
|
1403
|
-
f_arglist bodystmt k_end
|
1404
|
-
{
|
1405
|
-
|
1406
|
-
# [kdef, recv, _, _, (name, line), in_def, args, body, kend]
|
1407
|
-
# =>
|
1408
|
-
# [kdef, recv, (name, line), in_def, args, body, kend]
|
1409
|
-
|
1410
|
-
val.delete_at 3
|
1411
|
-
val.delete_at 2
|
1412
|
-
|
1413
|
-
result, in_def = new_defs val
|
1414
|
-
|
1415
|
-
lexer.cond.pop # group = local_pop
|
1416
|
-
lexer.cmdarg.pop
|
1417
|
-
self.env.unextend
|
1418
|
-
self.in_def = in_def
|
1419
|
-
|
1420
|
-
self.in_single -= 1
|
1421
|
-
|
1422
|
-
# TODO: restore cur_arg ? what's cur_arg?
|
1423
|
-
|
1424
|
-
self.lexer.ignore_body_comments
|
1425
|
-
}
|
1426
|
-
| kBREAK
|
1427
|
-
{
|
1428
|
-
(_, line), = val
|
1429
|
-
result = s(:break).line line
|
1430
|
-
}
|
1431
|
-
| kNEXT
|
1432
|
-
{
|
1433
|
-
(_, line), = val
|
1434
|
-
result = s(:next).line line
|
1435
|
-
}
|
1436
|
-
| kREDO
|
1437
|
-
{
|
1438
|
-
(_, line), = val
|
1439
|
-
result = s(:redo).line line
|
1440
|
-
}
|
1441
|
-
| kRETRY
|
1442
|
-
{
|
1443
|
-
(_, line), = val
|
1444
|
-
result = s(:retry).line line
|
1445
|
-
}
|
1446
|
-
|
1447
|
-
primary_value: primary
|
1448
|
-
{
|
1449
|
-
result = value_expr(val[0])
|
1450
|
-
}
|
1451
|
-
|
1452
|
-
# These are really stupid
|
1453
|
-
k_begin: kBEGIN
|
1454
|
-
k_if: kIF
|
1455
|
-
k_unless: kUNLESS
|
1456
|
-
k_while: kWHILE
|
1457
|
-
k_until: kUNTIL
|
1458
|
-
k_case: kCASE
|
1459
|
-
k_for: kFOR
|
1460
|
-
k_class: kCLASS
|
1461
|
-
{
|
1462
|
-
self.comments.push self.lexer.comments
|
1463
|
-
}
|
1464
|
-
k_module: kMODULE
|
1465
|
-
{
|
1466
|
-
self.comments.push self.lexer.comments
|
1467
|
-
}
|
1468
|
-
k_def: kDEF
|
1469
|
-
{
|
1470
|
-
self.comments.push self.lexer.comments
|
1471
|
-
}
|
1472
|
-
k_do: kDO
|
1473
|
-
k_do_block: kDO_BLOCK
|
1474
|
-
k_rescue: kRESCUE
|
1475
|
-
k_ensure: kENSURE
|
1476
|
-
k_when: kWHEN
|
1477
|
-
k_else: kELSE
|
1478
|
-
k_elsif: kELSIF
|
1479
|
-
k_end: kEND
|
1480
|
-
k_return: kRETURN
|
1481
|
-
|
1482
|
-
then: term
|
1483
|
-
| kTHEN
|
1484
|
-
| term kTHEN
|
1485
|
-
|
1486
|
-
do: term
|
1487
|
-
| kDO_COND
|
1488
|
-
|
1489
|
-
if_tail: opt_else
|
1490
|
-
| k_elsif expr_value then compstmt if_tail
|
1491
|
-
{
|
1492
|
-
(_, line), c, _, t, rest = val
|
1493
|
-
|
1494
|
-
result = s(:if, c, t, rest).line line
|
1495
|
-
}
|
1496
|
-
|
1497
|
-
opt_else: none
|
1498
|
-
| kELSE compstmt
|
1499
|
-
{
|
1500
|
-
result = val[1]
|
1501
|
-
}
|
1502
|
-
|
1503
|
-
for_var: lhs
|
1504
|
-
| mlhs
|
1505
|
-
{
|
1506
|
-
val[0].delete_at 1 if val[0][1].nil? # HACK
|
1507
|
-
}
|
1508
|
-
|
1509
|
-
f_marg: f_norm_arg
|
1510
|
-
| tLPAREN f_margs rparen
|
1511
|
-
{
|
1512
|
-
result = val[1]
|
1513
|
-
}
|
1514
|
-
|
1515
|
-
f_marg_list: f_marg
|
1516
|
-
{
|
1517
|
-
sym, = val
|
1518
|
-
|
1519
|
-
result = s(:array, sym).line lexer.lineno
|
1520
|
-
}
|
1521
|
-
| f_marg_list tCOMMA f_marg
|
1522
|
-
{
|
1523
|
-
result = list_append val[0], val[2]
|
1524
|
-
}
|
1525
|
-
|
1526
|
-
f_margs: f_marg_list
|
1527
|
-
{
|
1528
|
-
args, = val
|
1529
|
-
|
1530
|
-
result = block_var args
|
1531
|
-
}
|
1532
|
-
| f_marg_list tCOMMA f_rest_marg
|
1533
|
-
{
|
1534
|
-
args, _, rest = val
|
1535
|
-
|
1536
|
-
result = block_var args, rest
|
1537
|
-
}
|
1538
|
-
| f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
|
1539
|
-
{
|
1540
|
-
lhs, _, splat, _, rhs = val
|
1541
|
-
|
1542
|
-
result = block_var lhs, splat, rhs
|
1543
|
-
}
|
1544
|
-
| f_rest_marg
|
1545
|
-
{
|
1546
|
-
rest, = val
|
1547
|
-
|
1548
|
-
result = block_var rest
|
1549
|
-
}
|
1550
|
-
| f_rest_marg tCOMMA f_marg_list
|
1551
|
-
{
|
1552
|
-
splat, _, rest = val
|
1553
|
-
|
1554
|
-
result = block_var splat, rest
|
1555
|
-
}
|
1556
|
-
|
1557
|
-
f_rest_marg: tSTAR f_norm_arg
|
1558
|
-
{
|
1559
|
-
_, (id, line) = val
|
1560
|
-
|
1561
|
-
result = args ["*#{id}".to_sym]
|
1562
|
-
result.line line
|
1563
|
-
}
|
1564
|
-
| tSTAR
|
1565
|
-
{
|
1566
|
-
result = args [:*]
|
1567
|
-
result.line lexer.lineno # FIX: tSTAR -> line
|
1568
|
-
}
|
1569
|
-
|
1570
|
-
block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
|
1571
|
-
{
|
1572
|
-
result = call_args val
|
1573
|
-
}
|
1574
|
-
| f_block_kwarg opt_f_block_arg
|
1575
|
-
{
|
1576
|
-
result = call_args val
|
1577
|
-
}
|
1578
|
-
| f_kwrest opt_f_block_arg
|
1579
|
-
{
|
1580
|
-
result = call_args val
|
1581
|
-
}
|
1582
|
-
| f_block_arg
|
1583
|
-
{
|
1584
|
-
(id, line), = val
|
1585
|
-
result = call_args [id]
|
1586
|
-
result.line line
|
1587
|
-
}
|
1588
|
-
|
1589
|
-
opt_block_args_tail: tCOMMA block_args_tail
|
1590
|
-
{
|
1591
|
-
result = args val
|
1592
|
-
}
|
1593
|
-
| none
|
1594
|
-
|
1595
|
-
block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
|
1596
|
-
{
|
1597
|
-
result = args val
|
1598
|
-
}
|
1599
|
-
| f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
|
1600
|
-
{
|
1601
|
-
result = args val
|
1602
|
-
}
|
1603
|
-
| f_arg tCOMMA f_block_optarg opt_block_args_tail
|
1604
|
-
{
|
1605
|
-
result = args val
|
1606
|
-
}
|
1607
|
-
| f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
|
1608
|
-
{
|
1609
|
-
result = args val
|
1610
|
-
}
|
1611
|
-
| f_arg tCOMMA f_rest_arg opt_block_args_tail
|
1612
|
-
{
|
1613
|
-
result = args val
|
1614
|
-
}
|
1615
|
-
| f_arg tCOMMA
|
1616
|
-
{
|
1617
|
-
result = args(val) << nil
|
1618
|
-
}
|
1619
|
-
| f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
|
1620
|
-
{
|
1621
|
-
result = args val
|
1622
|
-
}
|
1623
|
-
| f_arg opt_block_args_tail
|
1624
|
-
{
|
1625
|
-
result = args val
|
1626
|
-
}
|
1627
|
-
| f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
|
1628
|
-
{
|
1629
|
-
result = args val
|
1630
|
-
}
|
1631
|
-
| f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
|
1632
|
-
{
|
1633
|
-
result = args val
|
1634
|
-
}
|
1635
|
-
| f_block_optarg opt_block_args_tail
|
1636
|
-
{
|
1637
|
-
result = args val
|
1638
|
-
}
|
1639
|
-
| f_block_optarg tCOMMA f_arg opt_block_args_tail
|
1640
|
-
{
|
1641
|
-
result = args val
|
1642
|
-
}
|
1643
|
-
| f_rest_arg opt_block_args_tail
|
1644
|
-
{
|
1645
|
-
result = args val
|
1646
|
-
}
|
1647
|
-
| f_rest_arg tCOMMA f_arg opt_block_args_tail
|
1648
|
-
{
|
1649
|
-
result = args val
|
1650
|
-
}
|
1651
|
-
| block_args_tail
|
1652
|
-
{
|
1653
|
-
result = args val
|
1654
|
-
}
|
1655
|
-
|
1656
|
-
opt_block_param: none { result = 0 }
|
1657
|
-
| block_param_def
|
1658
|
-
{
|
1659
|
-
self.lexer.command_start = true
|
1660
|
-
}
|
1661
|
-
|
1662
|
-
block_param_def: tPIPE opt_bv_decl tPIPE
|
1663
|
-
{
|
1664
|
-
# TODO: current_arg = 0
|
1665
|
-
result = args val
|
1666
|
-
}
|
1667
|
-
| tOROP
|
1668
|
-
{
|
1669
|
-
result = s(:args).line lexer.lineno
|
1670
|
-
}
|
1671
|
-
| tPIPE block_param opt_bv_decl tPIPE
|
1672
|
-
{
|
1673
|
-
# TODO: current_arg = 0
|
1674
|
-
result = args val
|
1675
|
-
}
|
1676
|
-
|
1677
|
-
opt_bv_decl: opt_nl
|
1678
|
-
| opt_nl tSEMI bv_decls opt_nl
|
1679
|
-
{
|
1680
|
-
result = args val
|
1681
|
-
}
|
1682
|
-
|
1683
|
-
bv_decls: bvar
|
1684
|
-
{
|
1685
|
-
result = args val
|
1686
|
-
}
|
1687
|
-
| bv_decls tCOMMA bvar
|
1688
|
-
{
|
1689
|
-
result = args val
|
1690
|
-
}
|
1691
|
-
|
1692
|
-
bvar: tIDENTIFIER
|
1693
|
-
{
|
1694
|
-
result = wrap :shadow, val[0]
|
1695
|
-
}
|
1696
|
-
| f_bad_arg
|
1697
|
-
|
1698
|
-
lambda: tLAMBDA
|
1699
|
-
{
|
1700
|
-
self.env.extend :dynamic
|
1701
|
-
result = [lexer.lineno, lexer.lpar_beg]
|
1702
|
-
lexer.paren_nest += 1
|
1703
|
-
lexer.lpar_beg = lexer.paren_nest
|
1704
|
-
}
|
1705
|
-
f_larglist
|
1706
|
-
{
|
1707
|
-
lexer.cmdarg.push false
|
1708
|
-
}
|
1709
|
-
lambda_body
|
1710
|
-
{
|
1711
|
-
_, (line, lpar), args, _cmdarg, body = val
|
1712
|
-
lexer.lpar_beg = lpar
|
1713
|
-
|
1714
|
-
lexer.cmdarg.pop
|
1715
|
-
|
1716
|
-
call = s(:lambda).line line
|
1717
|
-
result = new_iter call, args, body
|
1718
|
-
result.line line
|
1719
|
-
self.env.unextend # TODO: dynapush & dynapop
|
1720
|
-
}
|
1721
|
-
|
1722
|
-
f_larglist: tLPAREN2 f_args opt_bv_decl rparen
|
1723
|
-
{
|
1724
|
-
result = args val
|
1725
|
-
}
|
1726
|
-
| f_args
|
1727
|
-
{
|
1728
|
-
result = val[0]
|
1729
|
-
result = 0 if result == s(:args)
|
1730
|
-
}
|
1731
|
-
|
1732
|
-
lambda_body: tLAMBEG compstmt tRCURLY
|
1733
|
-
{
|
1734
|
-
result = val[1]
|
1735
|
-
}
|
1736
|
-
| kDO_LAMBDA bodystmt kEND
|
1737
|
-
{
|
1738
|
-
result = val[1]
|
1739
|
-
}
|
1740
|
-
|
1741
|
-
do_block: k_do_block do_body kEND
|
1742
|
-
{
|
1743
|
-
(_, line), iter, _ = val
|
1744
|
-
result = iter.line line
|
1745
|
-
}
|
1746
|
-
|
1747
|
-
block_call: command do_block
|
1748
|
-
{
|
1749
|
-
# TODO:
|
1750
|
-
## if (nd_type($1) == NODE_YIELD) {
|
1751
|
-
## compile_error(PARSER_ARG "block given to yield");
|
1752
|
-
|
1753
|
-
cmd, blk = val
|
1754
|
-
|
1755
|
-
syntax_error "Both block arg and actual block given." if
|
1756
|
-
cmd.block_pass?
|
1757
|
-
|
1758
|
-
if inverted? val then
|
1759
|
-
val = invert_block_call val
|
1760
|
-
cmd, blk = val
|
1761
|
-
end
|
1762
|
-
|
1763
|
-
result = blk
|
1764
|
-
result.insert 1, cmd
|
1765
|
-
}
|
1766
|
-
| block_call call_op2 operation2 opt_paren_args
|
1767
|
-
{
|
1768
|
-
lhs, _, (id, _line), args = val
|
1769
|
-
|
1770
|
-
result = new_call lhs, id.to_sym, args
|
1771
|
-
}
|
1772
|
-
| block_call call_op2 operation2 opt_paren_args brace_block
|
1773
|
-
{
|
1774
|
-
iter1, _, (name, _line), args, iter2 = val
|
1775
|
-
|
1776
|
-
call = new_call iter1, name.to_sym, args
|
1777
|
-
iter2.insert 1, call
|
1778
|
-
|
1779
|
-
result = iter2
|
1780
|
-
}
|
1781
|
-
| block_call call_op2 operation2 command_args do_block
|
1782
|
-
{
|
1783
|
-
iter1, _, (name, _line), args, iter2 = val
|
1784
|
-
|
1785
|
-
call = new_call iter1, name.to_sym, args
|
1786
|
-
iter2.insert 1, call
|
1787
|
-
|
1788
|
-
result = iter2
|
1789
|
-
}
|
1790
|
-
|
1791
|
-
method_call: fcall paren_args
|
1792
|
-
{
|
1793
|
-
call, args = val
|
1794
|
-
|
1795
|
-
result = call
|
1796
|
-
|
1797
|
-
if args then
|
1798
|
-
call.concat args.sexp_body
|
1799
|
-
result.line_max = args.line_max
|
1800
|
-
end
|
1801
|
-
}
|
1802
|
-
| primary_value call_op operation2 opt_paren_args
|
1803
|
-
{
|
1804
|
-
recv, call_op, (op, op_line), args = val
|
1805
|
-
|
1806
|
-
result = new_call recv, op.to_sym, args, call_op
|
1807
|
-
result.line_max = op_line unless args
|
1808
|
-
}
|
1809
|
-
| primary_value tCOLON2 operation2 paren_args
|
1810
|
-
{
|
1811
|
-
recv, _, (op, _line), args = val
|
1812
|
-
|
1813
|
-
result = new_call recv, op.to_sym, args
|
1814
|
-
}
|
1815
|
-
| primary_value tCOLON2 operation3
|
1816
|
-
{
|
1817
|
-
lhs, _, (id, _line) = val
|
1818
|
-
|
1819
|
-
result = new_call lhs, id.to_sym
|
1820
|
-
}
|
1821
|
-
| primary_value call_op paren_args
|
1822
|
-
{
|
1823
|
-
result = new_call val[0], :call, val[2], val[1]
|
1824
|
-
}
|
1825
|
-
| primary_value tCOLON2 paren_args
|
1826
|
-
{
|
1827
|
-
result = new_call val[0], :call, val[2]
|
1828
|
-
}
|
1829
|
-
| kSUPER paren_args
|
1830
|
-
{
|
1831
|
-
result = new_super val[1]
|
1832
|
-
}
|
1833
|
-
| kSUPER
|
1834
|
-
{
|
1835
|
-
result = s(:zsuper).line lexer.lineno
|
1836
|
-
}
|
1837
|
-
| primary_value tLBRACK2 opt_call_args rbracket
|
1838
|
-
{
|
1839
|
-
result = new_aref val
|
1840
|
-
}
|
1841
|
-
|
1842
|
-
brace_block: tLCURLY
|
1843
|
-
{
|
1844
|
-
self.env.extend :dynamic
|
1845
|
-
result = self.lexer.lineno
|
1846
|
-
}
|
1847
|
-
brace_body tRCURLY
|
1848
|
-
{
|
1849
|
-
_, line, body, _ = val
|
1850
|
-
|
1851
|
-
result = body
|
1852
|
-
result.line line
|
1853
|
-
|
1854
|
-
self.env.unextend
|
1855
|
-
}
|
1856
|
-
| k_do
|
1857
|
-
{
|
1858
|
-
self.env.extend :dynamic
|
1859
|
-
result = self.lexer.lineno
|
1860
|
-
}
|
1861
|
-
do_body kEND
|
1862
|
-
{
|
1863
|
-
_, line, body, _ = val
|
1864
|
-
|
1865
|
-
result = body
|
1866
|
-
result.line line
|
1867
|
-
|
1868
|
-
self.env.unextend
|
1869
|
-
}
|
1870
|
-
|
1871
|
-
brace_body: { self.env.extend :dynamic; result = self.lexer.lineno }
|
1872
|
-
{ result = lexer.cmdarg.store(false) }
|
1873
|
-
opt_block_param compstmt
|
1874
|
-
{
|
1875
|
-
line, cmdarg, param, cmpstmt = val
|
1876
|
-
|
1877
|
-
result = new_brace_body param, cmpstmt, line
|
1878
|
-
self.env.unextend
|
1879
|
-
lexer.cmdarg.restore cmdarg
|
1880
|
-
lexer.cmdarg.pop # because of: cmdarg_stack >> 1 ?
|
1881
|
-
}
|
1882
|
-
|
1883
|
-
do_body: { self.env.extend :dynamic; result = self.lexer.lineno }
|
1884
|
-
{ lexer.cmdarg.push false }
|
1885
|
-
opt_block_param
|
1886
|
-
bodystmt
|
1887
|
-
{
|
1888
|
-
line, _cmdarg, param, cmpstmt = val
|
1889
|
-
|
1890
|
-
result = new_do_body param, cmpstmt, line
|
1891
|
-
lexer.cmdarg.pop
|
1892
|
-
self.env.unextend
|
1893
|
-
}
|
1894
|
-
|
1895
|
-
case_args: arg_value
|
1896
|
-
{
|
1897
|
-
arg, = val
|
1898
|
-
|
1899
|
-
result = s(:array, arg).line arg.line
|
1900
|
-
}
|
1901
|
-
| tSTAR arg_value
|
1902
|
-
{
|
1903
|
-
_, arg = val
|
1904
|
-
|
1905
|
-
result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
|
1906
|
-
}
|
1907
|
-
| case_args tCOMMA arg_value
|
1908
|
-
{
|
1909
|
-
args, _, id = val
|
1910
|
-
|
1911
|
-
result = self.list_append args, id
|
1912
|
-
}
|
1913
|
-
| case_args tCOMMA tSTAR arg_value
|
1914
|
-
{
|
1915
|
-
args, _, _, id = val
|
1916
|
-
|
1917
|
-
result = self.list_append args, s(:splat, id).line(id.line)
|
1918
|
-
}
|
1919
|
-
|
1920
|
-
case_body: k_when
|
1921
|
-
{
|
1922
|
-
result = self.lexer.lineno
|
1923
|
-
}
|
1924
|
-
case_args then compstmt cases
|
1925
|
-
{
|
1926
|
-
result = new_when(val[2], val[4])
|
1927
|
-
result.line val[1]
|
1928
|
-
result << val[5] if val[5]
|
1929
|
-
}
|
1930
|
-
|
1931
|
-
cases: opt_else | case_body
|
1932
|
-
|
1933
|
-
opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
|
1934
|
-
{
|
1935
|
-
(_, line), klasses, var, _, body, rest = val
|
1936
|
-
|
1937
|
-
klasses ||= s(:array)
|
1938
|
-
klasses << new_assign(var, s(:gvar, :"$!").line(var.line)) if var
|
1939
|
-
klasses.line line
|
1940
|
-
|
1941
|
-
result = new_resbody(klasses, body)
|
1942
|
-
result << rest if rest # UGH, rewritten above
|
1943
|
-
}
|
1944
|
-
|
|
1945
|
-
{
|
1946
|
-
result = nil
|
1947
|
-
}
|
1948
|
-
|
1949
|
-
exc_list: arg_value
|
1950
|
-
{
|
1951
|
-
arg, = val
|
1952
|
-
result = s(:array, arg).line arg.line
|
1953
|
-
}
|
1954
|
-
| mrhs
|
1955
|
-
| none
|
1956
|
-
|
1957
|
-
exc_var: tASSOC lhs
|
1958
|
-
{
|
1959
|
-
result = val[1]
|
1960
|
-
}
|
1961
|
-
| none
|
1962
|
-
|
1963
|
-
opt_ensure: k_ensure compstmt
|
1964
|
-
{
|
1965
|
-
(_, line), body = val
|
1966
|
-
|
1967
|
-
result = body || s(:nil).line(line)
|
1968
|
-
}
|
1969
|
-
| none
|
1970
|
-
|
1971
|
-
literal: numeric
|
1972
|
-
{
|
1973
|
-
(lit, line), = val
|
1974
|
-
result = s(:lit, lit).line line
|
1975
|
-
}
|
1976
|
-
| symbol
|
1977
|
-
|
1978
|
-
strings: string
|
1979
|
-
{
|
1980
|
-
str, = val
|
1981
|
-
str = s(:dstr, str.value) if str.sexp_type == :evstr
|
1982
|
-
result = str
|
1983
|
-
}
|
1984
|
-
|
1985
|
-
string: tCHAR
|
1986
|
-
{
|
1987
|
-
debug 37
|
1988
|
-
}
|
1989
|
-
| string1
|
1990
|
-
| string string1
|
1991
|
-
{
|
1992
|
-
result = self.literal_concat val[0], val[1]
|
1993
|
-
}
|
1994
|
-
|
1995
|
-
string1: tSTRING_BEG string_contents tSTRING_END
|
1996
|
-
{
|
1997
|
-
(_, line), str, (_, func) = val
|
1998
|
-
|
1999
|
-
str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
|
2000
|
-
|
2001
|
-
result = str.line line
|
2002
|
-
}
|
2003
|
-
| tSTRING
|
2004
|
-
{
|
2005
|
-
result = new_string val
|
2006
|
-
}
|
2007
|
-
|
2008
|
-
xstring: tXSTRING_BEG xstring_contents tSTRING_END
|
2009
|
-
{
|
2010
|
-
result = new_xstring val
|
2011
|
-
# TODO: dedent?!?! SERIOUSLY?!?
|
2012
|
-
}
|
2013
|
-
|
2014
|
-
regexp: tREGEXP_BEG regexp_contents tREGEXP_END
|
2015
|
-
{
|
2016
|
-
result = new_regexp val
|
2017
|
-
}
|
2018
|
-
|
2019
|
-
words: tWORDS_BEG tSPACE tSTRING_END
|
2020
|
-
{
|
2021
|
-
(_, line), _, (_, line_max) = val
|
2022
|
-
|
2023
|
-
result = s(:array).line line
|
2024
|
-
result.line_max = line_max
|
2025
|
-
}
|
2026
|
-
| tWORDS_BEG word_list tSTRING_END
|
2027
|
-
{
|
2028
|
-
(_, line), list, (_, line_max) = val
|
2029
|
-
|
2030
|
-
result = list.line line
|
2031
|
-
result.line_max = line_max
|
2032
|
-
}
|
2033
|
-
|
2034
|
-
word_list: none
|
2035
|
-
{
|
2036
|
-
result = new_word_list
|
2037
|
-
}
|
2038
|
-
| word_list word tSPACE
|
2039
|
-
{
|
2040
|
-
result = val[0].dup << new_word_list_entry(val)
|
2041
|
-
}
|
2042
|
-
|
2043
|
-
word: string_content
|
2044
|
-
| word string_content
|
2045
|
-
{
|
2046
|
-
result = self.literal_concat val[0], val[1]
|
2047
|
-
}
|
2048
|
-
|
2049
|
-
symbols: tSYMBOLS_BEG tSPACE tSTRING_END
|
2050
|
-
{
|
2051
|
-
(_, line), _, (_, line_max) = val
|
2052
|
-
|
2053
|
-
result = s(:array).line line
|
2054
|
-
result.line_max = line_max
|
2055
|
-
}
|
2056
|
-
| tSYMBOLS_BEG symbol_list tSTRING_END
|
2057
|
-
{
|
2058
|
-
(_, line), list, (_, line_max), = val
|
2059
|
-
|
2060
|
-
result = list.line line
|
2061
|
-
result.line_max = line_max
|
2062
|
-
}
|
2063
|
-
|
2064
|
-
symbol_list: none
|
2065
|
-
{
|
2066
|
-
result = new_symbol_list
|
2067
|
-
}
|
2068
|
-
| symbol_list word tSPACE
|
2069
|
-
{
|
2070
|
-
list, * = val
|
2071
|
-
result = list.dup << new_symbol_list_entry(val)
|
2072
|
-
}
|
2073
|
-
|
2074
|
-
qwords: tQWORDS_BEG tSPACE tSTRING_END
|
2075
|
-
{
|
2076
|
-
(_, line), _, (_, line_max) = val
|
2077
|
-
|
2078
|
-
result = s(:array).line line
|
2079
|
-
result.line_max = line_max
|
2080
|
-
}
|
2081
|
-
| tQWORDS_BEG qword_list tSTRING_END
|
2082
|
-
{
|
2083
|
-
(_, line), list, (_, line_max) = val
|
2084
|
-
|
2085
|
-
result = list.line line
|
2086
|
-
result.line_max = line_max
|
2087
|
-
}
|
2088
|
-
|
2089
|
-
qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
|
2090
|
-
{
|
2091
|
-
(_, line), _, (_, line_max) = val
|
2092
|
-
|
2093
|
-
result = s(:array).line line
|
2094
|
-
result.line_max = line_max
|
2095
|
-
}
|
2096
|
-
| tQSYMBOLS_BEG qsym_list tSTRING_END
|
2097
|
-
{
|
2098
|
-
(_, line), list, (_, line_max) = val
|
2099
|
-
|
2100
|
-
result = list.line line
|
2101
|
-
result.line_max = line_max
|
2102
|
-
}
|
2103
|
-
|
2104
|
-
qword_list: none
|
2105
|
-
{
|
2106
|
-
result = new_qword_list
|
2107
|
-
}
|
2108
|
-
| qword_list tSTRING_CONTENT tSPACE
|
2109
|
-
{
|
2110
|
-
result = val[0].dup << new_qword_list_entry(val)
|
2111
|
-
}
|
2112
|
-
|
2113
|
-
qsym_list: none
|
2114
|
-
{
|
2115
|
-
result = new_qsym_list
|
2116
|
-
}
|
2117
|
-
| qsym_list tSTRING_CONTENT tSPACE
|
2118
|
-
{
|
2119
|
-
result = val[0].dup << new_qsym_list_entry(val)
|
2120
|
-
}
|
2121
|
-
|
2122
|
-
string_contents: none
|
2123
|
-
{
|
2124
|
-
line = prev_value_to_lineno _values.last
|
2125
|
-
result = s(:str, +"").line line
|
2126
|
-
}
|
2127
|
-
| string_contents string_content
|
2128
|
-
{
|
2129
|
-
v1, v2 = val
|
2130
|
-
result = literal_concat v1, v2
|
2131
|
-
}
|
2132
|
-
|
2133
|
-
xstring_contents: none
|
2134
|
-
{
|
2135
|
-
result = nil
|
2136
|
-
}
|
2137
|
-
| xstring_contents string_content
|
2138
|
-
{
|
2139
|
-
v1, v2 = val
|
2140
|
-
result = literal_concat v1, v2
|
2141
|
-
}
|
2142
|
-
|
2143
|
-
regexp_contents: none
|
2144
|
-
{
|
2145
|
-
result = nil
|
2146
|
-
}
|
2147
|
-
| regexp_contents string_content
|
2148
|
-
{
|
2149
|
-
v1, v2 = val
|
2150
|
-
result = literal_concat v1, v2
|
2151
|
-
}
|
2152
|
-
|
2153
|
-
string_content: tSTRING_CONTENT
|
2154
|
-
{
|
2155
|
-
result = new_string val
|
2156
|
-
}
|
2157
|
-
| tSTRING_DVAR
|
2158
|
-
{
|
2159
|
-
result = lexer.lex_strterm
|
2160
|
-
|
2161
|
-
lexer.lex_strterm = nil
|
2162
|
-
lexer.lex_state = EXPR_BEG
|
2163
|
-
}
|
2164
|
-
string_dvar
|
2165
|
-
{
|
2166
|
-
_, strterm, str = val
|
2167
|
-
lexer.lex_strterm = strterm
|
2168
|
-
result = s(:evstr, str).line str.line
|
2169
|
-
}
|
2170
|
-
| tSTRING_DBEG
|
2171
|
-
{
|
2172
|
-
result = [lexer.lex_strterm,
|
2173
|
-
lexer.brace_nest,
|
2174
|
-
lexer.string_nest, # TODO: remove
|
2175
|
-
lexer.lex_state,
|
2176
|
-
lexer.lineno,
|
2177
|
-
]
|
2178
|
-
|
2179
|
-
lexer.cmdarg.push false
|
2180
|
-
lexer.cond.push false
|
2181
|
-
|
2182
|
-
lexer.lex_strterm = nil
|
2183
|
-
lexer.brace_nest = 0
|
2184
|
-
lexer.string_nest = 0
|
2185
|
-
|
2186
|
-
lexer.lex_state = EXPR_BEG
|
2187
|
-
}
|
2188
|
-
compstmt
|
2189
|
-
tSTRING_DEND
|
2190
|
-
{
|
2191
|
-
_, memo, stmt, _ = val
|
2192
|
-
|
2193
|
-
lex_strterm, brace_nest, string_nest, oldlex_state, line = memo
|
2194
|
-
# TODO: heredoc_indent
|
2195
|
-
|
2196
|
-
lexer.lex_strterm = lex_strterm
|
2197
|
-
lexer.brace_nest = brace_nest
|
2198
|
-
lexer.string_nest = string_nest
|
2199
|
-
|
2200
|
-
lexer.cond.pop
|
2201
|
-
lexer.cmdarg.pop
|
2202
|
-
|
2203
|
-
lexer.lex_state = oldlex_state
|
2204
|
-
|
2205
|
-
case stmt
|
2206
|
-
when Sexp then
|
2207
|
-
case stmt.sexp_type
|
2208
|
-
when :str, :dstr, :evstr then
|
2209
|
-
result = stmt
|
2210
|
-
else
|
2211
|
-
result = s(:evstr, stmt).line line
|
2212
|
-
end
|
2213
|
-
when nil then
|
2214
|
-
result = s(:evstr).line line
|
2215
|
-
else
|
2216
|
-
debug 38
|
2217
|
-
raise "unknown string body: #{stmt.inspect}"
|
2218
|
-
end
|
2219
|
-
}
|
2220
|
-
|
2221
|
-
string_dvar: tGVAR
|
2222
|
-
{
|
2223
|
-
result = wrap :gvar, val[0]
|
2224
|
-
}
|
2225
|
-
| tIVAR
|
2226
|
-
{
|
2227
|
-
result = wrap :ivar, val[0]
|
2228
|
-
}
|
2229
|
-
| tCVAR
|
2230
|
-
{
|
2231
|
-
result = wrap :cvar, val[0]
|
2232
|
-
}
|
2233
|
-
| backref
|
2234
|
-
|
2235
|
-
symbol: ssym
|
2236
|
-
| dsym
|
2237
|
-
|
2238
|
-
ssym: tSYMBEG sym
|
2239
|
-
{
|
2240
|
-
lexer.lex_state = EXPR_END
|
2241
|
-
result = wrap :lit, val[1]
|
2242
|
-
}
|
2243
|
-
| tSYMBOL
|
2244
|
-
{
|
2245
|
-
lexer.lex_state = EXPR_END
|
2246
|
-
result = wrap :lit, val[0]
|
2247
|
-
}
|
2248
|
-
|
2249
|
-
sym: fname | tIVAR | tGVAR | tCVAR
|
2250
|
-
|
2251
|
-
dsym: tSYMBEG string_contents tSTRING_END
|
2252
|
-
{
|
2253
|
-
_, result, _ = val
|
2254
|
-
|
2255
|
-
lexer.lex_state = EXPR_END
|
2256
|
-
|
2257
|
-
result ||= s(:str, "").line lexer.lineno
|
2258
|
-
|
2259
|
-
case result.sexp_type
|
2260
|
-
when :dstr then
|
2261
|
-
result.sexp_type = :dsym
|
2262
|
-
when :str then
|
2263
|
-
result = s(:lit, result.last.to_sym).line result.line
|
2264
|
-
when :evstr then
|
2265
|
-
result = s(:dsym, "", result).line result.line
|
2266
|
-
else
|
2267
|
-
debug 39
|
2268
|
-
end
|
2269
|
-
}
|
2270
|
-
|
2271
|
-
numeric: simple_numeric
|
2272
|
-
| tUMINUS_NUM simple_numeric =tLOWEST
|
2273
|
-
{
|
2274
|
-
_, (num, line) = val
|
2275
|
-
result = [-num, line]
|
2276
|
-
}
|
2277
|
-
|
2278
|
-
simple_numeric: tINTEGER
|
2279
|
-
| tFLOAT
|
2280
|
-
| tRATIONAL
|
2281
|
-
| tIMAGINARY
|
2282
|
-
|
2283
|
-
user_variable: tIDENTIFIER
|
2284
|
-
| tIVAR
|
2285
|
-
| tGVAR
|
2286
|
-
| tCONSTANT
|
2287
|
-
| tCVAR
|
2288
|
-
|
2289
|
-
keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
2290
|
-
| kSELF { result = s(:self).line lexer.lineno }
|
2291
|
-
| kTRUE { result = s(:true).line lexer.lineno }
|
2292
|
-
| kFALSE { result = s(:false).line lexer.lineno }
|
2293
|
-
| k__FILE__ { result = s(:str, self.file).line lexer.lineno }
|
2294
|
-
| k__LINE__ { result = s(:lit, lexer.lineno).line lexer.lineno }
|
2295
|
-
| k__ENCODING__
|
2296
|
-
{
|
2297
|
-
l = lexer.lineno
|
2298
|
-
result =
|
2299
|
-
if defined? Encoding then
|
2300
|
-
s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
|
2301
|
-
else
|
2302
|
-
s(:str, "Unsupported!").line l
|
2303
|
-
end
|
2304
|
-
}
|
2305
|
-
|
2306
|
-
var_ref: user_variable
|
2307
|
-
{
|
2308
|
-
raise "NO: #{val.inspect}" if Sexp === val.first
|
2309
|
-
(var, line), = val
|
2310
|
-
result = Sexp === var ? var : self.gettable(var)
|
2311
|
-
result.line line
|
2312
|
-
}
|
2313
|
-
| keyword_variable
|
2314
|
-
{
|
2315
|
-
var = val[0]
|
2316
|
-
result = Sexp === var ? var : self.gettable(var)
|
2317
|
-
}
|
2318
|
-
|
2319
|
-
var_lhs: user_variable
|
2320
|
-
{
|
2321
|
-
result = self.assignable val[0]
|
2322
|
-
}
|
2323
|
-
| keyword_variable
|
2324
|
-
{
|
2325
|
-
result = self.assignable val[0]
|
2326
|
-
debug 40
|
2327
|
-
}
|
2328
|
-
|
2329
|
-
backref: tNTH_REF
|
2330
|
-
{
|
2331
|
-
(ref, line), = val
|
2332
|
-
result = s(:nth_ref, ref).line line
|
2333
|
-
}
|
2334
|
-
| tBACK_REF
|
2335
|
-
{
|
2336
|
-
(ref, line), = val
|
2337
|
-
result = s(:back_ref, ref).line line
|
2338
|
-
}
|
2339
|
-
|
2340
|
-
superclass: tLT
|
2341
|
-
{
|
2342
|
-
lexer.lex_state = EXPR_BEG
|
2343
|
-
lexer.command_start = true
|
2344
|
-
}
|
2345
|
-
expr_value term
|
2346
|
-
{
|
2347
|
-
result = val[2]
|
2348
|
-
}
|
2349
|
-
| none
|
2350
|
-
{
|
2351
|
-
result = nil
|
2352
|
-
}
|
2353
|
-
|
2354
|
-
f_arglist: tLPAREN2 f_args rparen
|
2355
|
-
{
|
2356
|
-
result = end_args val
|
2357
|
-
}
|
2358
|
-
| {
|
2359
|
-
result = self.in_kwarg
|
2360
|
-
self.in_kwarg = true
|
2361
|
-
self.lexer.lex_state |= EXPR_LABEL
|
2362
|
-
}
|
2363
|
-
f_args term
|
2364
|
-
{
|
2365
|
-
result = end_args val
|
2366
|
-
}
|
2367
|
-
|
2368
|
-
args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
|
2369
|
-
{
|
2370
|
-
result = args val
|
2371
|
-
}
|
2372
|
-
| f_kwarg opt_f_block_arg
|
2373
|
-
{
|
2374
|
-
result = args val
|
2375
|
-
}
|
2376
|
-
| f_kwrest opt_f_block_arg
|
2377
|
-
{
|
2378
|
-
result = args val
|
2379
|
-
}
|
2380
|
-
| f_block_arg
|
2381
|
-
|
2382
|
-
opt_args_tail: tCOMMA args_tail
|
2383
|
-
{
|
2384
|
-
result = val[1]
|
2385
|
-
}
|
2386
|
-
|
|
2387
|
-
{
|
2388
|
-
result = nil
|
2389
|
-
}
|
2390
|
-
|
2391
|
-
f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
|
2392
|
-
{
|
2393
|
-
result = args val
|
2394
|
-
}
|
2395
|
-
| f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
|
2396
|
-
{
|
2397
|
-
result = args val
|
2398
|
-
}
|
2399
|
-
| f_arg tCOMMA f_optarg opt_args_tail
|
2400
|
-
{
|
2401
|
-
result = args val
|
2402
|
-
}
|
2403
|
-
| f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
|
2404
|
-
{
|
2405
|
-
result = args val
|
2406
|
-
}
|
2407
|
-
| f_arg tCOMMA f_rest_arg opt_args_tail
|
2408
|
-
{
|
2409
|
-
result = args val
|
2410
|
-
}
|
2411
|
-
| f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
|
2412
|
-
{
|
2413
|
-
result = args val
|
2414
|
-
}
|
2415
|
-
| f_arg opt_args_tail
|
2416
|
-
{
|
2417
|
-
result = args val
|
2418
|
-
}
|
2419
|
-
| f_optarg tCOMMA f_rest_arg opt_args_tail
|
2420
|
-
{
|
2421
|
-
result = args val
|
2422
|
-
}
|
2423
|
-
| f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
|
2424
|
-
{
|
2425
|
-
result = args val
|
2426
|
-
}
|
2427
|
-
| f_optarg opt_args_tail
|
2428
|
-
{
|
2429
|
-
result = args val
|
2430
|
-
}
|
2431
|
-
| f_optarg tCOMMA f_arg opt_args_tail
|
2432
|
-
{
|
2433
|
-
result = args val
|
2434
|
-
}
|
2435
|
-
| f_rest_arg opt_args_tail
|
2436
|
-
{
|
2437
|
-
result = args val
|
2438
|
-
}
|
2439
|
-
| f_rest_arg tCOMMA f_arg opt_args_tail
|
2440
|
-
{
|
2441
|
-
result = args val
|
2442
|
-
}
|
2443
|
-
| args_tail
|
2444
|
-
{
|
2445
|
-
result = args val
|
2446
|
-
}
|
2447
|
-
|
|
2448
|
-
{
|
2449
|
-
result = args val
|
2450
|
-
# result.line lexer.lineno
|
2451
|
-
}
|
2452
|
-
|
2453
|
-
|
2454
|
-
f_bad_arg: tCONSTANT
|
2455
|
-
{
|
2456
|
-
yyerror "formal argument cannot be a constant"
|
2457
|
-
}
|
2458
|
-
| tIVAR
|
2459
|
-
{
|
2460
|
-
yyerror "formal argument cannot be an instance variable"
|
2461
|
-
}
|
2462
|
-
| tGVAR
|
2463
|
-
{
|
2464
|
-
yyerror "formal argument cannot be a global variable"
|
2465
|
-
}
|
2466
|
-
| tCVAR
|
2467
|
-
{
|
2468
|
-
yyerror "formal argument cannot be a class variable"
|
2469
|
-
}
|
2470
|
-
|
2471
|
-
f_norm_arg: f_bad_arg
|
2472
|
-
| tIDENTIFIER
|
2473
|
-
{
|
2474
|
-
(id, line), = val
|
2475
|
-
identifier = id.to_sym
|
2476
|
-
self.env[identifier] = :lvar
|
2477
|
-
|
2478
|
-
result = [identifier, line]
|
2479
|
-
}
|
2480
|
-
|
2481
|
-
f_arg_asgn: f_norm_arg
|
2482
|
-
|
2483
|
-
f_arg_item: f_arg_asgn
|
2484
|
-
| tLPAREN f_margs rparen
|
2485
|
-
{
|
2486
|
-
_, margs, _ = val
|
2487
|
-
|
2488
|
-
result = margs
|
2489
|
-
}
|
2490
|
-
|
2491
|
-
f_arg: f_arg_item
|
2492
|
-
{
|
2493
|
-
result = new_arg val
|
2494
|
-
}
|
2495
|
-
| f_arg tCOMMA f_arg_item
|
2496
|
-
{
|
2497
|
-
list, _, item = val
|
2498
|
-
|
2499
|
-
if list.sexp_type == :args then
|
2500
|
-
result = list
|
2501
|
-
else
|
2502
|
-
result = s(:args, list).line list.line
|
2503
|
-
end
|
2504
|
-
|
2505
|
-
if Sexp === item then
|
2506
|
-
line_max = item.line_max
|
2507
|
-
else
|
2508
|
-
item, line_max = item
|
2509
|
-
end
|
2510
|
-
|
2511
|
-
result << item
|
2512
|
-
result.line_max = line_max
|
2513
|
-
}
|
2514
|
-
|
2515
|
-
f_label: tLABEL
|
2516
|
-
|
2517
|
-
f_kw: f_label arg_value
|
2518
|
-
{
|
2519
|
-
# TODO: new_kw_arg
|
2520
|
-
(label, line), arg = val
|
2521
|
-
|
2522
|
-
identifier = label.to_sym
|
2523
|
-
self.env[identifier] = :lvar
|
2524
|
-
|
2525
|
-
kwarg = s(:kwarg, identifier, arg).line line
|
2526
|
-
result = s(:array, kwarg).line line
|
2527
|
-
}
|
2528
|
-
| f_label
|
2529
|
-
{
|
2530
|
-
(label, line), = val
|
2531
|
-
|
2532
|
-
id = label.to_sym
|
2533
|
-
self.env[id] = :lvar
|
2534
|
-
|
2535
|
-
result = s(:array, s(:kwarg, id).line(line)).line line
|
2536
|
-
}
|
2537
|
-
|
2538
|
-
f_block_kw: f_label primary_value
|
2539
|
-
{
|
2540
|
-
# TODO: new_kw_arg
|
2541
|
-
(label, line), expr = val
|
2542
|
-
id = label.to_sym
|
2543
|
-
self.env[id] = :lvar
|
2544
|
-
|
2545
|
-
result = s(:array, s(:kwarg, id, expr).line(line)).line line
|
2546
|
-
}
|
2547
|
-
| f_label
|
2548
|
-
{
|
2549
|
-
# TODO: new_kw_arg
|
2550
|
-
(label, line), = val
|
2551
|
-
id = label.to_sym
|
2552
|
-
self.env[id] = :lvar
|
2553
|
-
|
2554
|
-
result = s(:array, s(:kwarg, id).line(line)).line line
|
2555
|
-
}
|
2556
|
-
|
2557
|
-
f_block_kwarg: f_block_kw
|
2558
|
-
| f_block_kwarg tCOMMA f_block_kw
|
2559
|
-
{
|
2560
|
-
list, _, item = val
|
2561
|
-
result = list << item.last
|
2562
|
-
}
|
2563
|
-
|
2564
|
-
f_kwarg: f_kw
|
2565
|
-
| f_kwarg tCOMMA f_kw
|
2566
|
-
{
|
2567
|
-
result = args val
|
2568
|
-
}
|
2569
|
-
|
2570
|
-
kwrest_mark: tPOW
|
2571
|
-
| tDSTAR
|
2572
|
-
|
2573
|
-
|
2574
|
-
f_kwrest: kwrest_mark tIDENTIFIER
|
2575
|
-
{
|
2576
|
-
_, (id, line) = val
|
2577
|
-
|
2578
|
-
name = id.to_sym
|
2579
|
-
self.assignable [name, line]
|
2580
|
-
result = [:"**#{name}", line]
|
2581
|
-
}
|
2582
|
-
| kwrest_mark
|
2583
|
-
{
|
2584
|
-
id = :"**"
|
2585
|
-
self.env[id] = :lvar # TODO: needed?!?
|
2586
|
-
result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
|
2587
|
-
}
|
2588
|
-
|
2589
|
-
f_opt: f_arg_asgn tEQL arg_value
|
2590
|
-
{
|
2591
|
-
lhs, _, rhs = val
|
2592
|
-
result = self.assignable lhs, rhs
|
2593
|
-
# TODO: detect duplicate names
|
2594
|
-
}
|
2595
|
-
|
2596
|
-
f_block_opt: f_arg_asgn tEQL primary_value
|
2597
|
-
{
|
2598
|
-
lhs, _, rhs = val
|
2599
|
-
result = self.assignable lhs, rhs
|
2600
|
-
}
|
2601
|
-
|
2602
|
-
f_block_optarg: f_block_opt
|
2603
|
-
{
|
2604
|
-
optblk, = val
|
2605
|
-
result = s(:block, optblk).line optblk.line
|
2606
|
-
}
|
2607
|
-
| f_block_optarg tCOMMA f_block_opt
|
2608
|
-
{
|
2609
|
-
optarg, _, optblk = val
|
2610
|
-
result = optarg
|
2611
|
-
result << optblk
|
2612
|
-
}
|
2613
|
-
|
2614
|
-
f_optarg: f_opt
|
2615
|
-
{
|
2616
|
-
opt, = val
|
2617
|
-
result = s(:block, opt).line opt.line
|
2618
|
-
}
|
2619
|
-
| f_optarg tCOMMA f_opt
|
2620
|
-
{
|
2621
|
-
result = self.block_append val[0], val[2]
|
2622
|
-
}
|
2623
|
-
|
2624
|
-
restarg_mark: tSTAR2 | tSTAR
|
2625
|
-
|
2626
|
-
f_rest_arg: restarg_mark tIDENTIFIER
|
2627
|
-
{
|
2628
|
-
# TODO: differs from parse.y - needs tests
|
2629
|
-
_, (id, line) = val
|
2630
|
-
name = id.to_sym
|
2631
|
-
self.assignable [name, line]
|
2632
|
-
result = [:"*#{name}", line]
|
2633
|
-
}
|
2634
|
-
| restarg_mark
|
2635
|
-
{
|
2636
|
-
name = :"*"
|
2637
|
-
self.env[name] = :lvar
|
2638
|
-
result = [name, lexer.lineno] # FIX: tSTAR to include lineno
|
2639
|
-
}
|
2640
|
-
|
2641
|
-
blkarg_mark: tAMPER2 | tAMPER
|
2642
|
-
|
2643
|
-
f_block_arg: blkarg_mark tIDENTIFIER
|
2644
|
-
{
|
2645
|
-
_, (id, line) = val
|
2646
|
-
identifier = id.to_sym
|
2647
|
-
|
2648
|
-
self.env[identifier] = :lvar
|
2649
|
-
result = ["&#{identifier}".to_sym, line]
|
2650
|
-
}
|
2651
|
-
|
2652
|
-
opt_f_block_arg: tCOMMA f_block_arg
|
2653
|
-
{
|
2654
|
-
_, arg = val
|
2655
|
-
result = arg
|
2656
|
-
}
|
2657
|
-
|
|
2658
|
-
{
|
2659
|
-
result = nil
|
2660
|
-
}
|
2661
|
-
|
2662
|
-
singleton: var_ref
|
2663
|
-
| tLPAREN2
|
2664
|
-
{
|
2665
|
-
lexer.lex_state = EXPR_BEG
|
2666
|
-
}
|
2667
|
-
expr rparen
|
2668
|
-
{
|
2669
|
-
result = val[2]
|
2670
|
-
yyerror "Can't define single method for literals." if
|
2671
|
-
result.sexp_type == :lit
|
2672
|
-
}
|
2673
|
-
|
2674
|
-
assoc_list: none
|
2675
|
-
{
|
2676
|
-
result = s(:array).line lexer.lineno
|
2677
|
-
}
|
2678
|
-
| assocs trailer
|
2679
|
-
|
2680
|
-
assocs: assoc
|
2681
|
-
| assocs tCOMMA assoc
|
2682
|
-
{
|
2683
|
-
list = val[0].dup
|
2684
|
-
more = val[2].sexp_body
|
2685
|
-
list.push(*more) unless more.empty?
|
2686
|
-
result = list
|
2687
|
-
result.sexp_type = :hash
|
2688
|
-
}
|
2689
|
-
|
2690
|
-
assoc: arg_value tASSOC arg_value
|
2691
|
-
{
|
2692
|
-
v1, _, v2 = val
|
2693
|
-
result = s(:array, v1, v2).line v1.line
|
2694
|
-
}
|
2695
|
-
| tLABEL arg_value
|
2696
|
-
{
|
2697
|
-
label, arg = val
|
2698
|
-
|
2699
|
-
lit = wrap :lit, label
|
2700
|
-
result = s(:array, lit, arg).line lit.line
|
2701
|
-
}
|
2702
|
-
| tSTRING_BEG string_contents tLABEL_END arg_value
|
2703
|
-
{
|
2704
|
-
(_, line), sym, _, value = val
|
2705
|
-
|
2706
|
-
sym.sexp_type = :dsym
|
2707
|
-
|
2708
|
-
result = s(:array, sym, value).line line
|
2709
|
-
}
|
2710
|
-
| tDSTAR arg_value
|
2711
|
-
{
|
2712
|
-
_, arg = val
|
2713
|
-
line = arg.line
|
2714
|
-
result = s(:array, s(:kwsplat, arg).line(line)).line line
|
2715
|
-
}
|
2716
|
-
|
2717
|
-
operation: tIDENTIFIER | tCONSTANT | tFID
|
2718
|
-
operation2: tIDENTIFIER | tCONSTANT | tFID | op
|
2719
|
-
operation3: tIDENTIFIER | tFID | op
|
2720
|
-
dot_or_colon: tDOT | tCOLON2
|
2721
|
-
call_op: tDOT
|
2722
|
-
| tLONELY # TODO: rename tANDDOT?
|
2723
|
-
|
2724
|
-
call_op2: call_op
|
2725
|
-
| tCOLON2
|
2726
|
-
|
2727
|
-
opt_terms: | terms
|
2728
|
-
opt_nl: | tNL
|
2729
|
-
rparen: opt_nl tRPAREN
|
2730
|
-
{
|
2731
|
-
_, close = val
|
2732
|
-
result = [close, lexer.lineno]
|
2733
|
-
}
|
2734
|
-
rbracket: opt_nl tRBRACK
|
2735
|
-
{
|
2736
|
-
_, close = val
|
2737
|
-
result = [close, lexer.lineno]
|
2738
|
-
}
|
2739
|
-
trailer: | tNL | tCOMMA
|
2740
|
-
|
2741
|
-
term: tSEMI { yyerrok }
|
2742
|
-
| tNL
|
2743
|
-
|
2744
|
-
terms: term
|
2745
|
-
| terms tSEMI { yyerrok }
|
2746
|
-
|
2747
|
-
none: { result = nil; }
|
2748
|
-
end
|
2749
|
-
|
2750
|
-
---- inner
|
2751
|
-
|
2752
|
-
require "ruby_lexer"
|
2753
|
-
require "ruby_parser_extras"
|
2754
|
-
include RubyLexer::State::Values
|
2755
|
-
|
2756
|
-
# :stopdoc:
|
2757
|
-
|
2758
|
-
# Local Variables: **
|
2759
|
-
# racc-token-length-max:14 **
|
2760
|
-
# End: **
|