ruby_parser 3.12.0 → 3.18.1
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/.autotest +18 -29
- data/History.rdoc +283 -0
- data/Manifest.txt +12 -4
- data/README.rdoc +4 -3
- data/Rakefile +189 -51
- data/bin/ruby_parse +3 -1
- data/bin/ruby_parse_extract_error +19 -36
- data/compare/normalize.rb +76 -4
- data/debugging.md +190 -0
- data/gauntlet.md +106 -0
- data/lib/rp_extensions.rb +14 -42
- data/lib/rp_stringscanner.rb +20 -51
- data/lib/ruby20_parser.rb +4659 -4218
- data/lib/ruby20_parser.y +953 -602
- data/lib/ruby21_parser.rb +4723 -4308
- data/lib/ruby21_parser.y +956 -605
- data/lib/ruby22_parser.rb +4762 -4337
- data/lib/ruby22_parser.y +960 -612
- data/lib/ruby23_parser.rb +4761 -4342
- data/lib/ruby23_parser.y +961 -613
- data/lib/ruby24_parser.rb +4791 -4341
- data/lib/ruby24_parser.y +968 -612
- data/lib/ruby25_parser.rb +4791 -4341
- data/lib/ruby25_parser.y +968 -612
- data/lib/ruby26_parser.rb +7287 -0
- data/lib/ruby26_parser.y +2749 -0
- data/lib/ruby27_parser.rb +8517 -0
- data/lib/ruby27_parser.y +3346 -0
- data/lib/ruby30_parser.rb +8751 -0
- data/lib/ruby30_parser.y +3472 -0
- data/lib/ruby3_parser.yy +3476 -0
- data/lib/ruby_lexer.rb +611 -826
- data/lib/ruby_lexer.rex +48 -40
- data/lib/ruby_lexer.rex.rb +122 -46
- data/lib/ruby_lexer_strings.rb +638 -0
- data/lib/ruby_parser.rb +38 -34
- data/lib/ruby_parser.yy +1710 -704
- data/lib/ruby_parser_extras.rb +987 -553
- data/test/test_ruby_lexer.rb +1718 -1539
- data/test/test_ruby_parser.rb +3957 -2164
- data/test/test_ruby_parser_extras.rb +39 -4
- data/tools/munge.rb +250 -0
- data/tools/ripper.rb +44 -0
- data.tar.gz.sig +0 -0
- metadata +68 -47
- metadata.gz.sig +0 -0
- data/lib/ruby18_parser.rb +0 -5793
- data/lib/ruby18_parser.y +0 -1908
- data/lib/ruby19_parser.rb +0 -6185
- data/lib/ruby19_parser.y +0 -2116
data/lib/ruby19_parser.y
DELETED
@@ -1,2116 +0,0 @@
|
|
1
|
-
# -*- racc -*-
|
2
|
-
|
3
|
-
class Ruby19Parser
|
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 tLAST_TOKEN
|
21
|
-
tLAMBDA tLAMBEG
|
22
|
-
|
23
|
-
prechigh
|
24
|
-
right tBANG tTILDE tUPLUS
|
25
|
-
right tPOW
|
26
|
-
right tUMINUS_NUM tUMINUS
|
27
|
-
left tSTAR2 tDIVIDE tPERCENT
|
28
|
-
left tPLUS tMINUS
|
29
|
-
left tLSHFT tRSHFT
|
30
|
-
left tAMPER2
|
31
|
-
left tPIPE tCARET
|
32
|
-
left tGT tGEQ tLT tLEQ
|
33
|
-
nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
|
34
|
-
left tANDOP
|
35
|
-
left tOROP
|
36
|
-
nonassoc tDOT2 tDOT3
|
37
|
-
right tEH tCOLON
|
38
|
-
left kRESCUE_MOD
|
39
|
-
right tEQL tOP_ASGN
|
40
|
-
nonassoc kDEFINED
|
41
|
-
right kNOT
|
42
|
-
left kOR kAND
|
43
|
-
nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
|
44
|
-
nonassoc tLBRACE_ARG
|
45
|
-
nonassoc tLOWEST
|
46
|
-
preclow
|
47
|
-
|
48
|
-
rule
|
49
|
-
|
50
|
-
program: {
|
51
|
-
self.lexer.lex_state = :expr_beg
|
52
|
-
}
|
53
|
-
top_compstmt
|
54
|
-
{
|
55
|
-
result = new_compstmt val
|
56
|
-
}
|
57
|
-
|
58
|
-
top_compstmt: top_stmts opt_terms
|
59
|
-
{
|
60
|
-
result = val[0]
|
61
|
-
}
|
62
|
-
|
63
|
-
top_stmts: none
|
64
|
-
| top_stmt
|
65
|
-
| top_stmts terms top_stmt
|
66
|
-
{
|
67
|
-
result = self.block_append val[0], val[2]
|
68
|
-
}
|
69
|
-
| error top_stmt
|
70
|
-
|
71
|
-
top_stmt: stmt
|
72
|
-
| klBEGIN
|
73
|
-
{
|
74
|
-
if (self.in_def || self.in_single > 0) then
|
75
|
-
yyerror "BEGIN in method"
|
76
|
-
end
|
77
|
-
self.env.extend
|
78
|
-
}
|
79
|
-
tLCURLY top_compstmt tRCURLY
|
80
|
-
{
|
81
|
-
result = new_iter s(:preexe), nil, val[3]
|
82
|
-
}
|
83
|
-
|
84
|
-
bodystmt: compstmt opt_rescue opt_else opt_ensure
|
85
|
-
{
|
86
|
-
result = new_body val
|
87
|
-
}
|
88
|
-
|
89
|
-
compstmt: stmts opt_terms
|
90
|
-
{
|
91
|
-
result = new_compstmt val
|
92
|
-
}
|
93
|
-
|
94
|
-
stmts: none
|
95
|
-
| stmt
|
96
|
-
| stmts terms stmt
|
97
|
-
{
|
98
|
-
result = self.block_append val[0], val[2]
|
99
|
-
}
|
100
|
-
| error stmt
|
101
|
-
{
|
102
|
-
result = val[1]
|
103
|
-
}
|
104
|
-
|
105
|
-
stmt: kALIAS fitem
|
106
|
-
{
|
107
|
-
lexer.lex_state = :expr_fname
|
108
|
-
result = self.lexer.lineno
|
109
|
-
}
|
110
|
-
fitem
|
111
|
-
{
|
112
|
-
result = s(:alias, val[1], val[3]).line(val[2])
|
113
|
-
}
|
114
|
-
| kALIAS tGVAR tGVAR
|
115
|
-
{
|
116
|
-
result = s(:valias, val[1].to_sym, val[2].to_sym)
|
117
|
-
}
|
118
|
-
| kALIAS tGVAR tBACK_REF
|
119
|
-
{
|
120
|
-
result = s(:valias, val[1].to_sym, :"$#{val[2]}")
|
121
|
-
}
|
122
|
-
| kALIAS tGVAR tNTH_REF
|
123
|
-
{
|
124
|
-
yyerror "can't make alias for the number variables"
|
125
|
-
}
|
126
|
-
| kUNDEF undef_list
|
127
|
-
{
|
128
|
-
result = val[1]
|
129
|
-
}
|
130
|
-
| stmt kIF_MOD expr_value
|
131
|
-
{
|
132
|
-
result = new_if val[2], val[0], nil
|
133
|
-
}
|
134
|
-
| stmt kUNLESS_MOD expr_value
|
135
|
-
{
|
136
|
-
result = new_if val[2], nil, val[0]
|
137
|
-
}
|
138
|
-
| stmt kWHILE_MOD expr_value
|
139
|
-
{
|
140
|
-
result = new_while val[0], val[2], true
|
141
|
-
}
|
142
|
-
| stmt kUNTIL_MOD expr_value
|
143
|
-
{
|
144
|
-
result = new_until val[0], val[2], true
|
145
|
-
}
|
146
|
-
| stmt kRESCUE_MOD stmt
|
147
|
-
{
|
148
|
-
result = s(:rescue, val[0], new_resbody(s(:array), val[2]))
|
149
|
-
}
|
150
|
-
| klEND tLCURLY compstmt tRCURLY
|
151
|
-
{
|
152
|
-
if (self.in_def || self.in_single > 0) then
|
153
|
-
yyerror "END in method; use at_exit"
|
154
|
-
end
|
155
|
-
result = new_iter s(:postexe), 0, val[2]
|
156
|
-
}
|
157
|
-
| command_asgn
|
158
|
-
| mlhs tEQL command_call
|
159
|
-
{
|
160
|
-
result = new_masgn val[0], val[2], :wrap
|
161
|
-
}
|
162
|
-
| var_lhs tOP_ASGN command_call
|
163
|
-
{
|
164
|
-
result = new_op_asgn val
|
165
|
-
}
|
166
|
-
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_call
|
167
|
-
{
|
168
|
-
result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
|
169
|
-
}
|
170
|
-
| primary_value tDOT tIDENTIFIER tOP_ASGN command_call
|
171
|
-
{
|
172
|
-
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
173
|
-
}
|
174
|
-
| primary_value tDOT tCONSTANT tOP_ASGN command_call
|
175
|
-
{
|
176
|
-
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
177
|
-
}
|
178
|
-
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
|
179
|
-
{
|
180
|
-
result = s(:op_asgn, val[0], val[4], val[2], val[3])
|
181
|
-
}
|
182
|
-
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
|
183
|
-
{
|
184
|
-
result = s(:op_asgn, val[0], val[4], val[2], val[3])
|
185
|
-
}
|
186
|
-
| backref tOP_ASGN command_call
|
187
|
-
{
|
188
|
-
self.backref_assign_error val[0]
|
189
|
-
}
|
190
|
-
| lhs tEQL mrhs
|
191
|
-
{
|
192
|
-
result = new_assign val[0], s(:svalue, val[2])
|
193
|
-
}
|
194
|
-
| mlhs tEQL arg_value
|
195
|
-
{
|
196
|
-
result = new_masgn val[0], val[2], :wrap
|
197
|
-
}
|
198
|
-
| mlhs tEQL mrhs
|
199
|
-
{
|
200
|
-
result = new_masgn val[0], val[2]
|
201
|
-
}
|
202
|
-
| expr
|
203
|
-
|
204
|
-
command_asgn: lhs tEQL command_call
|
205
|
-
{
|
206
|
-
result = new_assign val[0], val[2]
|
207
|
-
}
|
208
|
-
| lhs tEQL command_asgn
|
209
|
-
{
|
210
|
-
result = new_assign val[0], val[2]
|
211
|
-
}
|
212
|
-
|
213
|
-
expr: command_call
|
214
|
-
| expr kAND expr
|
215
|
-
{
|
216
|
-
result = logical_op :and, val[0], val[2]
|
217
|
-
}
|
218
|
-
| expr kOR expr
|
219
|
-
{
|
220
|
-
result = logical_op :or, val[0], val[2]
|
221
|
-
}
|
222
|
-
| kNOT opt_nl expr
|
223
|
-
{
|
224
|
-
result = s(:call, val[2], :"!")
|
225
|
-
}
|
226
|
-
| tBANG command_call
|
227
|
-
{
|
228
|
-
result = s(:call, val[1], :"!")
|
229
|
-
}
|
230
|
-
| arg
|
231
|
-
|
232
|
-
expr_value: expr
|
233
|
-
{
|
234
|
-
result = value_expr(val[0])
|
235
|
-
}
|
236
|
-
|
237
|
-
command_call: command
|
238
|
-
| block_command
|
239
|
-
|
240
|
-
block_command: block_call
|
241
|
-
| block_call tDOT operation2 command_args # TODO: dot_or_colon
|
242
|
-
{
|
243
|
-
result = new_call val[0], val[2].to_sym, val[3]
|
244
|
-
}
|
245
|
-
| block_call tCOLON2 operation2 command_args
|
246
|
-
{
|
247
|
-
result = new_call val[0], val[2].to_sym, val[3]
|
248
|
-
}
|
249
|
-
|
250
|
-
cmd_brace_block: tLBRACE_ARG
|
251
|
-
{
|
252
|
-
self.env.extend(:dynamic)
|
253
|
-
result = self.lexer.lineno
|
254
|
-
}
|
255
|
-
opt_block_param
|
256
|
-
{
|
257
|
-
result = nil # self.env.dynamic.keys
|
258
|
-
}
|
259
|
-
compstmt tRCURLY
|
260
|
-
{
|
261
|
-
result = new_iter nil, val[2], val[4]
|
262
|
-
result.line = val[1]
|
263
|
-
|
264
|
-
self.env.unextend
|
265
|
-
}
|
266
|
-
|
267
|
-
command: operation command_args =tLOWEST
|
268
|
-
{
|
269
|
-
result = new_call nil, val[0].to_sym, val[1]
|
270
|
-
}
|
271
|
-
| operation command_args cmd_brace_block
|
272
|
-
{
|
273
|
-
result = new_call nil, val[0].to_sym, val[1]
|
274
|
-
if val[2] then
|
275
|
-
block_dup_check result, val[2]
|
276
|
-
|
277
|
-
result, operation = val[2], result
|
278
|
-
result.insert 1, operation
|
279
|
-
end
|
280
|
-
}
|
281
|
-
| primary_value tDOT operation2 command_args =tLOWEST
|
282
|
-
{
|
283
|
-
result = new_call val[0], val[2].to_sym, val[3]
|
284
|
-
}
|
285
|
-
| primary_value tDOT operation2 command_args cmd_brace_block
|
286
|
-
{
|
287
|
-
recv, _, msg, args, block = val
|
288
|
-
call = new_call recv, msg.to_sym, args
|
289
|
-
|
290
|
-
block_dup_check call, block
|
291
|
-
|
292
|
-
block.insert 1, call
|
293
|
-
result = block
|
294
|
-
}
|
295
|
-
| primary_value tCOLON2 operation2 command_args =tLOWEST
|
296
|
-
{
|
297
|
-
result = new_call val[0], val[2].to_sym, val[3]
|
298
|
-
}
|
299
|
-
| primary_value tCOLON2 operation2 command_args cmd_brace_block
|
300
|
-
{
|
301
|
-
recv, _, msg, args, block = val
|
302
|
-
call = new_call recv, msg.to_sym, args
|
303
|
-
|
304
|
-
block_dup_check call, block
|
305
|
-
|
306
|
-
block.insert 1, call
|
307
|
-
result = block
|
308
|
-
}
|
309
|
-
| kSUPER command_args
|
310
|
-
{
|
311
|
-
result = new_super val[1]
|
312
|
-
}
|
313
|
-
| kYIELD command_args
|
314
|
-
{
|
315
|
-
result = new_yield val[1]
|
316
|
-
}
|
317
|
-
| kRETURN call_args
|
318
|
-
{
|
319
|
-
line = val[0].last
|
320
|
-
result = s(:return, ret_args(val[1])).line(line)
|
321
|
-
}
|
322
|
-
| kBREAK call_args
|
323
|
-
{
|
324
|
-
line = val[0].last
|
325
|
-
result = s(:break, ret_args(val[1])).line(line)
|
326
|
-
}
|
327
|
-
| kNEXT call_args
|
328
|
-
{
|
329
|
-
line = val[0].last
|
330
|
-
result = s(:next, ret_args(val[1])).line(line)
|
331
|
-
}
|
332
|
-
|
333
|
-
mlhs: mlhs_basic
|
334
|
-
| tLPAREN mlhs_inner rparen
|
335
|
-
{
|
336
|
-
result = val[1]
|
337
|
-
}
|
338
|
-
|
339
|
-
mlhs_inner: mlhs_basic
|
340
|
-
| tLPAREN mlhs_inner rparen
|
341
|
-
{
|
342
|
-
result = s(:masgn, s(:array, val[1]))
|
343
|
-
}
|
344
|
-
|
345
|
-
mlhs_basic: mlhs_head
|
346
|
-
{
|
347
|
-
result = s(:masgn, val[0])
|
348
|
-
}
|
349
|
-
| mlhs_head mlhs_item
|
350
|
-
{
|
351
|
-
result = s(:masgn, val[0] << val[1].compact)
|
352
|
-
}
|
353
|
-
| mlhs_head tSTAR mlhs_node
|
354
|
-
{
|
355
|
-
result = s(:masgn, val[0] << s(:splat, val[2]))
|
356
|
-
}
|
357
|
-
| mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
|
358
|
-
{
|
359
|
-
ary = list_append val[0], s(:splat, val[2])
|
360
|
-
ary.concat val[4].sexp_body
|
361
|
-
result = s(:masgn, ary)
|
362
|
-
}
|
363
|
-
| mlhs_head tSTAR
|
364
|
-
{
|
365
|
-
result = s(:masgn, val[0] << s(:splat))
|
366
|
-
}
|
367
|
-
| mlhs_head tSTAR tCOMMA mlhs_post
|
368
|
-
{
|
369
|
-
ary = list_append val[0], s(:splat)
|
370
|
-
ary.concat val[3].sexp_body
|
371
|
-
result = s(:masgn, ary)
|
372
|
-
}
|
373
|
-
| tSTAR mlhs_node
|
374
|
-
{
|
375
|
-
result = s(:masgn, s(:array, s(:splat, val[1])))
|
376
|
-
}
|
377
|
-
| tSTAR mlhs_node tCOMMA mlhs_post
|
378
|
-
{
|
379
|
-
ary = s(:array, s(:splat, val[1]))
|
380
|
-
ary.concat val[3].sexp_body
|
381
|
-
result = s(:masgn, ary)
|
382
|
-
}
|
383
|
-
| tSTAR
|
384
|
-
{
|
385
|
-
result = s(:masgn, s(:array, s(:splat)))
|
386
|
-
}
|
387
|
-
| tSTAR tCOMMA mlhs_post
|
388
|
-
{
|
389
|
-
ary = s(:array, s(:splat))
|
390
|
-
ary.concat val[2].sexp_body
|
391
|
-
result = s(:masgn, ary)
|
392
|
-
}
|
393
|
-
|
394
|
-
mlhs_item: mlhs_node
|
395
|
-
| tLPAREN mlhs_inner rparen
|
396
|
-
{
|
397
|
-
result = val[1]
|
398
|
-
}
|
399
|
-
|
400
|
-
mlhs_head: mlhs_item tCOMMA
|
401
|
-
{
|
402
|
-
result = s(:array, val[0])
|
403
|
-
}
|
404
|
-
| mlhs_head mlhs_item tCOMMA
|
405
|
-
{
|
406
|
-
result = val[0] << val[1].compact
|
407
|
-
}
|
408
|
-
|
409
|
-
mlhs_post: mlhs_item
|
410
|
-
{
|
411
|
-
result = s(:array, val[0])
|
412
|
-
}
|
413
|
-
| mlhs_post tCOMMA mlhs_item
|
414
|
-
{
|
415
|
-
result = list_append val[0], val[2]
|
416
|
-
}
|
417
|
-
|
418
|
-
mlhs_node: user_variable
|
419
|
-
{
|
420
|
-
result = self.assignable val[0]
|
421
|
-
}
|
422
|
-
| keyword_variable
|
423
|
-
{
|
424
|
-
result = self.assignable val[0]
|
425
|
-
}
|
426
|
-
| primary_value tLBRACK2 opt_call_args rbracket
|
427
|
-
{
|
428
|
-
result = self.aryset val[0], val[2]
|
429
|
-
}
|
430
|
-
| primary_value tDOT tIDENTIFIER
|
431
|
-
{
|
432
|
-
result = s(:attrasgn, val[0], :"#{val[2]}=")
|
433
|
-
}
|
434
|
-
| primary_value tCOLON2 tIDENTIFIER
|
435
|
-
{
|
436
|
-
result = s(:attrasgn, val[0], :"#{val[2]}=")
|
437
|
-
}
|
438
|
-
| primary_value tDOT tCONSTANT
|
439
|
-
{
|
440
|
-
result = s(:attrasgn, val[0], :"#{val[2]}=")
|
441
|
-
}
|
442
|
-
| primary_value tCOLON2 tCONSTANT
|
443
|
-
{
|
444
|
-
if (self.in_def || self.in_single > 0) then
|
445
|
-
yyerror "dynamic constant assignment"
|
446
|
-
end
|
447
|
-
|
448
|
-
result = s(:const, s(:colon2, val[0], val[2].to_sym), nil)
|
449
|
-
}
|
450
|
-
| tCOLON3 tCONSTANT
|
451
|
-
{
|
452
|
-
if (self.in_def || self.in_single > 0) then
|
453
|
-
yyerror "dynamic constant assignment"
|
454
|
-
end
|
455
|
-
|
456
|
-
result = s(:const, nil, s(:colon3, val[1].to_sym))
|
457
|
-
}
|
458
|
-
| backref
|
459
|
-
{
|
460
|
-
self.backref_assign_error val[0]
|
461
|
-
}
|
462
|
-
|
463
|
-
lhs: user_variable
|
464
|
-
{
|
465
|
-
result = self.assignable val[0]
|
466
|
-
}
|
467
|
-
| keyword_variable
|
468
|
-
{
|
469
|
-
result = self.assignable val[0]
|
470
|
-
}
|
471
|
-
| primary_value tLBRACK2 opt_call_args rbracket
|
472
|
-
{
|
473
|
-
result = self.aryset val[0], val[2]
|
474
|
-
}
|
475
|
-
| primary_value tDOT tIDENTIFIER
|
476
|
-
{
|
477
|
-
result = s(:attrasgn, val[0], :"#{val[2]}=")
|
478
|
-
}
|
479
|
-
| primary_value tCOLON2 tIDENTIFIER
|
480
|
-
{
|
481
|
-
result = s(:attrasgn, val[0], :"#{val[2]}=")
|
482
|
-
}
|
483
|
-
| primary_value tDOT tCONSTANT
|
484
|
-
{
|
485
|
-
result = s(:attrasgn, val[0], :"#{val[2]}=")
|
486
|
-
}
|
487
|
-
| primary_value tCOLON2 tCONSTANT
|
488
|
-
{
|
489
|
-
if (self.in_def || self.in_single > 0) then
|
490
|
-
yyerror "dynamic constant assignment"
|
491
|
-
end
|
492
|
-
|
493
|
-
result = s(:const, s(:colon2, val[0], val[2].to_sym))
|
494
|
-
}
|
495
|
-
| tCOLON3 tCONSTANT
|
496
|
-
{
|
497
|
-
if (self.in_def || self.in_single > 0) then
|
498
|
-
yyerror "dynamic constant assignment"
|
499
|
-
end
|
500
|
-
|
501
|
-
result = s(:const, s(:colon3, val[1].to_sym))
|
502
|
-
}
|
503
|
-
| backref
|
504
|
-
{
|
505
|
-
self.backref_assign_error val[0]
|
506
|
-
}
|
507
|
-
|
508
|
-
cname: tIDENTIFIER
|
509
|
-
{
|
510
|
-
yyerror "class/module name must be CONSTANT"
|
511
|
-
}
|
512
|
-
| tCONSTANT
|
513
|
-
|
514
|
-
cpath: tCOLON3 cname
|
515
|
-
{
|
516
|
-
result = s(:colon3, val[1].to_sym)
|
517
|
-
}
|
518
|
-
| cname
|
519
|
-
{
|
520
|
-
result = val[0].to_sym
|
521
|
-
}
|
522
|
-
| primary_value tCOLON2 cname
|
523
|
-
{
|
524
|
-
result = s(:colon2, val[0], val[2].to_sym)
|
525
|
-
}
|
526
|
-
|
527
|
-
fname: tIDENTIFIER | tCONSTANT | tFID
|
528
|
-
| op
|
529
|
-
{
|
530
|
-
lexer.lex_state = :expr_end
|
531
|
-
result = val[0]
|
532
|
-
}
|
533
|
-
|
534
|
-
| reswords
|
535
|
-
{
|
536
|
-
lexer.lex_state = :expr_end
|
537
|
-
result = val[0]
|
538
|
-
}
|
539
|
-
|
540
|
-
fsym: fname | symbol
|
541
|
-
|
542
|
-
fitem: fsym { result = s(:lit, val[0].to_sym) }
|
543
|
-
| dsym
|
544
|
-
|
545
|
-
undef_list: fitem
|
546
|
-
{
|
547
|
-
result = new_undef val[0]
|
548
|
-
}
|
549
|
-
|
|
550
|
-
undef_list tCOMMA
|
551
|
-
{
|
552
|
-
lexer.lex_state = :expr_fname
|
553
|
-
}
|
554
|
-
fitem
|
555
|
-
{
|
556
|
-
result = new_undef val[0], val[3]
|
557
|
-
}
|
558
|
-
|
559
|
-
op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
|
560
|
-
| tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
|
561
|
-
| tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
|
562
|
-
| tSTAR | tDIVIDE | tPERCENT | tPOW | tBANG | tTILDE
|
563
|
-
| tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
|
564
|
-
|
565
|
-
reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
|
566
|
-
| kALIAS | kAND | kBEGIN | kBREAK | kCASE
|
567
|
-
| kCLASS | kDEF | kDEFINED | kDO | kELSE
|
568
|
-
| kELSIF | kEND | kENSURE | kFALSE | kFOR
|
569
|
-
| kIN | kMODULE | kNEXT | kNIL | kNOT
|
570
|
-
| kOR | kREDO | kRESCUE | kRETRY | kRETURN
|
571
|
-
| kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
|
572
|
-
| kWHEN | kYIELD | kIF | kUNLESS | kWHILE
|
573
|
-
| kUNTIL
|
574
|
-
|
575
|
-
arg: lhs tEQL arg
|
576
|
-
{
|
577
|
-
result = new_assign val[0], val[2]
|
578
|
-
}
|
579
|
-
| lhs tEQL arg kRESCUE_MOD arg
|
580
|
-
{
|
581
|
-
result = new_assign val[0], s(:rescue, val[2], new_resbody(s(:array), val[4]))
|
582
|
-
}
|
583
|
-
| var_lhs tOP_ASGN arg
|
584
|
-
{
|
585
|
-
result = new_op_asgn val
|
586
|
-
}
|
587
|
-
| var_lhs tOP_ASGN arg kRESCUE_MOD arg
|
588
|
-
{
|
589
|
-
result = new_op_asgn val
|
590
|
-
result = s(:rescue, result, new_resbody(s(:array), val[4]))
|
591
|
-
}
|
592
|
-
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
|
593
|
-
{
|
594
|
-
val[2].sexp_type = :arglist if val[2]
|
595
|
-
result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
|
596
|
-
}
|
597
|
-
| primary_value tDOT tIDENTIFIER tOP_ASGN arg
|
598
|
-
{
|
599
|
-
result = s(:op_asgn2, val[0], :"#{val[2]}=", val[3].to_sym, val[4])
|
600
|
-
}
|
601
|
-
| primary_value tDOT tCONSTANT tOP_ASGN arg
|
602
|
-
{
|
603
|
-
result = s(:op_asgn2, val[0], :"#{val[2]}=", val[3].to_sym, val[4])
|
604
|
-
}
|
605
|
-
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
|
606
|
-
{
|
607
|
-
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
608
|
-
}
|
609
|
-
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg
|
610
|
-
{
|
611
|
-
yyerror "constant re-assignment"
|
612
|
-
}
|
613
|
-
| tCOLON3 tCONSTANT tOP_ASGN arg
|
614
|
-
{
|
615
|
-
yyerror "constant re-assignment"
|
616
|
-
}
|
617
|
-
| backref tOP_ASGN arg
|
618
|
-
{
|
619
|
-
self.backref_assign_error val[0]
|
620
|
-
}
|
621
|
-
| arg tDOT2 arg
|
622
|
-
{
|
623
|
-
v1, v2 = val[0], val[2]
|
624
|
-
if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
|
625
|
-
result = s(:lit, (v1.last)..(v2.last))
|
626
|
-
else
|
627
|
-
result = s(:dot2, v1, v2)
|
628
|
-
end
|
629
|
-
}
|
630
|
-
| arg tDOT3 arg
|
631
|
-
{
|
632
|
-
v1, v2 = val[0], val[2]
|
633
|
-
if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
|
634
|
-
result = s(:lit, (v1.last)...(v2.last))
|
635
|
-
else
|
636
|
-
result = s(:dot3, v1, v2)
|
637
|
-
end
|
638
|
-
}
|
639
|
-
| arg tPLUS arg
|
640
|
-
{
|
641
|
-
result = new_call val[0], :+, argl(val[2])
|
642
|
-
}
|
643
|
-
| arg tMINUS arg
|
644
|
-
{
|
645
|
-
result = new_call val[0], :-, argl(val[2])
|
646
|
-
}
|
647
|
-
| arg tSTAR2 arg
|
648
|
-
{
|
649
|
-
result = new_call val[0], :*, argl(val[2])
|
650
|
-
}
|
651
|
-
| arg tDIVIDE arg
|
652
|
-
{
|
653
|
-
result = new_call val[0], :"/", argl(val[2])
|
654
|
-
}
|
655
|
-
| arg tPERCENT arg
|
656
|
-
{
|
657
|
-
result = new_call val[0], :"%", argl(val[2])
|
658
|
-
}
|
659
|
-
| arg tPOW arg
|
660
|
-
{
|
661
|
-
result = new_call val[0], :**, argl(val[2])
|
662
|
-
}
|
663
|
-
| tUMINUS_NUM tINTEGER tPOW arg
|
664
|
-
{
|
665
|
-
result = new_call(new_call(s(:lit, val[1]), :"**", argl(val[3])), :"-@")
|
666
|
-
}
|
667
|
-
| tUMINUS_NUM tFLOAT tPOW arg
|
668
|
-
{
|
669
|
-
result = new_call(new_call(s(:lit, val[1]), :"**", argl(val[3])), :"-@")
|
670
|
-
}
|
671
|
-
| tUPLUS arg
|
672
|
-
{
|
673
|
-
result = new_call val[1], :"+@"
|
674
|
-
}
|
675
|
-
| tUMINUS arg
|
676
|
-
{
|
677
|
-
result = new_call val[1], :"-@"
|
678
|
-
}
|
679
|
-
| arg tPIPE arg
|
680
|
-
{
|
681
|
-
result = new_call val[0], :"|", argl(val[2])
|
682
|
-
}
|
683
|
-
| arg tCARET arg
|
684
|
-
{
|
685
|
-
result = new_call val[0], :"^", argl(val[2])
|
686
|
-
}
|
687
|
-
| arg tAMPER2 arg
|
688
|
-
{
|
689
|
-
result = new_call val[0], :"&", argl(val[2])
|
690
|
-
}
|
691
|
-
| arg tCMP arg
|
692
|
-
{
|
693
|
-
result = new_call val[0], :"<=>", argl(val[2])
|
694
|
-
}
|
695
|
-
| arg tGT arg
|
696
|
-
{
|
697
|
-
result = new_call val[0], :">", argl(val[2])
|
698
|
-
}
|
699
|
-
| arg tGEQ arg
|
700
|
-
{
|
701
|
-
result = new_call val[0], :">=", argl(val[2])
|
702
|
-
}
|
703
|
-
| arg tLT arg
|
704
|
-
{
|
705
|
-
result = new_call val[0], :"<", argl(val[2])
|
706
|
-
}
|
707
|
-
| arg tLEQ arg
|
708
|
-
{
|
709
|
-
result = new_call val[0], :"<=", argl(val[2])
|
710
|
-
}
|
711
|
-
| arg tEQ arg
|
712
|
-
{
|
713
|
-
result = new_call val[0], :"==", argl(val[2])
|
714
|
-
}
|
715
|
-
| arg tEQQ arg
|
716
|
-
{
|
717
|
-
result = new_call val[0], :"===", argl(val[2])
|
718
|
-
}
|
719
|
-
| arg tNEQ arg
|
720
|
-
{
|
721
|
-
result = new_call val[0], :"!=", argl(val[2])
|
722
|
-
}
|
723
|
-
| arg tMATCH arg
|
724
|
-
{
|
725
|
-
result = new_match val[0], val[2]
|
726
|
-
}
|
727
|
-
| arg tNMATCH arg
|
728
|
-
{
|
729
|
-
result = s(:not, new_match(val[0], val[2]))
|
730
|
-
}
|
731
|
-
| tBANG arg
|
732
|
-
{
|
733
|
-
result = new_call val[1], :"!"
|
734
|
-
}
|
735
|
-
| tTILDE arg
|
736
|
-
{
|
737
|
-
val[2] = value_expr val[2]
|
738
|
-
result = new_call val[1], :"~"
|
739
|
-
}
|
740
|
-
| arg tLSHFT arg
|
741
|
-
{
|
742
|
-
val[0] = value_expr val[0]
|
743
|
-
val[2] = value_expr val[2]
|
744
|
-
result = new_call val[0], :"\<\<", argl(val[2])
|
745
|
-
}
|
746
|
-
| arg tRSHFT arg
|
747
|
-
{
|
748
|
-
val[0] = value_expr val[0]
|
749
|
-
val[2] = value_expr val[2]
|
750
|
-
result = new_call val[0], :">>", argl(val[2])
|
751
|
-
}
|
752
|
-
| arg tANDOP arg
|
753
|
-
{
|
754
|
-
result = logical_op :and, val[0], val[2]
|
755
|
-
}
|
756
|
-
| arg tOROP arg
|
757
|
-
{
|
758
|
-
result = logical_op :or, val[0], val[2]
|
759
|
-
}
|
760
|
-
| kDEFINED opt_nl arg
|
761
|
-
{
|
762
|
-
result = s(:defined, val[2])
|
763
|
-
}
|
764
|
-
| arg tEH arg opt_nl tCOLON arg
|
765
|
-
{
|
766
|
-
result = s(:if, val[0], val[2], val[5])
|
767
|
-
}
|
768
|
-
| primary
|
769
|
-
|
770
|
-
arg_value: arg
|
771
|
-
{
|
772
|
-
result = value_expr(val[0])
|
773
|
-
}
|
774
|
-
|
775
|
-
aref_args: none
|
776
|
-
| args trailer
|
777
|
-
{
|
778
|
-
result = val[0]
|
779
|
-
}
|
780
|
-
| args tCOMMA assocs trailer
|
781
|
-
{
|
782
|
-
result = val[0] << s(:hash, *val[2].values)
|
783
|
-
}
|
784
|
-
| assocs trailer
|
785
|
-
{
|
786
|
-
result = s(:array, s(:hash, *val[0].values))
|
787
|
-
}
|
788
|
-
|
789
|
-
paren_args: tLPAREN2 opt_call_args rparen
|
790
|
-
{
|
791
|
-
result = val[1]
|
792
|
-
}
|
793
|
-
|
794
|
-
opt_paren_args: none
|
795
|
-
| paren_args
|
796
|
-
|
797
|
-
opt_call_args: none
|
798
|
-
{
|
799
|
-
result = val[0]
|
800
|
-
}
|
801
|
-
| call_args
|
802
|
-
{
|
803
|
-
result = val[0]
|
804
|
-
}
|
805
|
-
| args tCOMMA
|
806
|
-
{
|
807
|
-
result = val[0]
|
808
|
-
}
|
809
|
-
| args tCOMMA assocs tCOMMA
|
810
|
-
{
|
811
|
-
result = val[0] << s(:hash, *val[2].sexp_body) # TODO: self.args
|
812
|
-
}
|
813
|
-
| assocs tCOMMA
|
814
|
-
{
|
815
|
-
result = s(:hash, *val[0].values)
|
816
|
-
}
|
817
|
-
|
818
|
-
call_args: command
|
819
|
-
{
|
820
|
-
warning "parenthesize argument(s) for future version"
|
821
|
-
result = s(:array, val[0])
|
822
|
-
}
|
823
|
-
| args opt_block_arg
|
824
|
-
{
|
825
|
-
result = self.arg_blk_pass val[0], val[1]
|
826
|
-
}
|
827
|
-
| assocs opt_block_arg
|
828
|
-
{
|
829
|
-
result = s(:array, s(:hash, *val[0].values))
|
830
|
-
result = self.arg_blk_pass result, val[1]
|
831
|
-
}
|
832
|
-
| args tCOMMA assocs opt_block_arg
|
833
|
-
{
|
834
|
-
result = val[0] << s(:hash, *val[2].values)
|
835
|
-
result = self.arg_blk_pass result, val[3]
|
836
|
-
}
|
837
|
-
| block_arg
|
838
|
-
|
839
|
-
command_args: {
|
840
|
-
result = lexer.cmdarg.stack.dup # TODO: smell?
|
841
|
-
lexer.cmdarg.push true
|
842
|
-
}
|
843
|
-
call_args
|
844
|
-
{
|
845
|
-
lexer.cmdarg.stack.replace val[0]
|
846
|
-
result = val[1]
|
847
|
-
}
|
848
|
-
|
849
|
-
block_arg: tAMPER arg_value
|
850
|
-
{
|
851
|
-
result = s(:block_pass, val[1])
|
852
|
-
}
|
853
|
-
|
854
|
-
opt_block_arg: tCOMMA block_arg
|
855
|
-
{
|
856
|
-
result = val[1]
|
857
|
-
}
|
858
|
-
| none
|
859
|
-
|
860
|
-
args: arg_value
|
861
|
-
{
|
862
|
-
result = s(:array, val[0])
|
863
|
-
}
|
864
|
-
| tSTAR arg_value
|
865
|
-
{
|
866
|
-
result = s(:array, s(:splat, val[1]))
|
867
|
-
}
|
868
|
-
| args tCOMMA arg_value
|
869
|
-
{
|
870
|
-
result = self.list_append val[0], val[2]
|
871
|
-
}
|
872
|
-
| args tCOMMA tSTAR arg_value
|
873
|
-
{
|
874
|
-
result = self.list_append val[0], s(:splat, val[3])
|
875
|
-
}
|
876
|
-
|
877
|
-
mrhs: args tCOMMA arg_value
|
878
|
-
{
|
879
|
-
result = val[0] << val[2]
|
880
|
-
}
|
881
|
-
| args tCOMMA tSTAR arg_value
|
882
|
-
{
|
883
|
-
result = self.arg_concat val[0], val[3]
|
884
|
-
}
|
885
|
-
| tSTAR arg_value
|
886
|
-
{
|
887
|
-
result = s(:splat, val[1])
|
888
|
-
}
|
889
|
-
|
890
|
-
primary: literal
|
891
|
-
| strings
|
892
|
-
| xstring
|
893
|
-
| regexp
|
894
|
-
| words
|
895
|
-
| qwords
|
896
|
-
| var_ref
|
897
|
-
| backref
|
898
|
-
| tFID
|
899
|
-
{
|
900
|
-
result = new_call nil, val[0].to_sym
|
901
|
-
}
|
902
|
-
| kBEGIN
|
903
|
-
{
|
904
|
-
result = self.lexer.lineno
|
905
|
-
}
|
906
|
-
bodystmt kEND
|
907
|
-
{
|
908
|
-
unless val[2] then
|
909
|
-
result = s(:nil)
|
910
|
-
else
|
911
|
-
result = s(:begin, val[2])
|
912
|
-
end
|
913
|
-
|
914
|
-
result.line = val[1]
|
915
|
-
}
|
916
|
-
| tLPAREN_ARG expr
|
917
|
-
{
|
918
|
-
lexer.lex_state = :expr_endarg
|
919
|
-
}
|
920
|
-
rparen
|
921
|
-
{
|
922
|
-
warning "(...) interpreted as grouped expression"
|
923
|
-
result = val[1]
|
924
|
-
}
|
925
|
-
| tLPAREN compstmt tRPAREN
|
926
|
-
{
|
927
|
-
result = val[1] || s(:nil)
|
928
|
-
result.paren = true
|
929
|
-
}
|
930
|
-
| primary_value tCOLON2 tCONSTANT
|
931
|
-
{
|
932
|
-
result = s(:colon2, val[0], val[2].to_sym)
|
933
|
-
}
|
934
|
-
| tCOLON3 tCONSTANT
|
935
|
-
{
|
936
|
-
result = s(:colon3, val[1].to_sym)
|
937
|
-
}
|
938
|
-
| tLBRACK aref_args tRBRACK
|
939
|
-
{
|
940
|
-
result = val[1] || s(:array)
|
941
|
-
}
|
942
|
-
| tLBRACE
|
943
|
-
{
|
944
|
-
result = self.lexer.lineno
|
945
|
-
}
|
946
|
-
assoc_list tRCURLY
|
947
|
-
{
|
948
|
-
result = new_hash val
|
949
|
-
}
|
950
|
-
| kRETURN
|
951
|
-
{
|
952
|
-
result = s(:return)
|
953
|
-
}
|
954
|
-
| kYIELD tLPAREN2 call_args rparen
|
955
|
-
{
|
956
|
-
result = new_yield val[2]
|
957
|
-
}
|
958
|
-
| kYIELD tLPAREN2 rparen
|
959
|
-
{
|
960
|
-
result = new_yield
|
961
|
-
}
|
962
|
-
| kYIELD
|
963
|
-
{
|
964
|
-
result = new_yield
|
965
|
-
}
|
966
|
-
| kDEFINED opt_nl tLPAREN2 expr rparen
|
967
|
-
{
|
968
|
-
result = s(:defined, val[3])
|
969
|
-
}
|
970
|
-
| kNOT tLPAREN2 expr rparen
|
971
|
-
{
|
972
|
-
result = s(:call, val[2], :"!")
|
973
|
-
}
|
974
|
-
| kNOT tLPAREN2 rparen
|
975
|
-
{
|
976
|
-
raise "no3\non#{val.inspect}"
|
977
|
-
}
|
978
|
-
| operation brace_block
|
979
|
-
{
|
980
|
-
oper, iter = val[0], val[1]
|
981
|
-
call = new_call nil, oper.to_sym
|
982
|
-
iter.insert 1, call
|
983
|
-
result = iter
|
984
|
-
call.line = iter.line
|
985
|
-
}
|
986
|
-
| method_call
|
987
|
-
| method_call brace_block
|
988
|
-
{
|
989
|
-
call, iter = val[0], val[1]
|
990
|
-
block_dup_check call, iter
|
991
|
-
iter.insert 1, call # FIX
|
992
|
-
result = iter
|
993
|
-
}
|
994
|
-
| tLAMBDA lambda
|
995
|
-
{
|
996
|
-
result = val[1] # TODO: fix lineno
|
997
|
-
}
|
998
|
-
| kIF expr_value then compstmt if_tail kEND
|
999
|
-
{
|
1000
|
-
result = new_if val[1], val[3], val[4]
|
1001
|
-
}
|
1002
|
-
| kUNLESS expr_value then compstmt opt_else kEND
|
1003
|
-
{
|
1004
|
-
result = new_if val[1], val[4], val[3]
|
1005
|
-
}
|
1006
|
-
| kWHILE
|
1007
|
-
{
|
1008
|
-
lexer.cond.push true
|
1009
|
-
}
|
1010
|
-
expr_value do
|
1011
|
-
{
|
1012
|
-
lexer.cond.pop
|
1013
|
-
}
|
1014
|
-
compstmt kEND
|
1015
|
-
{
|
1016
|
-
result = new_while val[5], val[2], true
|
1017
|
-
}
|
1018
|
-
| kUNTIL
|
1019
|
-
{
|
1020
|
-
lexer.cond.push true
|
1021
|
-
}
|
1022
|
-
expr_value do
|
1023
|
-
{
|
1024
|
-
lexer.cond.pop
|
1025
|
-
}
|
1026
|
-
compstmt kEND
|
1027
|
-
{
|
1028
|
-
result = new_until val[5], val[2], true
|
1029
|
-
}
|
1030
|
-
| kCASE expr_value opt_terms case_body kEND
|
1031
|
-
{
|
1032
|
-
(_, line), expr, _, body, _ = val
|
1033
|
-
result = new_case expr, body, line
|
1034
|
-
}
|
1035
|
-
| kCASE opt_terms case_body kEND
|
1036
|
-
{
|
1037
|
-
(_, line), _, body, _ = val
|
1038
|
-
result = new_case nil, body, line
|
1039
|
-
}
|
1040
|
-
| kFOR for_var kIN
|
1041
|
-
{
|
1042
|
-
lexer.cond.push true
|
1043
|
-
}
|
1044
|
-
expr_value do
|
1045
|
-
{
|
1046
|
-
lexer.cond.pop
|
1047
|
-
}
|
1048
|
-
compstmt kEND
|
1049
|
-
{
|
1050
|
-
result = new_for val[4], val[1], val[7]
|
1051
|
-
}
|
1052
|
-
| kCLASS
|
1053
|
-
{
|
1054
|
-
result = self.lexer.lineno
|
1055
|
-
}
|
1056
|
-
cpath superclass
|
1057
|
-
{
|
1058
|
-
self.comments.push self.lexer.comments
|
1059
|
-
if (self.in_def || self.in_single > 0) then
|
1060
|
-
yyerror "class definition in method body"
|
1061
|
-
end
|
1062
|
-
self.env.extend
|
1063
|
-
}
|
1064
|
-
bodystmt kEND
|
1065
|
-
{
|
1066
|
-
result = new_class val
|
1067
|
-
self.env.unextend
|
1068
|
-
self.lexer.comments # we don't care about comments in the body
|
1069
|
-
}
|
1070
|
-
| kCLASS tLSHFT
|
1071
|
-
{
|
1072
|
-
result = self.lexer.lineno
|
1073
|
-
}
|
1074
|
-
expr
|
1075
|
-
{
|
1076
|
-
result = self.in_def
|
1077
|
-
self.in_def = false
|
1078
|
-
}
|
1079
|
-
term
|
1080
|
-
{
|
1081
|
-
result = self.in_single
|
1082
|
-
self.in_single = 0
|
1083
|
-
self.env.extend
|
1084
|
-
}
|
1085
|
-
bodystmt kEND
|
1086
|
-
{
|
1087
|
-
result = new_sclass val
|
1088
|
-
self.env.unextend
|
1089
|
-
self.lexer.comments # we don't care about comments in the body
|
1090
|
-
}
|
1091
|
-
| kMODULE
|
1092
|
-
{
|
1093
|
-
result = self.lexer.lineno
|
1094
|
-
}
|
1095
|
-
cpath
|
1096
|
-
{
|
1097
|
-
self.comments.push self.lexer.comments
|
1098
|
-
yyerror "module definition in method body" if
|
1099
|
-
self.in_def or self.in_single > 0
|
1100
|
-
|
1101
|
-
self.env.extend
|
1102
|
-
}
|
1103
|
-
bodystmt kEND
|
1104
|
-
{
|
1105
|
-
result = new_module val
|
1106
|
-
self.env.unextend
|
1107
|
-
self.lexer.comments # we don't care about comments in the body
|
1108
|
-
}
|
1109
|
-
| kDEF fname
|
1110
|
-
{
|
1111
|
-
result = [self.in_def, self.lexer.cmdarg.stack.dup]
|
1112
|
-
|
1113
|
-
self.comments.push self.lexer.comments
|
1114
|
-
self.in_def = true
|
1115
|
-
self.env.extend
|
1116
|
-
lexer.cmdarg.stack.replace [false]
|
1117
|
-
}
|
1118
|
-
f_arglist bodystmt kEND
|
1119
|
-
{
|
1120
|
-
in_def, cmdarg = val[2]
|
1121
|
-
|
1122
|
-
result = new_defn val
|
1123
|
-
|
1124
|
-
lexer.cmdarg.stack.replace cmdarg
|
1125
|
-
self.env.unextend
|
1126
|
-
self.in_def = in_def
|
1127
|
-
self.lexer.comments # we don't care about comments in the body
|
1128
|
-
}
|
1129
|
-
| kDEF singleton dot_or_colon
|
1130
|
-
{
|
1131
|
-
self.comments.push self.lexer.comments
|
1132
|
-
lexer.lex_state = :expr_fname
|
1133
|
-
}
|
1134
|
-
fname
|
1135
|
-
{
|
1136
|
-
self.in_single += 1
|
1137
|
-
self.env.extend
|
1138
|
-
lexer.lex_state = :expr_end # force for args
|
1139
|
-
result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
|
1140
|
-
lexer.cmdarg.stack.replace [false]
|
1141
|
-
}
|
1142
|
-
f_arglist bodystmt kEND
|
1143
|
-
{
|
1144
|
-
line, cmdarg = val[5]
|
1145
|
-
result = new_defs val
|
1146
|
-
result[3].line line
|
1147
|
-
|
1148
|
-
lexer.cmdarg.stack.replace cmdarg
|
1149
|
-
self.env.unextend
|
1150
|
-
self.in_single -= 1
|
1151
|
-
self.lexer.comments # we don't care about comments in the body
|
1152
|
-
}
|
1153
|
-
| kBREAK
|
1154
|
-
{
|
1155
|
-
result = s(:break)
|
1156
|
-
}
|
1157
|
-
| kNEXT
|
1158
|
-
{
|
1159
|
-
result = s(:next)
|
1160
|
-
}
|
1161
|
-
| kREDO
|
1162
|
-
{
|
1163
|
-
result = s(:redo)
|
1164
|
-
}
|
1165
|
-
| kRETRY
|
1166
|
-
{
|
1167
|
-
result = s(:retry)
|
1168
|
-
}
|
1169
|
-
|
1170
|
-
primary_value: primary
|
1171
|
-
{
|
1172
|
-
result = value_expr(val[0])
|
1173
|
-
}
|
1174
|
-
|
1175
|
-
# These are really stupid
|
1176
|
-
k_begin: kBEGIN
|
1177
|
-
k_if: kIF
|
1178
|
-
k_unless: kUNLESS
|
1179
|
-
k_while: kWHILE
|
1180
|
-
k_until: kUNTIL
|
1181
|
-
k_case: kCASE
|
1182
|
-
k_for: kFOR
|
1183
|
-
k_class: kCLASS
|
1184
|
-
k_module: kMODULE
|
1185
|
-
k_def: kDEF
|
1186
|
-
k_end: kEND
|
1187
|
-
|
1188
|
-
then: term
|
1189
|
-
| kTHEN
|
1190
|
-
| term kTHEN
|
1191
|
-
|
1192
|
-
do: term
|
1193
|
-
| kDO_COND
|
1194
|
-
|
1195
|
-
if_tail: opt_else
|
1196
|
-
| kELSIF expr_value then compstmt if_tail
|
1197
|
-
{
|
1198
|
-
result = s(:if, val[1], val[3], val[4])
|
1199
|
-
}
|
1200
|
-
|
1201
|
-
opt_else: none
|
1202
|
-
| kELSE compstmt
|
1203
|
-
{
|
1204
|
-
result = val[1]
|
1205
|
-
}
|
1206
|
-
|
1207
|
-
for_var: lhs
|
1208
|
-
| mlhs
|
1209
|
-
{
|
1210
|
-
val[0].delete_at 1 if val[0][1].nil? # HACK
|
1211
|
-
}
|
1212
|
-
|
1213
|
-
f_marg: f_norm_arg
|
1214
|
-
| tLPAREN f_margs rparen
|
1215
|
-
{
|
1216
|
-
result = val[1]
|
1217
|
-
}
|
1218
|
-
|
1219
|
-
f_marg_list: f_marg
|
1220
|
-
{
|
1221
|
-
result = s(:array, val[0])
|
1222
|
-
}
|
1223
|
-
| f_marg_list tCOMMA f_marg
|
1224
|
-
{
|
1225
|
-
result = list_append val[0], val[2]
|
1226
|
-
}
|
1227
|
-
|
1228
|
-
f_margs: f_marg_list
|
1229
|
-
{
|
1230
|
-
args, = val
|
1231
|
-
|
1232
|
-
result = block_var args
|
1233
|
-
}
|
1234
|
-
| f_marg_list tCOMMA tSTAR f_norm_arg
|
1235
|
-
{
|
1236
|
-
args, _, _, splat = val
|
1237
|
-
|
1238
|
-
result = block_var args, "*#{splat}".to_sym
|
1239
|
-
}
|
1240
|
-
| f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
|
1241
|
-
{
|
1242
|
-
args, _, _, splat, _, args2 = val
|
1243
|
-
|
1244
|
-
result = block_var args, "*#{splat}".to_sym, args2
|
1245
|
-
}
|
1246
|
-
| f_marg_list tCOMMA tSTAR
|
1247
|
-
{
|
1248
|
-
args, _, _ = val
|
1249
|
-
|
1250
|
-
result = block_var args, :*
|
1251
|
-
}
|
1252
|
-
| f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
|
1253
|
-
{
|
1254
|
-
args, _, _, _, args2 = val
|
1255
|
-
|
1256
|
-
result = block_var args, :*, args2
|
1257
|
-
}
|
1258
|
-
| tSTAR f_norm_arg
|
1259
|
-
{
|
1260
|
-
_, splat = val
|
1261
|
-
|
1262
|
-
result = block_var :"*#{splat}"
|
1263
|
-
}
|
1264
|
-
| tSTAR f_norm_arg tCOMMA f_marg_list
|
1265
|
-
{
|
1266
|
-
_, splat, _, args = val
|
1267
|
-
|
1268
|
-
result = block_var :"*#{splat}", args
|
1269
|
-
}
|
1270
|
-
| tSTAR
|
1271
|
-
{
|
1272
|
-
result = block_var :*
|
1273
|
-
}
|
1274
|
-
| tSTAR tCOMMA f_marg_list
|
1275
|
-
{
|
1276
|
-
_, _, args = val
|
1277
|
-
|
1278
|
-
result = block_var :*, args
|
1279
|
-
}
|
1280
|
-
|
1281
|
-
block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_f_block_arg
|
1282
|
-
{
|
1283
|
-
result = args val
|
1284
|
-
}
|
1285
|
-
| f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
|
1286
|
-
{
|
1287
|
-
result = args val
|
1288
|
-
}
|
1289
|
-
| f_arg tCOMMA f_block_optarg opt_f_block_arg
|
1290
|
-
{
|
1291
|
-
result = args val
|
1292
|
-
}
|
1293
|
-
| f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_f_block_arg
|
1294
|
-
{
|
1295
|
-
result = args val
|
1296
|
-
}
|
1297
|
-
| f_arg tCOMMA f_rest_arg opt_f_block_arg
|
1298
|
-
{
|
1299
|
-
result = args val
|
1300
|
-
}
|
1301
|
-
| f_arg tCOMMA
|
1302
|
-
{
|
1303
|
-
result = args val
|
1304
|
-
}
|
1305
|
-
| f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
|
1306
|
-
{
|
1307
|
-
result = args val
|
1308
|
-
}
|
1309
|
-
| f_arg opt_f_block_arg
|
1310
|
-
{
|
1311
|
-
result = args val
|
1312
|
-
}
|
1313
|
-
| f_block_optarg tCOMMA f_rest_arg opt_f_block_arg
|
1314
|
-
{
|
1315
|
-
result = args val
|
1316
|
-
}
|
1317
|
-
| f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
|
1318
|
-
{
|
1319
|
-
result = args val
|
1320
|
-
}
|
1321
|
-
| f_block_optarg opt_f_block_arg
|
1322
|
-
{
|
1323
|
-
result = args val
|
1324
|
-
}
|
1325
|
-
| f_block_optarg tCOMMA f_arg opt_f_block_arg
|
1326
|
-
{
|
1327
|
-
result = args val
|
1328
|
-
}
|
1329
|
-
| f_rest_arg opt_f_block_arg
|
1330
|
-
{
|
1331
|
-
result = args val
|
1332
|
-
}
|
1333
|
-
| f_rest_arg tCOMMA f_arg opt_f_block_arg
|
1334
|
-
{
|
1335
|
-
result = args val
|
1336
|
-
}
|
1337
|
-
| f_block_arg
|
1338
|
-
{
|
1339
|
-
result = args val
|
1340
|
-
}
|
1341
|
-
|
1342
|
-
opt_block_param: none { result = 0 }
|
1343
|
-
| block_param_def
|
1344
|
-
|
1345
|
-
block_param_def: tPIPE opt_bv_decl tPIPE
|
1346
|
-
{
|
1347
|
-
result = args val
|
1348
|
-
}
|
1349
|
-
| tOROP
|
1350
|
-
{
|
1351
|
-
result = s(:args)
|
1352
|
-
self.lexer.command_start = true
|
1353
|
-
}
|
1354
|
-
| tPIPE block_param opt_bv_decl tPIPE
|
1355
|
-
{
|
1356
|
-
result = args val
|
1357
|
-
}
|
1358
|
-
|
1359
|
-
opt_bv_decl: none
|
1360
|
-
| tSEMI bv_decls
|
1361
|
-
{
|
1362
|
-
result = val[1]
|
1363
|
-
}
|
1364
|
-
|
1365
|
-
bv_decls: bvar
|
1366
|
-
{
|
1367
|
-
result = args val
|
1368
|
-
}
|
1369
|
-
| bv_decls tCOMMA bvar
|
1370
|
-
{
|
1371
|
-
result = args val
|
1372
|
-
}
|
1373
|
-
|
1374
|
-
bvar: tIDENTIFIER
|
1375
|
-
{
|
1376
|
-
result = s(:shadow, val[0].to_sym)
|
1377
|
-
}
|
1378
|
-
| f_bad_arg
|
1379
|
-
|
1380
|
-
lambda: {
|
1381
|
-
# TODO: dyna_push ? hrm
|
1382
|
-
result = lexer.lpar_beg
|
1383
|
-
lexer.paren_nest += 1
|
1384
|
-
lexer.lpar_beg = lexer.paren_nest
|
1385
|
-
}
|
1386
|
-
f_larglist lambda_body
|
1387
|
-
{
|
1388
|
-
lpar, args, body = val
|
1389
|
-
lexer.lpar_beg = lpar
|
1390
|
-
|
1391
|
-
call = new_call nil, :lambda
|
1392
|
-
result = new_iter call, args, body
|
1393
|
-
}
|
1394
|
-
|
1395
|
-
f_larglist: tLPAREN2 f_args opt_bv_decl rparen
|
1396
|
-
{
|
1397
|
-
result = args val
|
1398
|
-
}
|
1399
|
-
| f_args
|
1400
|
-
{
|
1401
|
-
result = val[0]
|
1402
|
-
result = 0 if result == s(:args)
|
1403
|
-
}
|
1404
|
-
|
1405
|
-
lambda_body: tLAMBEG compstmt tRCURLY
|
1406
|
-
{
|
1407
|
-
result = val[1]
|
1408
|
-
}
|
1409
|
-
| kDO_LAMBDA compstmt kEND
|
1410
|
-
{
|
1411
|
-
result = val[1]
|
1412
|
-
}
|
1413
|
-
|
1414
|
-
do_block: kDO_BLOCK
|
1415
|
-
{
|
1416
|
-
self.env.extend :dynamic
|
1417
|
-
result = self.lexer.lineno
|
1418
|
-
}
|
1419
|
-
opt_block_param
|
1420
|
-
{
|
1421
|
-
result = nil # self.env.dynamic.keys
|
1422
|
-
}
|
1423
|
-
compstmt kEND
|
1424
|
-
{
|
1425
|
-
args = val[2]
|
1426
|
-
body = val[4]
|
1427
|
-
result = new_iter nil, args, body
|
1428
|
-
result.line = val[1]
|
1429
|
-
|
1430
|
-
self.env.unextend
|
1431
|
-
}
|
1432
|
-
|
1433
|
-
block_call: command do_block
|
1434
|
-
{
|
1435
|
-
# TODO:
|
1436
|
-
# if (nd_type($1) == NODE_YIELD) {
|
1437
|
-
# compile_error(PARSER_ARG "block given to yield");
|
1438
|
-
|
1439
|
-
syntax_error "Both block arg and actual block given." if
|
1440
|
-
val[0].block_pass?
|
1441
|
-
|
1442
|
-
val = invert_block_call val if inverted? val
|
1443
|
-
|
1444
|
-
result = val[1]
|
1445
|
-
result.insert 1, val[0]
|
1446
|
-
}
|
1447
|
-
| block_call tDOT operation2 opt_paren_args
|
1448
|
-
{
|
1449
|
-
result = new_call val[0], val[2].to_sym, val[3]
|
1450
|
-
}
|
1451
|
-
| block_call tCOLON2 operation2 opt_paren_args
|
1452
|
-
{
|
1453
|
-
result = new_call val[0], val[2].to_sym, val[3]
|
1454
|
-
}
|
1455
|
-
|
1456
|
-
method_call: operation
|
1457
|
-
{
|
1458
|
-
result = self.lexer.lineno
|
1459
|
-
}
|
1460
|
-
paren_args
|
1461
|
-
{
|
1462
|
-
result = new_call nil, val[0].to_sym, val[2]
|
1463
|
-
}
|
1464
|
-
| primary_value tDOT operation2 opt_paren_args
|
1465
|
-
{
|
1466
|
-
result = new_call val[0], val[2].to_sym, val[3]
|
1467
|
-
}
|
1468
|
-
| primary_value tCOLON2 operation2 paren_args
|
1469
|
-
{
|
1470
|
-
result = new_call val[0], val[2].to_sym, val[3]
|
1471
|
-
}
|
1472
|
-
| primary_value tCOLON2 operation3
|
1473
|
-
{
|
1474
|
-
result = new_call val[0], val[2].to_sym
|
1475
|
-
}
|
1476
|
-
| primary_value tDOT paren_args
|
1477
|
-
{
|
1478
|
-
result = new_call val[0], :call, val[2]
|
1479
|
-
}
|
1480
|
-
| primary_value tCOLON2 paren_args
|
1481
|
-
{
|
1482
|
-
result = new_call val[0], :call, val[2]
|
1483
|
-
}
|
1484
|
-
| kSUPER paren_args
|
1485
|
-
{
|
1486
|
-
result = new_super val[1]
|
1487
|
-
}
|
1488
|
-
| kSUPER
|
1489
|
-
{
|
1490
|
-
result = s(:zsuper)
|
1491
|
-
}
|
1492
|
-
| primary_value tLBRACK2 opt_call_args rbracket
|
1493
|
-
{
|
1494
|
-
result = new_aref val
|
1495
|
-
}
|
1496
|
-
|
1497
|
-
brace_block: tLCURLY
|
1498
|
-
{
|
1499
|
-
self.env.extend :dynamic
|
1500
|
-
result = self.lexer.lineno
|
1501
|
-
}
|
1502
|
-
opt_block_param
|
1503
|
-
{
|
1504
|
-
result = nil # self.env.dynamic.keys
|
1505
|
-
}
|
1506
|
-
compstmt tRCURLY
|
1507
|
-
{
|
1508
|
-
_, line, args, _, body, _ = val
|
1509
|
-
|
1510
|
-
result = new_iter nil, args, body
|
1511
|
-
result.line = line
|
1512
|
-
|
1513
|
-
self.env.unextend
|
1514
|
-
}
|
1515
|
-
| kDO
|
1516
|
-
{
|
1517
|
-
self.env.extend :dynamic
|
1518
|
-
result = self.lexer.lineno
|
1519
|
-
}
|
1520
|
-
opt_block_param
|
1521
|
-
{
|
1522
|
-
result = nil # self.env.dynamic.keys
|
1523
|
-
}
|
1524
|
-
compstmt kEND
|
1525
|
-
{
|
1526
|
-
_, line, args, _, body, _ = val
|
1527
|
-
|
1528
|
-
result = new_iter nil, args, body
|
1529
|
-
result.line = line
|
1530
|
-
|
1531
|
-
self.env.unextend
|
1532
|
-
}
|
1533
|
-
|
1534
|
-
case_body: kWHEN
|
1535
|
-
{
|
1536
|
-
result = self.lexer.lineno
|
1537
|
-
}
|
1538
|
-
args then compstmt cases
|
1539
|
-
{
|
1540
|
-
result = new_when(val[2], val[4])
|
1541
|
-
result.line = val[1]
|
1542
|
-
result << val[5] if val[5]
|
1543
|
-
}
|
1544
|
-
|
1545
|
-
cases: opt_else | case_body
|
1546
|
-
|
1547
|
-
opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
|
1548
|
-
{
|
1549
|
-
(_, line), klasses, var, _, body, rest = val
|
1550
|
-
|
1551
|
-
klasses ||= s(:array)
|
1552
|
-
klasses << new_assign(var, s(:gvar, :"$!")) if var
|
1553
|
-
klasses.line line
|
1554
|
-
|
1555
|
-
result = new_resbody(klasses, body)
|
1556
|
-
result << rest if rest # UGH, rewritten above
|
1557
|
-
}
|
1558
|
-
|
|
1559
|
-
{
|
1560
|
-
result = nil
|
1561
|
-
}
|
1562
|
-
|
1563
|
-
exc_list: arg_value
|
1564
|
-
{
|
1565
|
-
result = s(:array, val[0])
|
1566
|
-
}
|
1567
|
-
| mrhs
|
1568
|
-
| none
|
1569
|
-
|
1570
|
-
exc_var: tASSOC lhs
|
1571
|
-
{
|
1572
|
-
result = val[1]
|
1573
|
-
}
|
1574
|
-
| none
|
1575
|
-
|
1576
|
-
opt_ensure: kENSURE compstmt
|
1577
|
-
{
|
1578
|
-
_, body = val
|
1579
|
-
|
1580
|
-
result = body || s(:nil)
|
1581
|
-
}
|
1582
|
-
| none
|
1583
|
-
|
1584
|
-
literal: numeric { result = s(:lit, val[0]) }
|
1585
|
-
| symbol { result = s(:lit, val[0]) }
|
1586
|
-
| dsym
|
1587
|
-
|
1588
|
-
strings: string
|
1589
|
-
{
|
1590
|
-
val[0] = s(:dstr, val[0].value) if val[0].sexp_type == :evstr
|
1591
|
-
result = val[0]
|
1592
|
-
}
|
1593
|
-
|
1594
|
-
string: string1
|
1595
|
-
| string string1
|
1596
|
-
{
|
1597
|
-
result = self.literal_concat val[0], val[1]
|
1598
|
-
}
|
1599
|
-
|
1600
|
-
string1: tSTRING_BEG string_contents tSTRING_END
|
1601
|
-
{
|
1602
|
-
result = val[1]
|
1603
|
-
}
|
1604
|
-
| tSTRING
|
1605
|
-
{
|
1606
|
-
result = new_string val
|
1607
|
-
}
|
1608
|
-
|
1609
|
-
xstring: tXSTRING_BEG xstring_contents tSTRING_END
|
1610
|
-
{
|
1611
|
-
result = new_xstring val[1]
|
1612
|
-
}
|
1613
|
-
|
1614
|
-
regexp: tREGEXP_BEG regexp_contents tREGEXP_END
|
1615
|
-
{
|
1616
|
-
result = new_regexp val
|
1617
|
-
}
|
1618
|
-
|
1619
|
-
words: tWORDS_BEG tSPACE tSTRING_END
|
1620
|
-
{
|
1621
|
-
result = s(:array)
|
1622
|
-
}
|
1623
|
-
| tWORDS_BEG word_list tSTRING_END
|
1624
|
-
{
|
1625
|
-
result = val[1]
|
1626
|
-
}
|
1627
|
-
|
1628
|
-
word_list: none
|
1629
|
-
{
|
1630
|
-
result = new_word_list
|
1631
|
-
}
|
1632
|
-
| word_list word tSPACE
|
1633
|
-
{
|
1634
|
-
result = val[0] << new_word_list_entry(val)
|
1635
|
-
}
|
1636
|
-
|
1637
|
-
word: string_content
|
1638
|
-
| word string_content
|
1639
|
-
{
|
1640
|
-
result = self.literal_concat val[0], val[1]
|
1641
|
-
}
|
1642
|
-
|
1643
|
-
qwords: tQWORDS_BEG tSPACE tSTRING_END
|
1644
|
-
{
|
1645
|
-
result = s(:array)
|
1646
|
-
}
|
1647
|
-
| tQWORDS_BEG qword_list tSTRING_END
|
1648
|
-
{
|
1649
|
-
result = val[1]
|
1650
|
-
}
|
1651
|
-
|
1652
|
-
qword_list: none
|
1653
|
-
{
|
1654
|
-
result = new_qword_list
|
1655
|
-
}
|
1656
|
-
| qword_list tSTRING_CONTENT tSPACE
|
1657
|
-
{
|
1658
|
-
result = val[0] << new_qword_list_entry(val)
|
1659
|
-
}
|
1660
|
-
|
1661
|
-
string_contents: none
|
1662
|
-
{
|
1663
|
-
result = s(:str, "")
|
1664
|
-
}
|
1665
|
-
| string_contents string_content
|
1666
|
-
{
|
1667
|
-
result = literal_concat(val[0], val[1])
|
1668
|
-
}
|
1669
|
-
|
1670
|
-
xstring_contents: none
|
1671
|
-
{
|
1672
|
-
result = nil
|
1673
|
-
}
|
1674
|
-
| xstring_contents string_content
|
1675
|
-
{
|
1676
|
-
result = literal_concat(val[0], val[1])
|
1677
|
-
}
|
1678
|
-
|
1679
|
-
regexp_contents: none
|
1680
|
-
{
|
1681
|
-
result = nil
|
1682
|
-
}
|
1683
|
-
| regexp_contents string_content
|
1684
|
-
{
|
1685
|
-
result = literal_concat(val[0], val[1])
|
1686
|
-
}
|
1687
|
-
|
1688
|
-
string_content: tSTRING_CONTENT
|
1689
|
-
{
|
1690
|
-
result = new_string val
|
1691
|
-
}
|
1692
|
-
| tSTRING_DVAR
|
1693
|
-
{
|
1694
|
-
result = lexer.lex_strterm
|
1695
|
-
|
1696
|
-
lexer.lex_strterm = nil
|
1697
|
-
lexer.lex_state = :expr_beg
|
1698
|
-
}
|
1699
|
-
string_dvar
|
1700
|
-
{
|
1701
|
-
lexer.lex_strterm = val[1]
|
1702
|
-
result = s(:evstr, val[2])
|
1703
|
-
}
|
1704
|
-
| tSTRING_DBEG
|
1705
|
-
{
|
1706
|
-
result = [lexer.lex_strterm,
|
1707
|
-
lexer.brace_nest,
|
1708
|
-
lexer.string_nest, # TODO: remove
|
1709
|
-
lexer.cond.store,
|
1710
|
-
lexer.cmdarg.store]
|
1711
|
-
|
1712
|
-
lexer.lex_strterm = nil
|
1713
|
-
lexer.brace_nest = 0
|
1714
|
-
lexer.string_nest = 0
|
1715
|
-
|
1716
|
-
lexer.lex_state = :expr_beg
|
1717
|
-
}
|
1718
|
-
compstmt tRCURLY
|
1719
|
-
{
|
1720
|
-
_, memo, stmt, _ = val
|
1721
|
-
|
1722
|
-
lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg = memo
|
1723
|
-
|
1724
|
-
lexer.lex_strterm = lex_strterm
|
1725
|
-
lexer.brace_nest = brace_nest
|
1726
|
-
lexer.string_nest = string_nest
|
1727
|
-
|
1728
|
-
lexer.cond.restore oldcond
|
1729
|
-
lexer.cmdarg.restore oldcmdarg
|
1730
|
-
|
1731
|
-
case stmt
|
1732
|
-
when Sexp then
|
1733
|
-
case stmt.sexp_type
|
1734
|
-
when :str, :dstr, :evstr then
|
1735
|
-
result = stmt
|
1736
|
-
else
|
1737
|
-
result = s(:evstr, stmt)
|
1738
|
-
end
|
1739
|
-
when nil then
|
1740
|
-
result = s(:evstr)
|
1741
|
-
else
|
1742
|
-
raise "unknown string body: #{stmt.inspect}"
|
1743
|
-
end
|
1744
|
-
}
|
1745
|
-
|
1746
|
-
string_dvar: tGVAR { result = s(:gvar, val[0].to_sym) }
|
1747
|
-
| tIVAR { result = s(:ivar, val[0].to_sym) }
|
1748
|
-
| tCVAR { result = s(:cvar, val[0].to_sym) }
|
1749
|
-
| backref
|
1750
|
-
|
1751
|
-
symbol: tSYMBEG sym
|
1752
|
-
{
|
1753
|
-
lexer.lex_state = :expr_end
|
1754
|
-
result = val[1].to_sym
|
1755
|
-
}
|
1756
|
-
| tSYMBOL
|
1757
|
-
{
|
1758
|
-
result = val[0].to_sym
|
1759
|
-
}
|
1760
|
-
|
1761
|
-
sym: fname | tIVAR | tGVAR | tCVAR
|
1762
|
-
|
1763
|
-
dsym: tSYMBEG xstring_contents tSTRING_END
|
1764
|
-
{
|
1765
|
-
lexer.lex_state = :expr_end
|
1766
|
-
result = val[1]
|
1767
|
-
|
1768
|
-
result ||= s(:str, "")
|
1769
|
-
|
1770
|
-
case result.sexp_type
|
1771
|
-
when :dstr then
|
1772
|
-
result.sexp_type = :dsym
|
1773
|
-
when :str then
|
1774
|
-
result = s(:lit, result.last.intern)
|
1775
|
-
else
|
1776
|
-
result = s(:dsym, "", result)
|
1777
|
-
end
|
1778
|
-
}
|
1779
|
-
|
1780
|
-
numeric: tINTEGER
|
1781
|
-
| tFLOAT
|
1782
|
-
| tUMINUS_NUM tINTEGER =tLOWEST
|
1783
|
-
{
|
1784
|
-
result = -val[1] # TODO: pt_testcase
|
1785
|
-
}
|
1786
|
-
| tUMINUS_NUM tFLOAT =tLOWEST
|
1787
|
-
{
|
1788
|
-
result = -val[1] # TODO: pt_testcase
|
1789
|
-
}
|
1790
|
-
|
1791
|
-
user_variable: tIDENTIFIER
|
1792
|
-
| tIVAR
|
1793
|
-
| tGVAR
|
1794
|
-
| tCONSTANT
|
1795
|
-
| tCVAR
|
1796
|
-
|
1797
|
-
keyword_variable: kNIL { result = s(:nil) }
|
1798
|
-
| kSELF { result = s(:self) }
|
1799
|
-
| kTRUE { result = s(:true) }
|
1800
|
-
| kFALSE { result = s(:false) }
|
1801
|
-
| k__FILE__ { result = s(:str, self.file) }
|
1802
|
-
| k__LINE__ { result = s(:lit, lexer.lineno) }
|
1803
|
-
| k__ENCODING__
|
1804
|
-
{
|
1805
|
-
result =
|
1806
|
-
if defined? Encoding then
|
1807
|
-
s(:colon2, s(:const, :Encoding), :UTF_8)
|
1808
|
-
else
|
1809
|
-
s(:str, "Unsupported!")
|
1810
|
-
end
|
1811
|
-
}
|
1812
|
-
|
1813
|
-
var_ref: user_variable
|
1814
|
-
{
|
1815
|
-
var = val[0]
|
1816
|
-
result = Sexp === var ? var : self.gettable(var)
|
1817
|
-
}
|
1818
|
-
| keyword_variable
|
1819
|
-
{
|
1820
|
-
var = val[0]
|
1821
|
-
result = Sexp === var ? var : self.gettable(var)
|
1822
|
-
}
|
1823
|
-
|
1824
|
-
var_lhs: user_variable
|
1825
|
-
{
|
1826
|
-
result = self.assignable val[0]
|
1827
|
-
}
|
1828
|
-
| keyword_variable
|
1829
|
-
{
|
1830
|
-
result = self.assignable val[0]
|
1831
|
-
}
|
1832
|
-
|
1833
|
-
backref: tNTH_REF { result = s(:nth_ref, val[0]) }
|
1834
|
-
| tBACK_REF { result = s(:back_ref, val[0]) }
|
1835
|
-
|
1836
|
-
superclass: term
|
1837
|
-
{
|
1838
|
-
result = nil
|
1839
|
-
}
|
1840
|
-
| tLT
|
1841
|
-
{
|
1842
|
-
lexer.lex_state = :expr_beg
|
1843
|
-
}
|
1844
|
-
expr_value term
|
1845
|
-
{
|
1846
|
-
result = val[2]
|
1847
|
-
}
|
1848
|
-
| error term
|
1849
|
-
{
|
1850
|
-
yyerrok
|
1851
|
-
result = nil
|
1852
|
-
}
|
1853
|
-
|
1854
|
-
f_arglist: tLPAREN2 f_args rparen
|
1855
|
-
{
|
1856
|
-
result = val[1]
|
1857
|
-
lexer.lex_state = :expr_beg
|
1858
|
-
self.lexer.command_start = true
|
1859
|
-
}
|
1860
|
-
| f_args term
|
1861
|
-
{
|
1862
|
-
result = val[0]
|
1863
|
-
}
|
1864
|
-
|
1865
|
-
f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_f_block_arg
|
1866
|
-
{
|
1867
|
-
result = args val
|
1868
|
-
}
|
1869
|
-
| f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
|
1870
|
-
{
|
1871
|
-
result = args val
|
1872
|
-
}
|
1873
|
-
| f_arg tCOMMA f_optarg opt_f_block_arg
|
1874
|
-
{
|
1875
|
-
result = args val
|
1876
|
-
}
|
1877
|
-
| f_arg tCOMMA f_optarg tCOMMA f_arg opt_f_block_arg
|
1878
|
-
{
|
1879
|
-
result = args val
|
1880
|
-
}
|
1881
|
-
| f_arg tCOMMA f_rest_arg opt_f_block_arg
|
1882
|
-
{
|
1883
|
-
result = args val
|
1884
|
-
}
|
1885
|
-
| f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
|
1886
|
-
{
|
1887
|
-
result = args val
|
1888
|
-
}
|
1889
|
-
| f_arg opt_f_block_arg
|
1890
|
-
{
|
1891
|
-
result = args val
|
1892
|
-
}
|
1893
|
-
| f_optarg tCOMMA f_rest_arg opt_f_block_arg
|
1894
|
-
{
|
1895
|
-
result = args val
|
1896
|
-
}
|
1897
|
-
| f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
|
1898
|
-
{
|
1899
|
-
result = args val
|
1900
|
-
}
|
1901
|
-
| f_optarg opt_f_block_arg
|
1902
|
-
{
|
1903
|
-
result = args val
|
1904
|
-
}
|
1905
|
-
| f_optarg tCOMMA f_arg opt_f_block_arg
|
1906
|
-
{
|
1907
|
-
result = args val
|
1908
|
-
}
|
1909
|
-
| f_rest_arg opt_f_block_arg
|
1910
|
-
{
|
1911
|
-
result = args val
|
1912
|
-
}
|
1913
|
-
| f_rest_arg tCOMMA f_arg opt_f_block_arg
|
1914
|
-
{
|
1915
|
-
result = args val
|
1916
|
-
}
|
1917
|
-
| f_block_arg
|
1918
|
-
{
|
1919
|
-
result = args val
|
1920
|
-
}
|
1921
|
-
|
|
1922
|
-
{
|
1923
|
-
result = args val
|
1924
|
-
}
|
1925
|
-
|
1926
|
-
f_bad_arg: tCONSTANT
|
1927
|
-
{
|
1928
|
-
yyerror "formal argument cannot be a constant"
|
1929
|
-
}
|
1930
|
-
| tIVAR
|
1931
|
-
{
|
1932
|
-
yyerror "formal argument cannot be an instance variable"
|
1933
|
-
}
|
1934
|
-
| tGVAR
|
1935
|
-
{
|
1936
|
-
yyerror "formal argument cannot be a global variable"
|
1937
|
-
}
|
1938
|
-
| tCVAR
|
1939
|
-
{
|
1940
|
-
yyerror "formal argument cannot be a class variable"
|
1941
|
-
}
|
1942
|
-
|
1943
|
-
f_norm_arg: f_bad_arg
|
1944
|
-
| tIDENTIFIER
|
1945
|
-
{
|
1946
|
-
identifier = val[0].to_sym
|
1947
|
-
self.env[identifier] = :lvar
|
1948
|
-
|
1949
|
-
result = identifier
|
1950
|
-
}
|
1951
|
-
|
1952
|
-
f_arg_item: f_norm_arg
|
1953
|
-
| tLPAREN f_margs rparen
|
1954
|
-
{
|
1955
|
-
result = val[1]
|
1956
|
-
}
|
1957
|
-
|
1958
|
-
f_arg: f_arg_item
|
1959
|
-
{
|
1960
|
-
case val[0]
|
1961
|
-
when Symbol then
|
1962
|
-
result = s(:args)
|
1963
|
-
result << val[0]
|
1964
|
-
when Sexp then
|
1965
|
-
result = val[0]
|
1966
|
-
else
|
1967
|
-
raise "Unknown f_arg type: #{val.inspect}"
|
1968
|
-
end
|
1969
|
-
}
|
1970
|
-
| f_arg tCOMMA f_arg_item
|
1971
|
-
{
|
1972
|
-
list, _, item = val
|
1973
|
-
|
1974
|
-
if list.sexp_type == :args then
|
1975
|
-
result = list
|
1976
|
-
else
|
1977
|
-
result = s(:args, list)
|
1978
|
-
end
|
1979
|
-
|
1980
|
-
result << item
|
1981
|
-
}
|
1982
|
-
|
1983
|
-
f_opt: tIDENTIFIER tEQL arg_value
|
1984
|
-
{
|
1985
|
-
result = self.assignable val[0], val[2]
|
1986
|
-
# TODO: detect duplicate names
|
1987
|
-
}
|
1988
|
-
|
1989
|
-
f_block_opt: tIDENTIFIER tEQL primary_value
|
1990
|
-
{
|
1991
|
-
result = self.assignable val[0], val[2]
|
1992
|
-
}
|
1993
|
-
|
1994
|
-
f_block_optarg: f_block_opt
|
1995
|
-
{
|
1996
|
-
result = s(:block, val[0])
|
1997
|
-
}
|
1998
|
-
| f_block_optarg tCOMMA f_block_opt
|
1999
|
-
{
|
2000
|
-
result = val[0]
|
2001
|
-
result << val[2]
|
2002
|
-
}
|
2003
|
-
|
2004
|
-
f_optarg: f_opt
|
2005
|
-
{
|
2006
|
-
result = s(:block, val[0])
|
2007
|
-
}
|
2008
|
-
| f_optarg tCOMMA f_opt
|
2009
|
-
{
|
2010
|
-
result = self.block_append val[0], val[2]
|
2011
|
-
}
|
2012
|
-
|
2013
|
-
restarg_mark: tSTAR2 | tSTAR
|
2014
|
-
|
2015
|
-
f_rest_arg: restarg_mark tIDENTIFIER
|
2016
|
-
{
|
2017
|
-
# TODO: differs from parse.y - needs tests
|
2018
|
-
name = val[1].to_sym
|
2019
|
-
self.assignable name
|
2020
|
-
result = :"*#{name}"
|
2021
|
-
}
|
2022
|
-
| restarg_mark
|
2023
|
-
{
|
2024
|
-
name = :"*"
|
2025
|
-
self.env[name] = :lvar
|
2026
|
-
result = name
|
2027
|
-
}
|
2028
|
-
|
2029
|
-
blkarg_mark: tAMPER2 | tAMPER
|
2030
|
-
|
2031
|
-
f_block_arg: blkarg_mark tIDENTIFIER
|
2032
|
-
{
|
2033
|
-
identifier = val[1].to_sym
|
2034
|
-
|
2035
|
-
self.env[identifier] = :lvar
|
2036
|
-
result = "&#{identifier}".to_sym
|
2037
|
-
}
|
2038
|
-
|
2039
|
-
opt_f_block_arg: tCOMMA f_block_arg
|
2040
|
-
{
|
2041
|
-
result = val[1]
|
2042
|
-
}
|
2043
|
-
|
|
2044
|
-
{
|
2045
|
-
result = nil
|
2046
|
-
}
|
2047
|
-
|
2048
|
-
singleton: var_ref
|
2049
|
-
| tLPAREN2
|
2050
|
-
{
|
2051
|
-
lexer.lex_state = :expr_beg
|
2052
|
-
}
|
2053
|
-
expr rparen
|
2054
|
-
{
|
2055
|
-
result = val[2]
|
2056
|
-
yyerror "Can't define single method for literals." if
|
2057
|
-
result.sexp_type == :lit
|
2058
|
-
}
|
2059
|
-
|
2060
|
-
assoc_list: none # [!nil]
|
2061
|
-
{
|
2062
|
-
result = s(:array)
|
2063
|
-
}
|
2064
|
-
| assocs trailer # [!nil]
|
2065
|
-
{
|
2066
|
-
result = val[0]
|
2067
|
-
}
|
2068
|
-
|
2069
|
-
assocs: assoc
|
2070
|
-
| assocs tCOMMA assoc
|
2071
|
-
{
|
2072
|
-
list = val[0].dup
|
2073
|
-
more = val[2].sexp_body
|
2074
|
-
list.push(*more) unless more.empty?
|
2075
|
-
result = list
|
2076
|
-
}
|
2077
|
-
|
2078
|
-
assoc: arg_value tASSOC arg_value
|
2079
|
-
{
|
2080
|
-
result = s(:array, val[0], val[2])
|
2081
|
-
}
|
2082
|
-
| tLABEL opt_nl arg_value
|
2083
|
-
{
|
2084
|
-
label, _ = val[0] # TODO: fix lineno?
|
2085
|
-
result = s(:array, s(:lit, label.to_sym), val.last)
|
2086
|
-
}
|
2087
|
-
|
2088
|
-
operation: tIDENTIFIER | tCONSTANT | tFID
|
2089
|
-
operation2: tIDENTIFIER | tCONSTANT | tFID | op
|
2090
|
-
operation3: tIDENTIFIER | tFID | op
|
2091
|
-
dot_or_colon: tDOT | tCOLON2
|
2092
|
-
opt_terms: | terms
|
2093
|
-
opt_nl: | tNL
|
2094
|
-
rparen: opt_nl tRPAREN
|
2095
|
-
rbracket: opt_nl tRBRACK
|
2096
|
-
trailer: | tNL | tCOMMA
|
2097
|
-
|
2098
|
-
term: tSEMI { yyerrok }
|
2099
|
-
| tNL
|
2100
|
-
|
2101
|
-
terms: term
|
2102
|
-
| terms tSEMI { yyerrok }
|
2103
|
-
|
2104
|
-
none: { result = nil }
|
2105
|
-
end
|
2106
|
-
|
2107
|
-
---- inner
|
2108
|
-
|
2109
|
-
require "ruby_lexer"
|
2110
|
-
require "ruby_parser_extras"
|
2111
|
-
|
2112
|
-
# :stopdoc:
|
2113
|
-
|
2114
|
-
# Local Variables: **
|
2115
|
-
# racc-token-length-max:14 **
|
2116
|
-
# End: **
|