parser 2.1.9 → 2.2.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,8 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in parser.gemspec
4
4
  gemspec
5
-
6
- platforms :rbx do
7
- gem 'rubysl', '~> 2.0'
8
- gem 'rubinius', '~> 2.0'
9
- end
data/README.md CHANGED
@@ -96,7 +96,7 @@ with Parser:
96
96
  * Precise source location reporting.
97
97
  * [Documented](doc/AST_FORMAT.md) AST format which is convenient to work with.
98
98
  * A simple interface and a powerful, tweakable one.
99
- * Parses 1.8, 1.9, 2.0 and 2.1 (preliminary) syntax with backwards-compatible
99
+ * Parses 1.8, 1.9, 2.0, 2.1 and 2.2 (preliminary) syntax with backwards-compatible
100
100
  AST formats.
101
101
  * [Rewriting][rewriting] support.
102
102
  * Parsing error recovery.
data/Rakefile CHANGED
@@ -22,7 +22,8 @@ GENERATED_FILES = %w(lib/parser/lexer.rb
22
22
  lib/parser/ruby18.rb
23
23
  lib/parser/ruby19.rb
24
24
  lib/parser/ruby20.rb
25
- lib/parser/ruby21.rb)
25
+ lib/parser/ruby21.rb
26
+ lib/parser/ruby22.rb)
26
27
 
27
28
  CLEAN.include(GENERATED_FILES)
28
29
 
@@ -58,6 +59,16 @@ task :yard => :generate do
58
59
  sh('yard doc')
59
60
  end
60
61
 
62
+ PAGES_REPO = 'git@github.com:whitequark/parser'
63
+
64
+ desc "Build and deploy documentation to GitHub pages"
65
+ task :pages do
66
+ system "git clone #{PAGES_REPO} gh-temp/ -b gh-pages; rm gh-temp/* -rf; touch gh-temp/.nojekyll" or abort
67
+ system "yardoc -o gh-temp/;" or abort
68
+ system "cd gh-temp/; git add -A; git commit -m 'Updated pages.'; git push -f origin gh-pages" or abort
69
+ FileUtils.rm_rf 'gh-temp'
70
+ end
71
+
61
72
  desc 'Generate Changelog'
62
73
  task :changelog do
63
74
  fs = "\u{fffd}"
@@ -70,7 +81,7 @@ task :changelog do
70
81
  end
71
82
  end
72
83
 
73
- IO.popen("git log --pretty='#{format}' 2.0 2.1 master", 'r') do |io|
84
+ IO.popen("git log --pretty='#{format}' remotes/origin/2.0 remotes/origin/2.1 master", 'r') do |io|
74
85
  current_version = nil
75
86
 
76
87
  io.each_line do |line|
@@ -327,9 +327,9 @@ Format:
327
327
  Format:
328
328
 
329
329
  ~~~
330
- (cvar :$foo)
331
- "$foo"
332
- ~~~~ expression
330
+ (cvar :@@foo)
331
+ "@@foo"
332
+ ~~~~~ expression
333
333
  ~~~
334
334
 
335
335
  ### Global variable
@@ -50,6 +50,7 @@ module Parser
50
50
  end
51
51
 
52
52
  require 'parser/syntax_error'
53
+ require 'parser/clobbering_error'
53
54
  require 'parser/diagnostic'
54
55
  require 'parser/diagnostic/engine'
55
56
 
@@ -1,3 +1,4 @@
1
1
  require 'parser/ruby18'
2
2
  require 'parser/ruby19'
3
3
  require 'parser/ruby20'
4
+ require 'parser/ruby21'
@@ -0,0 +1,11 @@
1
+ module Parser
2
+ ##
3
+ # {Parser::ClobberingError} is raised when {Parser::Source::Rewriter}
4
+ # detects a clobbering rewrite action. This class inherits {RuntimeError}
5
+ # rather than {StandardError} for backward compatibility.
6
+ #
7
+ # @api public
8
+ #
9
+ class ClobberingError < RuntimeError
10
+ end
11
+ end
@@ -32,9 +32,14 @@ module Parser
32
32
  require 'parser/ruby21'
33
33
  CurrentRuby = Ruby21
34
34
 
35
+ when /^2\.2\./
36
+ require 'parser/ruby22'
37
+ CurrentRuby = Ruby22
38
+
35
39
  else # :nocov:
36
40
  # Keep this in sync with released Ruby.
37
41
  warn_syntax_deviation 'parser/ruby21', '2.1'
42
+ require 'parser/ruby21'
38
43
  CurrentRuby = Ruby21
39
44
  end
40
45
  end
@@ -116,8 +116,11 @@ class Parser::Lexer
116
116
 
117
117
  @cond = StackState.new('cond')
118
118
  @cmdarg = StackState.new('cmdarg')
119
+ @cmdarg_stack = []
119
120
  end
120
121
 
122
+ @force_utf32 = false # Set to true by some tests
123
+
121
124
  @source = nil # source string
122
125
  @source_pts = nil # @source as a codepoint array
123
126
  @encoding = nil # target encoding for output strings
@@ -237,6 +240,15 @@ class Parser::Lexer
237
240
  @cs = LEX_STATES.fetch(state)
238
241
  end
239
242
 
243
+ def push_cmdarg
244
+ @cmdarg_stack.push(@cmdarg)
245
+ @cmdarg = StackState.new("cmdarg.#{@cmdarg_stack.count}")
246
+ end
247
+
248
+ def pop_cmdarg
249
+ @cmdarg = @cmdarg_stack.pop
250
+ end
251
+
240
252
  # Return next token: [type, value].
241
253
  def advance
242
254
  if @token_queue.any?
@@ -0,0 +1,2327 @@
1
+ class Parser::Ruby22
2
+
3
+ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
4
+ kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
5
+ kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kDO_LAMBDA kRETURN kYIELD kSUPER
6
+ kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
7
+ kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
8
+ k__FILE__ k__ENCODING__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT
9
+ tLABEL tCVAR tNTH_REF tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT
10
+ tREGEXP_END tUPLUS tUMINUS tUMINUS_NUM tPOW tCMP tEQ tEQQ tNEQ
11
+ tGEQ tLEQ tANDOP tOROP tMATCH tNMATCH tDOT tDOT2 tDOT3 tAREF
12
+ tASET tLSHFT tRSHFT tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN
13
+ tLPAREN2 tRPAREN tLPAREN_ARG tLBRACK tLBRACK2 tRBRACK tLBRACE
14
+ tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2 tTILDE tPERCENT tDIVIDE
15
+ tDSTAR tPLUS tMINUS tLT tGT tPIPE tBANG tCARET tLCURLY tRCURLY
16
+ tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tREGEXP_OPT
17
+ tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DBEG
18
+ tSTRING_DVAR tSTRING_END tSTRING_DEND tSTRING tSYMBOL
19
+ tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA tLAMBEG tCHARACTER
20
+ tRATIONAL tIMAGINARY
21
+
22
+ prechigh
23
+ right tBANG tTILDE tUPLUS
24
+ right tPOW
25
+ right tUMINUS_NUM tUMINUS
26
+ left tSTAR2 tDIVIDE tPERCENT
27
+ left tPLUS tMINUS
28
+ left tLSHFT tRSHFT
29
+ left tAMPER2
30
+ left tPIPE tCARET
31
+ left tGT tGEQ tLT tLEQ
32
+ nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
33
+ left tANDOP
34
+ left tOROP
35
+ nonassoc tDOT2 tDOT3
36
+ right tEH tCOLON
37
+ left kRESCUE_MOD
38
+ right tEQL tOP_ASGN
39
+ nonassoc kDEFINED
40
+ right kNOT
41
+ left kOR kAND
42
+ nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
43
+ nonassoc tLBRACE_ARG
44
+ nonassoc tLOWEST
45
+ preclow
46
+
47
+ rule
48
+
49
+ program: top_compstmt
50
+
51
+ top_compstmt: top_stmts opt_terms
52
+ {
53
+ result = @builder.compstmt(val[0])
54
+ }
55
+
56
+ top_stmts: # nothing
57
+ {
58
+ result = []
59
+ }
60
+ | top_stmt
61
+ {
62
+ result = [ val[0] ]
63
+ }
64
+ | top_stmts terms top_stmt
65
+ {
66
+ result = val[0] << val[2]
67
+ }
68
+ | error top_stmt
69
+ {
70
+ result = [ val[1] ]
71
+ }
72
+
73
+ top_stmt: stmt
74
+ | klBEGIN tLCURLY top_compstmt tRCURLY
75
+ {
76
+ result = @builder.preexe(val[0], val[1], val[2], val[3])
77
+ }
78
+
79
+ bodystmt: compstmt opt_rescue opt_else opt_ensure
80
+ {
81
+ rescue_bodies = val[1]
82
+ else_t, else_ = val[2]
83
+ ensure_t, ensure_ = val[3]
84
+
85
+ if rescue_bodies.empty? && !else_.nil?
86
+ diagnostic :warning, :useless_else, nil, else_t
87
+ end
88
+
89
+ result = @builder.begin_body(val[0],
90
+ rescue_bodies,
91
+ else_t, else_,
92
+ ensure_t, ensure_)
93
+ }
94
+
95
+ compstmt: stmts opt_terms
96
+ {
97
+ result = @builder.compstmt(val[0])
98
+ }
99
+
100
+ stmts: # nothing
101
+ {
102
+ result = []
103
+ }
104
+ | stmt_or_begin
105
+ {
106
+ result = [ val[0] ]
107
+ }
108
+ | stmts terms stmt_or_begin
109
+ {
110
+ result = val[0] << val[2]
111
+ }
112
+ | error stmt
113
+ {
114
+ result = [ val[1] ]
115
+ }
116
+
117
+ stmt_or_begin: stmt
118
+ | klBEGIN tLCURLY top_compstmt tRCURLY
119
+ {
120
+ diagnostic :error, :begin_in_method, nil, val[0]
121
+ }
122
+
123
+ stmt: kALIAS fitem
124
+ {
125
+ @lexer.state = :expr_fname
126
+ }
127
+ fitem
128
+ {
129
+ result = @builder.alias(val[0], val[1], val[3])
130
+ }
131
+ | kALIAS tGVAR tGVAR
132
+ {
133
+ result = @builder.alias(val[0],
134
+ @builder.gvar(val[1]),
135
+ @builder.gvar(val[2]))
136
+ }
137
+ | kALIAS tGVAR tBACK_REF
138
+ {
139
+ result = @builder.alias(val[0],
140
+ @builder.gvar(val[1]),
141
+ @builder.back_ref(val[2]))
142
+ }
143
+ | kALIAS tGVAR tNTH_REF
144
+ {
145
+ diagnostic :error, :nth_ref_alias, nil, val[2]
146
+ }
147
+ | kUNDEF undef_list
148
+ {
149
+ result = @builder.undef_method(val[0], val[1])
150
+ }
151
+ | stmt kIF_MOD expr_value
152
+ {
153
+ result = @builder.condition_mod(val[0], nil,
154
+ val[1], val[2])
155
+ }
156
+ | stmt kUNLESS_MOD expr_value
157
+ {
158
+ result = @builder.condition_mod(nil, val[0],
159
+ val[1], val[2])
160
+ }
161
+ | stmt kWHILE_MOD expr_value
162
+ {
163
+ result = @builder.loop_mod(:while, val[0], val[1], val[2])
164
+ }
165
+ | stmt kUNTIL_MOD expr_value
166
+ {
167
+ result = @builder.loop_mod(:until, val[0], val[1], val[2])
168
+ }
169
+ | stmt kRESCUE_MOD stmt
170
+ {
171
+ rescue_body = @builder.rescue_body(val[1],
172
+ nil, nil, nil,
173
+ nil, val[2])
174
+
175
+ result = @builder.begin_body(val[0], [ rescue_body ])
176
+ }
177
+ | klEND tLCURLY compstmt tRCURLY
178
+ {
179
+ result = @builder.postexe(val[0], val[1], val[2], val[3])
180
+ }
181
+ | command_asgn
182
+ | mlhs tEQL command_call
183
+ {
184
+ result = @builder.multi_assign(val[0], val[1], val[2])
185
+ }
186
+ | var_lhs tOP_ASGN command_call
187
+ {
188
+ result = @builder.op_assign(val[0], val[1], val[2])
189
+ }
190
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_call
191
+ {
192
+ result = @builder.op_assign(
193
+ @builder.index(
194
+ val[0], val[1], val[2], val[3]),
195
+ val[4], val[5])
196
+ }
197
+ | primary_value tDOT tIDENTIFIER tOP_ASGN command_call
198
+ {
199
+ result = @builder.op_assign(
200
+ @builder.call_method(
201
+ val[0], val[1], val[2]),
202
+ val[3], val[4])
203
+ }
204
+ | primary_value tDOT tCONSTANT tOP_ASGN command_call
205
+ {
206
+ result = @builder.op_assign(
207
+ @builder.call_method(
208
+ val[0], val[1], val[2]),
209
+ val[3], val[4])
210
+ }
211
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
212
+ {
213
+ result = @builder.op_assign(
214
+ @builder.call_method(
215
+ val[0], val[1], val[2]),
216
+ val[3], val[4])
217
+ }
218
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
219
+ {
220
+ result = @builder.op_assign(
221
+ @builder.call_method(
222
+ val[0], val[1], val[2]),
223
+ val[3], val[4])
224
+ }
225
+ | backref tOP_ASGN command_call
226
+ {
227
+ @builder.op_assign(val[0], val[1], val[2])
228
+ }
229
+ | lhs tEQL mrhs
230
+ {
231
+ result = @builder.assign(val[0], val[1],
232
+ @builder.array(nil, val[2], nil))
233
+ }
234
+ | mlhs tEQL mrhs_arg
235
+ {
236
+ result = @builder.multi_assign(val[0], val[1], val[2])
237
+ }
238
+ | expr
239
+
240
+ command_asgn: lhs tEQL command_call
241
+ {
242
+ result = @builder.assign(val[0], val[1], val[2])
243
+ }
244
+ | lhs tEQL command_asgn
245
+ {
246
+ result = @builder.assign(val[0], val[1], val[2])
247
+ }
248
+
249
+ expr: command_call
250
+ | expr kAND expr
251
+ {
252
+ result = @builder.logical_op(:and, val[0], val[1], val[2])
253
+ }
254
+ | expr kOR expr
255
+ {
256
+ result = @builder.logical_op(:or, val[0], val[1], val[2])
257
+ }
258
+ | kNOT opt_nl expr
259
+ {
260
+ result = @builder.not_op(val[0], nil, val[2], nil)
261
+ }
262
+ | tBANG command_call
263
+ {
264
+ result = @builder.not_op(val[0], nil, val[1], nil)
265
+ }
266
+ | arg
267
+
268
+ expr_value: expr
269
+
270
+ command_call: command
271
+ | block_command
272
+
273
+ block_command: block_call
274
+ | block_call dot_or_colon operation2 command_args
275
+ {
276
+ result = @builder.call_method(val[0], val[1], val[2],
277
+ nil, val[3], nil)
278
+ }
279
+
280
+ cmd_brace_block: tLBRACE_ARG
281
+ {
282
+ @static_env.extend_dynamic
283
+ }
284
+ opt_block_param compstmt tRCURLY
285
+ {
286
+ result = [ val[0], val[2], val[3], val[4] ]
287
+
288
+ @static_env.unextend
289
+ }
290
+
291
+ fcall: operation
292
+
293
+ command: fcall command_args =tLOWEST
294
+ {
295
+ result = @builder.call_method(nil, nil, val[0],
296
+ nil, val[1], nil)
297
+ }
298
+ | fcall command_args cmd_brace_block
299
+ {
300
+ method_call = @builder.call_method(nil, nil, val[0],
301
+ nil, val[1], nil)
302
+
303
+ begin_t, args, body, end_t = val[2]
304
+ result = @builder.block(method_call,
305
+ begin_t, args, body, end_t)
306
+ }
307
+ | primary_value tDOT operation2 command_args =tLOWEST
308
+ {
309
+ result = @builder.call_method(val[0], val[1], val[2],
310
+ nil, val[3], nil)
311
+ }
312
+ | primary_value tDOT operation2 command_args cmd_brace_block
313
+ {
314
+ method_call = @builder.call_method(val[0], val[1], val[2],
315
+ nil, val[3], nil)
316
+
317
+ begin_t, args, body, end_t = val[4]
318
+ result = @builder.block(method_call,
319
+ begin_t, args, body, end_t)
320
+ }
321
+ | primary_value tCOLON2 operation2 command_args =tLOWEST
322
+ {
323
+ result = @builder.call_method(val[0], val[1], val[2],
324
+ nil, val[3], nil)
325
+ }
326
+ | primary_value tCOLON2 operation2 command_args cmd_brace_block
327
+ {
328
+ method_call = @builder.call_method(val[0], val[1], val[2],
329
+ nil, val[3], nil)
330
+
331
+ begin_t, args, body, end_t = val[4]
332
+ result = @builder.block(method_call,
333
+ begin_t, args, body, end_t)
334
+ }
335
+ | kSUPER command_args
336
+ {
337
+ result = @builder.keyword_cmd(:super, val[0],
338
+ nil, val[1], nil)
339
+ }
340
+ | kYIELD command_args
341
+ {
342
+ result = @builder.keyword_cmd(:yield, val[0],
343
+ nil, val[1], nil)
344
+ }
345
+ | kRETURN call_args
346
+ {
347
+ result = @builder.keyword_cmd(:return, val[0],
348
+ nil, val[1], nil)
349
+ }
350
+ | kBREAK call_args
351
+ {
352
+ result = @builder.keyword_cmd(:break, val[0],
353
+ nil, val[1], nil)
354
+ }
355
+ | kNEXT call_args
356
+ {
357
+ result = @builder.keyword_cmd(:next, val[0],
358
+ nil, val[1], nil)
359
+ }
360
+
361
+ mlhs: mlhs_basic
362
+ {
363
+ result = @builder.multi_lhs(nil, val[0], nil)
364
+ }
365
+ | tLPAREN mlhs_inner rparen
366
+ {
367
+ result = @builder.begin(val[0], val[1], val[2])
368
+ }
369
+
370
+ mlhs_inner: mlhs_basic
371
+ {
372
+ result = @builder.multi_lhs(nil, val[0], nil)
373
+ }
374
+ | tLPAREN mlhs_inner rparen
375
+ {
376
+ result = @builder.multi_lhs(val[0], val[1], val[2])
377
+ }
378
+
379
+ mlhs_basic: mlhs_head
380
+ | mlhs_head mlhs_item
381
+ {
382
+ result = val[0].
383
+ push(val[1])
384
+ }
385
+ | mlhs_head tSTAR mlhs_node
386
+ {
387
+ result = val[0].
388
+ push(@builder.splat(val[1], val[2]))
389
+ }
390
+ | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
391
+ {
392
+ result = val[0].
393
+ push(@builder.splat(val[1], val[2])).
394
+ concat(val[4])
395
+ }
396
+ | mlhs_head tSTAR
397
+ {
398
+ result = val[0].
399
+ push(@builder.splat(val[1]))
400
+ }
401
+ | mlhs_head tSTAR tCOMMA mlhs_post
402
+ {
403
+ result = val[0].
404
+ push(@builder.splat(val[1])).
405
+ concat(val[3])
406
+ }
407
+ | tSTAR mlhs_node
408
+ {
409
+ result = [ @builder.splat(val[0], val[1]) ]
410
+ }
411
+ | tSTAR mlhs_node tCOMMA mlhs_post
412
+ {
413
+ result = [ @builder.splat(val[0], val[1]),
414
+ *val[3] ]
415
+ }
416
+ | tSTAR
417
+ {
418
+ result = [ @builder.splat(val[0]) ]
419
+ }
420
+ | tSTAR tCOMMA mlhs_post
421
+ {
422
+ result = [ @builder.splat(val[0]),
423
+ *val[2] ]
424
+ }
425
+
426
+ mlhs_item: mlhs_node
427
+ | tLPAREN mlhs_inner rparen
428
+ {
429
+ result = @builder.begin(val[0], val[1], val[2])
430
+ }
431
+
432
+ mlhs_head: mlhs_item tCOMMA
433
+ {
434
+ result = [ val[0] ]
435
+ }
436
+ | mlhs_head mlhs_item tCOMMA
437
+ {
438
+ result = val[0] << val[1]
439
+ }
440
+
441
+ mlhs_post: mlhs_item
442
+ {
443
+ result = [ val[0] ]
444
+ }
445
+ | mlhs_post tCOMMA mlhs_item
446
+ {
447
+ result = val[0] << val[2]
448
+ }
449
+
450
+ mlhs_node: user_variable
451
+ {
452
+ result = @builder.assignable(val[0])
453
+ }
454
+ | keyword_variable
455
+ {
456
+ result = @builder.assignable(val[0])
457
+ }
458
+ | primary_value tLBRACK2 opt_call_args rbracket
459
+ {
460
+ result = @builder.index_asgn(val[0], val[1], val[2], val[3])
461
+ }
462
+ | primary_value tDOT tIDENTIFIER
463
+ {
464
+ result = @builder.attr_asgn(val[0], val[1], val[2])
465
+ }
466
+ | primary_value tCOLON2 tIDENTIFIER
467
+ {
468
+ result = @builder.attr_asgn(val[0], val[1], val[2])
469
+ }
470
+ | primary_value tDOT tCONSTANT
471
+ {
472
+ result = @builder.attr_asgn(val[0], val[1], val[2])
473
+ }
474
+ | primary_value tCOLON2 tCONSTANT
475
+ {
476
+ result = @builder.assignable(
477
+ @builder.const_fetch(val[0], val[1], val[2]))
478
+ }
479
+ | tCOLON3 tCONSTANT
480
+ {
481
+ result = @builder.assignable(
482
+ @builder.const_global(val[0], val[1]))
483
+ }
484
+ | backref
485
+ {
486
+ result = @builder.assignable(val[0])
487
+ }
488
+
489
+ lhs: user_variable
490
+ {
491
+ result = @builder.assignable(val[0])
492
+ }
493
+ | keyword_variable
494
+ {
495
+ result = @builder.assignable(val[0])
496
+ }
497
+ | primary_value tLBRACK2 opt_call_args rbracket
498
+ {
499
+ result = @builder.index_asgn(val[0], val[1], val[2], val[3])
500
+ }
501
+ | primary_value tDOT tIDENTIFIER
502
+ {
503
+ result = @builder.attr_asgn(val[0], val[1], val[2])
504
+ }
505
+ | primary_value tCOLON2 tIDENTIFIER
506
+ {
507
+ result = @builder.attr_asgn(val[0], val[1], val[2])
508
+ }
509
+ | primary_value tDOT tCONSTANT
510
+ {
511
+ result = @builder.attr_asgn(val[0], val[1], val[2])
512
+ }
513
+ | primary_value tCOLON2 tCONSTANT
514
+ {
515
+ result = @builder.assignable(
516
+ @builder.const_fetch(val[0], val[1], val[2]))
517
+ }
518
+ | tCOLON3 tCONSTANT
519
+ {
520
+ result = @builder.assignable(
521
+ @builder.const_global(val[0], val[1]))
522
+ }
523
+ | backref
524
+ {
525
+ result = @builder.assignable(val[0])
526
+ }
527
+
528
+ cname: tIDENTIFIER
529
+ {
530
+ diagnostic :error, :module_name_const, nil, val[0]
531
+ }
532
+ | tCONSTANT
533
+
534
+ cpath: tCOLON3 cname
535
+ {
536
+ result = @builder.const_global(val[0], val[1])
537
+ }
538
+ | cname
539
+ {
540
+ result = @builder.const(val[0])
541
+ }
542
+ | primary_value tCOLON2 cname
543
+ {
544
+ result = @builder.const_fetch(val[0], val[1], val[2])
545
+ }
546
+
547
+ fname: tIDENTIFIER | tCONSTANT | tFID
548
+ | op
549
+ | reswords
550
+
551
+ fsym: fname
552
+ {
553
+ result = @builder.symbol(val[0])
554
+ }
555
+ | symbol
556
+
557
+ fitem: fsym
558
+ | dsym
559
+
560
+ undef_list: fitem
561
+ {
562
+ result = [ val[0] ]
563
+ }
564
+ | undef_list tCOMMA
565
+ {
566
+ @lexer.state = :expr_fname
567
+ }
568
+ fitem
569
+ {
570
+ result = val[0] << val[3]
571
+ }
572
+
573
+ op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
574
+ | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
575
+ | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
576
+ | tSTAR | tDIVIDE | tPERCENT | tPOW | tBANG | tTILDE
577
+ | tUPLUS | tUMINUS | tAREF | tASET | tDSTAR | tBACK_REF2
578
+
579
+ reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
580
+ | kALIAS | kAND | kBEGIN | kBREAK | kCASE
581
+ | kCLASS | kDEF | kDEFINED | kDO | kELSE
582
+ | kELSIF | kEND | kENSURE | kFALSE | kFOR
583
+ | kIN | kMODULE | kNEXT | kNIL | kNOT
584
+ | kOR | kREDO | kRESCUE | kRETRY | kRETURN
585
+ | kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
586
+ | kWHEN | kYIELD | kIF | kUNLESS | kWHILE
587
+ | kUNTIL
588
+
589
+ arg: lhs tEQL arg
590
+ {
591
+ result = @builder.assign(val[0], val[1], val[2])
592
+ }
593
+ | lhs tEQL arg kRESCUE_MOD arg
594
+ {
595
+ rescue_body = @builder.rescue_body(val[3],
596
+ nil, nil, nil,
597
+ nil, val[4])
598
+
599
+ rescue_ = @builder.begin_body(val[2], [ rescue_body ])
600
+
601
+ result = @builder.assign(val[0], val[1], rescue_)
602
+ }
603
+ | var_lhs tOP_ASGN arg
604
+ {
605
+ result = @builder.op_assign(val[0], val[1], val[2])
606
+ }
607
+ | var_lhs tOP_ASGN arg kRESCUE_MOD arg
608
+ {
609
+ rescue_body = @builder.rescue_body(val[3],
610
+ nil, nil, nil,
611
+ nil, val[4])
612
+
613
+ rescue_ = @builder.begin_body(val[2], [ rescue_body ])
614
+
615
+ result = @builder.op_assign(val[0], val[1], rescue_)
616
+ }
617
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
618
+ {
619
+ result = @builder.op_assign(
620
+ @builder.index(
621
+ val[0], val[1], val[2], val[3]),
622
+ val[4], val[5])
623
+ }
624
+ | primary_value tDOT tIDENTIFIER tOP_ASGN arg
625
+ {
626
+ result = @builder.op_assign(
627
+ @builder.call_method(
628
+ val[0], val[1], val[2]),
629
+ val[3], val[4])
630
+ }
631
+ | primary_value tDOT tCONSTANT tOP_ASGN arg
632
+ {
633
+ result = @builder.op_assign(
634
+ @builder.call_method(
635
+ val[0], val[1], val[2]),
636
+ val[3], val[4])
637
+ }
638
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
639
+ {
640
+ result = @builder.op_assign(
641
+ @builder.call_method(
642
+ val[0], val[1], val[2]),
643
+ val[3], val[4])
644
+ }
645
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
646
+ {
647
+ const = @builder.const_op_assignable(
648
+ @builder.const_fetch(val[0], val[1], val[2]))
649
+ result = @builder.op_assign(const, val[3], val[4])
650
+ }
651
+ | tCOLON3 tCONSTANT tOP_ASGN arg
652
+ {
653
+ const = @builder.const_op_assignable(
654
+ @builder.const_global(val[0], val[1]))
655
+ result = @builder.op_assign(const, val[2], val[3])
656
+ }
657
+ | backref tOP_ASGN arg
658
+ {
659
+ result = @builder.op_assign(val[0], val[1], val[2])
660
+ }
661
+ | arg tDOT2 arg
662
+ {
663
+ result = @builder.range_inclusive(val[0], val[1], val[2])
664
+ }
665
+ | arg tDOT3 arg
666
+ {
667
+ result = @builder.range_exclusive(val[0], val[1], val[2])
668
+ }
669
+ | arg tPLUS arg
670
+ {
671
+ result = @builder.binary_op(val[0], val[1], val[2])
672
+ }
673
+ | arg tMINUS arg
674
+ {
675
+ result = @builder.binary_op(val[0], val[1], val[2])
676
+ }
677
+ | arg tSTAR2 arg
678
+ {
679
+ result = @builder.binary_op(val[0], val[1], val[2])
680
+ }
681
+ | arg tDIVIDE arg
682
+ {
683
+ result = @builder.binary_op(val[0], val[1], val[2])
684
+ }
685
+ | arg tPERCENT arg
686
+ {
687
+ result = @builder.binary_op(val[0], val[1], val[2])
688
+ }
689
+ | arg tPOW arg
690
+ {
691
+ result = @builder.binary_op(val[0], val[1], val[2])
692
+ }
693
+ | tUMINUS_NUM simple_numeric tPOW arg
694
+ {
695
+ result = @builder.unary_op(val[0],
696
+ @builder.binary_op(
697
+ val[1], val[2], val[3]))
698
+ }
699
+ | tUPLUS arg
700
+ {
701
+ result = @builder.unary_op(val[0], val[1])
702
+ }
703
+ | tUMINUS arg
704
+ {
705
+ result = @builder.unary_op(val[0], val[1])
706
+ }
707
+ | arg tPIPE arg
708
+ {
709
+ result = @builder.binary_op(val[0], val[1], val[2])
710
+ }
711
+ | arg tCARET arg
712
+ {
713
+ result = @builder.binary_op(val[0], val[1], val[2])
714
+ }
715
+ | arg tAMPER2 arg
716
+ {
717
+ result = @builder.binary_op(val[0], val[1], val[2])
718
+ }
719
+ | arg tCMP arg
720
+ {
721
+ result = @builder.binary_op(val[0], val[1], val[2])
722
+ }
723
+ | arg tGT arg
724
+ {
725
+ result = @builder.binary_op(val[0], val[1], val[2])
726
+ }
727
+ | arg tGEQ arg
728
+ {
729
+ result = @builder.binary_op(val[0], val[1], val[2])
730
+ }
731
+ | arg tLT arg
732
+ {
733
+ result = @builder.binary_op(val[0], val[1], val[2])
734
+ }
735
+ | arg tLEQ arg
736
+ {
737
+ result = @builder.binary_op(val[0], val[1], val[2])
738
+ }
739
+ | arg tEQ arg
740
+ {
741
+ result = @builder.binary_op(val[0], val[1], val[2])
742
+ }
743
+ | arg tEQQ arg
744
+ {
745
+ result = @builder.binary_op(val[0], val[1], val[2])
746
+ }
747
+ | arg tNEQ arg
748
+ {
749
+ result = @builder.binary_op(val[0], val[1], val[2])
750
+ }
751
+ | arg tMATCH arg
752
+ {
753
+ result = @builder.match_op(val[0], val[1], val[2])
754
+ }
755
+ | arg tNMATCH arg
756
+ {
757
+ result = @builder.binary_op(val[0], val[1], val[2])
758
+ }
759
+ | tBANG arg
760
+ {
761
+ result = @builder.not_op(val[0], nil, val[1], nil)
762
+ }
763
+ | tTILDE arg
764
+ {
765
+ result = @builder.unary_op(val[0], val[1])
766
+ }
767
+ | arg tLSHFT arg
768
+ {
769
+ result = @builder.binary_op(val[0], val[1], val[2])
770
+ }
771
+ | arg tRSHFT arg
772
+ {
773
+ result = @builder.binary_op(val[0], val[1], val[2])
774
+ }
775
+ | arg tANDOP arg
776
+ {
777
+ result = @builder.logical_op(:and, val[0], val[1], val[2])
778
+ }
779
+ | arg tOROP arg
780
+ {
781
+ result = @builder.logical_op(:or, val[0], val[1], val[2])
782
+ }
783
+ | kDEFINED opt_nl arg
784
+ {
785
+ result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
786
+ }
787
+
788
+ | arg tEH arg opt_nl tCOLON arg
789
+ {
790
+ result = @builder.ternary(val[0], val[1],
791
+ val[2], val[4], val[5])
792
+ }
793
+ | primary
794
+
795
+ arg_value: arg
796
+
797
+ aref_args: none
798
+ | args trailer
799
+ | args tCOMMA assocs trailer
800
+ {
801
+ result = val[0] << @builder.associate(nil, val[2], nil)
802
+ }
803
+ | assocs trailer
804
+ {
805
+ result = [ @builder.associate(nil, val[0], nil) ]
806
+ }
807
+
808
+ paren_args: tLPAREN2 opt_call_args rparen
809
+ {
810
+ result = val
811
+ }
812
+
813
+ opt_paren_args: # nothing
814
+ {
815
+ result = [ nil, [], nil ]
816
+ }
817
+ | paren_args
818
+
819
+ opt_call_args: # nothing
820
+ {
821
+ result = []
822
+ }
823
+ | call_args
824
+ | args tCOMMA
825
+ | args tCOMMA assocs tCOMMA
826
+ {
827
+ result = val[0] << @builder.associate(nil, val[2], nil)
828
+ }
829
+ | assocs tCOMMA
830
+ {
831
+ result = [ @builder.associate(nil, val[0], nil) ]
832
+ }
833
+
834
+ call_args: command
835
+ {
836
+ result = [ val[0] ]
837
+ }
838
+ | args opt_block_arg
839
+ {
840
+ result = val[0].concat(val[1])
841
+ }
842
+ | assocs opt_block_arg
843
+ {
844
+ result = [ @builder.associate(nil, val[0], nil) ]
845
+ result.concat(val[1])
846
+ }
847
+ | args tCOMMA assocs opt_block_arg
848
+ {
849
+ assocs = @builder.associate(nil, val[2], nil)
850
+ result = val[0] << assocs
851
+ result.concat(val[3])
852
+ }
853
+ | block_arg
854
+ {
855
+ result = [ val[0] ]
856
+ }
857
+
858
+ command_args: {
859
+ result = @lexer.cmdarg.dup
860
+ @lexer.cmdarg.push(true)
861
+ }
862
+ call_args
863
+ {
864
+ @lexer.cmdarg = val[0]
865
+
866
+ result = val[1]
867
+ }
868
+
869
+ block_arg: tAMPER arg_value
870
+ {
871
+ result = @builder.block_pass(val[0], val[1])
872
+ }
873
+
874
+ opt_block_arg: tCOMMA block_arg
875
+ {
876
+ result = [ val[1] ]
877
+ }
878
+ | # nothing
879
+ {
880
+ result = []
881
+ }
882
+
883
+ args: arg_value
884
+ {
885
+ result = [ val[0] ]
886
+ }
887
+ | tSTAR arg_value
888
+ {
889
+ result = [ @builder.splat(val[0], val[1]) ]
890
+ }
891
+ | args tCOMMA arg_value
892
+ {
893
+ result = val[0] << val[2]
894
+ }
895
+ | args tCOMMA tSTAR arg_value
896
+ {
897
+ result = val[0] << @builder.splat(val[2], val[3])
898
+ }
899
+
900
+ mrhs_arg: mrhs
901
+ {
902
+ result = @builder.array(nil, val[0], nil)
903
+ }
904
+ | arg_value
905
+
906
+ mrhs: args tCOMMA arg_value
907
+ {
908
+ result = val[0] << val[2]
909
+ }
910
+ | args tCOMMA tSTAR arg_value
911
+ {
912
+ result = val[0] << @builder.splat(val[2], val[3])
913
+ }
914
+ | tSTAR arg_value
915
+ {
916
+ result = [ @builder.splat(val[0], val[1]) ]
917
+ }
918
+
919
+ primary: literal
920
+ | strings
921
+ | xstring
922
+ | regexp
923
+ | words
924
+ | qwords
925
+ | symbols
926
+ | qsymbols
927
+ | var_ref
928
+ | backref
929
+ | tFID
930
+ {
931
+ result = @builder.call_method(nil, nil, val[0])
932
+ }
933
+ | kBEGIN
934
+ {
935
+ result = @lexer.cmdarg.dup
936
+ @lexer.cmdarg.clear
937
+ }
938
+ bodystmt kEND
939
+ {
940
+ @lexer.cmdarg = val[1]
941
+
942
+ result = @builder.begin_keyword(val[0], val[2], val[3])
943
+ }
944
+ | tLPAREN_ARG
945
+ {
946
+ result = @lexer.cmdarg.dup
947
+ @lexer.cmdarg.clear
948
+ }
949
+ expr
950
+ {
951
+ @lexer.state = :expr_endarg
952
+ }
953
+ opt_nl tRPAREN
954
+ {
955
+ @lexer.cmdarg = val[1]
956
+
957
+ result = @builder.begin(val[0], val[2], val[5])
958
+ }
959
+ | tLPAREN_ARG
960
+ {
961
+ @lexer.state = :expr_endarg
962
+ }
963
+ opt_nl tRPAREN
964
+ {
965
+ result = @builder.begin(val[0], nil, val[3])
966
+ }
967
+ | tLPAREN compstmt tRPAREN
968
+ {
969
+ result = @builder.begin(val[0], val[1], val[2])
970
+ }
971
+ | primary_value tCOLON2 tCONSTANT
972
+ {
973
+ result = @builder.const_fetch(val[0], val[1], val[2])
974
+ }
975
+ | tCOLON3 tCONSTANT
976
+ {
977
+ result = @builder.const_global(val[0], val[1])
978
+ }
979
+ | tLBRACK aref_args tRBRACK
980
+ {
981
+ result = @builder.array(val[0], val[1], val[2])
982
+ }
983
+ | tLBRACE assoc_list tRCURLY
984
+ {
985
+ result = @builder.associate(val[0], val[1], val[2])
986
+ }
987
+ | kRETURN
988
+ {
989
+ result = @builder.keyword_cmd(:return, val[0])
990
+ }
991
+ | kYIELD tLPAREN2 call_args rparen
992
+ {
993
+ result = @builder.keyword_cmd(:yield, val[0], val[1], val[2], val[3])
994
+ }
995
+ | kYIELD tLPAREN2 rparen
996
+ {
997
+ result = @builder.keyword_cmd(:yield, val[0], val[1], [], val[2])
998
+ }
999
+ | kYIELD
1000
+ {
1001
+ result = @builder.keyword_cmd(:yield, val[0])
1002
+ }
1003
+ | kDEFINED opt_nl tLPAREN2 expr rparen
1004
+ {
1005
+ result = @builder.keyword_cmd(:defined?, val[0],
1006
+ val[2], [ val[3] ], val[4])
1007
+ }
1008
+ | kNOT tLPAREN2 expr rparen
1009
+ {
1010
+ result = @builder.not_op(val[0], val[1], val[2], val[3])
1011
+ }
1012
+ | kNOT tLPAREN2 rparen
1013
+ {
1014
+ result = @builder.not_op(val[0], val[1], nil, val[2])
1015
+ }
1016
+ | fcall brace_block
1017
+ {
1018
+ method_call = @builder.call_method(nil, nil, val[0])
1019
+
1020
+ begin_t, args, body, end_t = val[1]
1021
+ result = @builder.block(method_call,
1022
+ begin_t, args, body, end_t)
1023
+ }
1024
+ | method_call
1025
+ | method_call brace_block
1026
+ {
1027
+ begin_t, args, body, end_t = val[1]
1028
+ result = @builder.block(val[0],
1029
+ begin_t, args, body, end_t)
1030
+ }
1031
+ | tLAMBDA lambda
1032
+ {
1033
+ lambda_call = @builder.call_lambda(val[0])
1034
+
1035
+ args, (begin_t, body, end_t) = val[1]
1036
+ result = @builder.block(lambda_call,
1037
+ begin_t, args, body, end_t)
1038
+ }
1039
+ | kIF expr_value then compstmt if_tail kEND
1040
+ {
1041
+ else_t, else_ = val[4]
1042
+ result = @builder.condition(val[0], val[1], val[2],
1043
+ val[3], else_t,
1044
+ else_, val[5])
1045
+ }
1046
+ | kUNLESS expr_value then compstmt opt_else kEND
1047
+ {
1048
+ else_t, else_ = val[4]
1049
+ result = @builder.condition(val[0], val[1], val[2],
1050
+ else_, else_t,
1051
+ val[3], val[5])
1052
+ }
1053
+ | kWHILE
1054
+ {
1055
+ @lexer.cond.push(true)
1056
+ }
1057
+ expr_value do
1058
+ {
1059
+ @lexer.cond.pop
1060
+ }
1061
+ compstmt kEND
1062
+ {
1063
+ result = @builder.loop(:while, val[0], val[2], val[3],
1064
+ val[5], val[6])
1065
+ }
1066
+ | kUNTIL
1067
+ {
1068
+ @lexer.cond.push(true)
1069
+ }
1070
+ expr_value do
1071
+ {
1072
+ @lexer.cond.pop
1073
+ }
1074
+ compstmt kEND
1075
+ {
1076
+ result = @builder.loop(:until, val[0], val[2], val[3],
1077
+ val[5], val[6])
1078
+ }
1079
+ | kCASE expr_value opt_terms case_body kEND
1080
+ {
1081
+ *when_bodies, (else_t, else_body) = *val[3]
1082
+
1083
+ result = @builder.case(val[0], val[1],
1084
+ when_bodies, else_t, else_body,
1085
+ val[4])
1086
+ }
1087
+ | kCASE opt_terms case_body kEND
1088
+ {
1089
+ *when_bodies, (else_t, else_body) = *val[2]
1090
+
1091
+ result = @builder.case(val[0], nil,
1092
+ when_bodies, else_t, else_body,
1093
+ val[3])
1094
+ }
1095
+ | kFOR for_var kIN
1096
+ {
1097
+ @lexer.cond.push(true)
1098
+ }
1099
+ expr_value do
1100
+ {
1101
+ @lexer.cond.pop
1102
+ }
1103
+ compstmt kEND
1104
+ {
1105
+ result = @builder.for(val[0], val[1],
1106
+ val[2], val[4],
1107
+ val[5], val[7], val[8])
1108
+ }
1109
+ | kCLASS cpath superclass
1110
+ {
1111
+ @static_env.extend_static
1112
+ @lexer.push_cmdarg
1113
+ }
1114
+ bodystmt kEND
1115
+ {
1116
+ if in_def?
1117
+ diagnostic :error, :class_in_def, nil, val[0]
1118
+ end
1119
+
1120
+ lt_t, superclass = val[2]
1121
+ result = @builder.def_class(val[0], val[1],
1122
+ lt_t, superclass,
1123
+ val[4], val[5])
1124
+
1125
+ @lexer.pop_cmdarg
1126
+ @static_env.unextend
1127
+ }
1128
+ | kCLASS tLSHFT expr term
1129
+ {
1130
+ result = @def_level
1131
+ @def_level = 0
1132
+
1133
+ @static_env.extend_static
1134
+ @lexer.push_cmdarg
1135
+ }
1136
+ bodystmt kEND
1137
+ {
1138
+ result = @builder.def_sclass(val[0], val[1], val[2],
1139
+ val[5], val[6])
1140
+
1141
+ @lexer.pop_cmdarg
1142
+ @static_env.unextend
1143
+
1144
+ @def_level = val[4]
1145
+ }
1146
+ | kMODULE cpath
1147
+ {
1148
+ @static_env.extend_static
1149
+ @lexer.push_cmdarg
1150
+ }
1151
+ bodystmt kEND
1152
+ {
1153
+ if in_def?
1154
+ diagnostic :error, :module_in_def, nil, val[0]
1155
+ end
1156
+
1157
+ result = @builder.def_module(val[0], val[1],
1158
+ val[3], val[4])
1159
+
1160
+ @lexer.pop_cmdarg
1161
+ @static_env.unextend
1162
+ }
1163
+ | kDEF fname
1164
+ {
1165
+ @def_level += 1
1166
+ @static_env.extend_static
1167
+ @lexer.push_cmdarg
1168
+ }
1169
+ f_arglist bodystmt kEND
1170
+ {
1171
+ result = @builder.def_method(val[0], val[1],
1172
+ val[3], val[4], val[5])
1173
+
1174
+ @lexer.pop_cmdarg
1175
+ @static_env.unextend
1176
+ @def_level -= 1
1177
+ }
1178
+ | kDEF singleton dot_or_colon
1179
+ {
1180
+ @lexer.state = :expr_fname
1181
+ }
1182
+ fname
1183
+ {
1184
+ @def_level += 1
1185
+ @static_env.extend_static
1186
+ @lexer.push_cmdarg
1187
+ }
1188
+ f_arglist bodystmt kEND
1189
+ {
1190
+ result = @builder.def_singleton(val[0], val[1], val[2],
1191
+ val[4], val[6], val[7], val[8])
1192
+
1193
+ @lexer.pop_cmdarg
1194
+ @static_env.unextend
1195
+ @def_level -= 1
1196
+ }
1197
+ | kBREAK
1198
+ {
1199
+ result = @builder.keyword_cmd(:break, val[0])
1200
+ }
1201
+ | kNEXT
1202
+ {
1203
+ result = @builder.keyword_cmd(:next, val[0])
1204
+ }
1205
+ | kREDO
1206
+ {
1207
+ result = @builder.keyword_cmd(:redo, val[0])
1208
+ }
1209
+ | kRETRY
1210
+ {
1211
+ result = @builder.keyword_cmd(:retry, val[0])
1212
+ }
1213
+
1214
+ primary_value: primary
1215
+
1216
+ then: term
1217
+ | kTHEN
1218
+ | term kTHEN
1219
+ {
1220
+ result = val[1]
1221
+ }
1222
+
1223
+ do: term
1224
+ | kDO_COND
1225
+
1226
+ if_tail: opt_else
1227
+ | kELSIF expr_value then compstmt if_tail
1228
+ {
1229
+ else_t, else_ = val[4]
1230
+ result = [ val[0],
1231
+ @builder.condition(val[0], val[1], val[2],
1232
+ val[3], else_t,
1233
+ else_, nil),
1234
+ ]
1235
+ }
1236
+
1237
+ opt_else: none
1238
+ | kELSE compstmt
1239
+ {
1240
+ result = val
1241
+ }
1242
+
1243
+ for_var: lhs
1244
+ | mlhs
1245
+
1246
+ f_marg: f_norm_arg
1247
+ {
1248
+ result = @builder.arg(val[0])
1249
+ }
1250
+ | tLPAREN f_margs rparen
1251
+ {
1252
+ result = @builder.multi_lhs(val[0], val[1], val[2])
1253
+ }
1254
+
1255
+ f_marg_list: f_marg
1256
+ {
1257
+ result = [ val[0] ]
1258
+ }
1259
+ | f_marg_list tCOMMA f_marg
1260
+ {
1261
+ result = val[0] << val[2]
1262
+ }
1263
+
1264
+ f_margs: f_marg_list
1265
+ | f_marg_list tCOMMA tSTAR f_norm_arg
1266
+ {
1267
+ result = val[0].
1268
+ push(@builder.restarg(val[2], val[3]))
1269
+ }
1270
+ | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1271
+ {
1272
+ result = val[0].
1273
+ push(@builder.restarg(val[2], val[3])).
1274
+ concat(val[5])
1275
+ }
1276
+ | f_marg_list tCOMMA tSTAR
1277
+ {
1278
+ result = val[0].
1279
+ push(@builder.restarg(val[2]))
1280
+ }
1281
+ | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1282
+ {
1283
+ result = val[0].
1284
+ push(@builder.restarg(val[2])).
1285
+ concat(val[4])
1286
+ }
1287
+ | tSTAR f_norm_arg
1288
+ {
1289
+ result = [ @builder.restarg(val[0], val[1]) ]
1290
+ }
1291
+ | tSTAR f_norm_arg tCOMMA f_marg_list
1292
+ {
1293
+ result = [ @builder.restarg(val[0], val[1]),
1294
+ *val[3] ]
1295
+ }
1296
+ | tSTAR
1297
+ {
1298
+ result = [ @builder.restarg(val[0]) ]
1299
+ }
1300
+ | tSTAR tCOMMA f_marg_list
1301
+ {
1302
+ result = [ @builder.restarg(val[0]),
1303
+ *val[2] ]
1304
+ }
1305
+
1306
+ block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1307
+ {
1308
+ result = val[0].concat(val[2]).concat(val[3])
1309
+ }
1310
+ | f_block_kwarg opt_f_block_arg
1311
+ {
1312
+ result = val[0].concat(val[1])
1313
+ }
1314
+ | f_kwrest opt_f_block_arg
1315
+ {
1316
+ result = val[0].concat(val[1])
1317
+ }
1318
+ | f_block_arg
1319
+ {
1320
+ result = [ val[0] ]
1321
+ }
1322
+
1323
+ opt_block_args_tail:
1324
+ tCOMMA block_args_tail
1325
+ {
1326
+ result = val[1]
1327
+ }
1328
+ | # nothing
1329
+ {
1330
+ result = []
1331
+ }
1332
+
1333
+ block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1334
+ {
1335
+ result = val[0].
1336
+ concat(val[2]).
1337
+ concat(val[4]).
1338
+ concat(val[5])
1339
+ }
1340
+ | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1341
+ {
1342
+ result = val[0].
1343
+ concat(val[2]).
1344
+ concat(val[4]).
1345
+ concat(val[6]).
1346
+ concat(val[7])
1347
+ }
1348
+ | f_arg tCOMMA f_block_optarg opt_block_args_tail
1349
+ {
1350
+ result = val[0].
1351
+ concat(val[2]).
1352
+ concat(val[3])
1353
+ }
1354
+ | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
1355
+ {
1356
+ result = val[0].
1357
+ concat(val[2]).
1358
+ concat(val[4]).
1359
+ concat(val[5])
1360
+ }
1361
+ | f_arg tCOMMA f_rest_arg opt_block_args_tail
1362
+ {
1363
+ result = val[0].
1364
+ concat(val[2]).
1365
+ concat(val[3])
1366
+ }
1367
+ | f_arg tCOMMA
1368
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1369
+ {
1370
+ result = val[0].
1371
+ concat(val[2]).
1372
+ concat(val[4]).
1373
+ concat(val[5])
1374
+ }
1375
+ | f_arg opt_block_args_tail
1376
+ {
1377
+ result = val[0].concat(val[1])
1378
+ }
1379
+ | f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1380
+ {
1381
+ result = val[0].
1382
+ concat(val[2]).
1383
+ concat(val[3])
1384
+ }
1385
+ | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1386
+ {
1387
+ result = val[0].
1388
+ concat(val[2]).
1389
+ concat(val[4]).
1390
+ concat(val[5])
1391
+ }
1392
+ | f_block_optarg opt_block_args_tail
1393
+ {
1394
+ result = val[0].
1395
+ concat(val[1])
1396
+ }
1397
+ | f_block_optarg tCOMMA f_arg opt_block_args_tail
1398
+ {
1399
+ result = val[0].
1400
+ concat(val[2]).
1401
+ concat(val[3])
1402
+ }
1403
+ | f_rest_arg opt_block_args_tail
1404
+ {
1405
+ result = val[0].
1406
+ concat(val[1])
1407
+ }
1408
+ | f_rest_arg tCOMMA f_arg opt_block_args_tail
1409
+ {
1410
+ result = val[0].
1411
+ concat(val[2]).
1412
+ concat(val[3])
1413
+ }
1414
+ | block_args_tail
1415
+
1416
+ opt_block_param: # nothing
1417
+ {
1418
+ result = @builder.args(nil, [], nil)
1419
+ }
1420
+ | block_param_def
1421
+ {
1422
+ @lexer.state = :expr_value
1423
+ }
1424
+
1425
+ block_param_def: tPIPE opt_bv_decl tPIPE
1426
+ {
1427
+ result = @builder.args(val[0], val[1], val[2])
1428
+ }
1429
+ | tOROP
1430
+ {
1431
+ result = @builder.args(val[0], [], val[0])
1432
+ }
1433
+ | tPIPE block_param opt_bv_decl tPIPE
1434
+ {
1435
+ result = @builder.args(val[0], val[1].concat(val[2]), val[3])
1436
+ }
1437
+
1438
+ opt_bv_decl: opt_nl
1439
+ {
1440
+ result = []
1441
+ }
1442
+ | opt_nl tSEMI bv_decls opt_nl
1443
+ {
1444
+ result = val[2]
1445
+ }
1446
+
1447
+ bv_decls: bvar
1448
+ {
1449
+ result = [ val[0] ]
1450
+ }
1451
+ | bv_decls tCOMMA bvar
1452
+ {
1453
+ result = val[0] << val[2]
1454
+ }
1455
+
1456
+ bvar: tIDENTIFIER
1457
+ {
1458
+ result = @builder.shadowarg(val[0])
1459
+ }
1460
+ | f_bad_arg
1461
+
1462
+ lambda: {
1463
+ @static_env.extend_dynamic
1464
+ }
1465
+ f_larglist lambda_body
1466
+ {
1467
+ result = [ val[1], val[2] ]
1468
+
1469
+ @static_env.unextend
1470
+ }
1471
+
1472
+ f_larglist: tLPAREN2 f_args opt_bv_decl tRPAREN
1473
+ {
1474
+ result = @builder.args(val[0], val[1].concat(val[2]), val[3])
1475
+ }
1476
+ | f_args
1477
+ {
1478
+ result = @builder.args(nil, val[0], nil)
1479
+ }
1480
+
1481
+ lambda_body: tLAMBEG compstmt tRCURLY
1482
+ {
1483
+ result = [ val[0], val[1], val[2] ]
1484
+ }
1485
+ | kDO_LAMBDA compstmt kEND
1486
+ {
1487
+ result = [ val[0], val[1], val[2] ]
1488
+ }
1489
+
1490
+ do_block: kDO_BLOCK
1491
+ {
1492
+ @static_env.extend_dynamic
1493
+ }
1494
+ opt_block_param compstmt kEND
1495
+ {
1496
+ result = [ val[0], val[2], val[3], val[4] ]
1497
+
1498
+ @static_env.unextend
1499
+ }
1500
+
1501
+ block_call: command do_block
1502
+ {
1503
+ begin_t, block_args, body, end_t = val[1]
1504
+ result = @builder.block(val[0],
1505
+ begin_t, block_args, body, end_t)
1506
+ }
1507
+ | block_call dot_or_colon operation2 opt_paren_args
1508
+ {
1509
+ lparen_t, args, rparen_t = val[3]
1510
+ result = @builder.call_method(val[0], val[1], val[2],
1511
+ lparen_t, args, rparen_t)
1512
+ }
1513
+ | block_call dot_or_colon operation2 opt_paren_args brace_block
1514
+ {
1515
+ lparen_t, args, rparen_t = val[3]
1516
+ method_call = @builder.call_method(val[0], val[1], val[2],
1517
+ lparen_t, args, rparen_t)
1518
+
1519
+ begin_t, args, body, end_t = val[4]
1520
+ result = @builder.block(method_call,
1521
+ begin_t, args, body, end_t)
1522
+ }
1523
+ | block_call dot_or_colon operation2 command_args do_block
1524
+ {
1525
+ method_call = @builder.call_method(val[0], val[1], val[2],
1526
+ nil, val[3], nil)
1527
+
1528
+ begin_t, args, body, end_t = val[4]
1529
+ result = @builder.block(method_call,
1530
+ begin_t, args, body, end_t)
1531
+ }
1532
+
1533
+ method_call: fcall paren_args
1534
+ {
1535
+ lparen_t, args, rparen_t = val[1]
1536
+ result = @builder.call_method(nil, nil, val[0],
1537
+ lparen_t, args, rparen_t)
1538
+ }
1539
+ | primary_value tDOT operation2 opt_paren_args
1540
+ {
1541
+ lparen_t, args, rparen_t = val[3]
1542
+ result = @builder.call_method(val[0], val[1], val[2],
1543
+ lparen_t, args, rparen_t)
1544
+ }
1545
+ | primary_value tCOLON2 operation2 paren_args
1546
+ {
1547
+ lparen_t, args, rparen_t = val[3]
1548
+ result = @builder.call_method(val[0], val[1], val[2],
1549
+ lparen_t, args, rparen_t)
1550
+ }
1551
+ | primary_value tCOLON2 operation3
1552
+ {
1553
+ result = @builder.call_method(val[0], val[1], val[2])
1554
+ }
1555
+ | primary_value tDOT paren_args
1556
+ {
1557
+ lparen_t, args, rparen_t = val[2]
1558
+ result = @builder.call_method(val[0], val[1], nil,
1559
+ lparen_t, args, rparen_t)
1560
+ }
1561
+ | primary_value tCOLON2 paren_args
1562
+ {
1563
+ lparen_t, args, rparen_t = val[2]
1564
+ result = @builder.call_method(val[0], val[1], nil,
1565
+ lparen_t, args, rparen_t)
1566
+ }
1567
+ | kSUPER paren_args
1568
+ {
1569
+ lparen_t, args, rparen_t = val[1]
1570
+ result = @builder.keyword_cmd(:super, val[0],
1571
+ lparen_t, args, rparen_t)
1572
+ }
1573
+ | kSUPER
1574
+ {
1575
+ result = @builder.keyword_cmd(:zsuper, val[0])
1576
+ }
1577
+ | primary_value tLBRACK2 opt_call_args rbracket
1578
+ {
1579
+ result = @builder.index(val[0], val[1], val[2], val[3])
1580
+ }
1581
+
1582
+ brace_block: tLCURLY
1583
+ {
1584
+ @static_env.extend_dynamic
1585
+ }
1586
+ opt_block_param compstmt tRCURLY
1587
+ {
1588
+ result = [ val[0], val[2], val[3], val[4] ]
1589
+
1590
+ @static_env.unextend
1591
+ }
1592
+ | kDO
1593
+ {
1594
+ @static_env.extend_dynamic
1595
+ }
1596
+ opt_block_param compstmt kEND
1597
+ {
1598
+ result = [ val[0], val[2], val[3], val[4] ]
1599
+
1600
+ @static_env.unextend
1601
+ }
1602
+
1603
+ case_body: kWHEN args then compstmt cases
1604
+ {
1605
+ result = [ @builder.when(val[0], val[1], val[2], val[3]),
1606
+ *val[4] ]
1607
+ }
1608
+
1609
+ cases: opt_else
1610
+ {
1611
+ result = [ val[0] ]
1612
+ }
1613
+ | case_body
1614
+
1615
+ opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
1616
+ {
1617
+ assoc_t, exc_var = val[2]
1618
+
1619
+ if val[1]
1620
+ exc_list = @builder.array(nil, val[1], nil)
1621
+ end
1622
+
1623
+ result = [ @builder.rescue_body(val[0],
1624
+ exc_list, assoc_t, exc_var,
1625
+ val[3], val[4]),
1626
+ *val[5] ]
1627
+ }
1628
+ |
1629
+ {
1630
+ result = []
1631
+ }
1632
+
1633
+ exc_list: arg_value
1634
+ {
1635
+ result = [ val[0] ]
1636
+ }
1637
+ | mrhs
1638
+ | none
1639
+
1640
+ exc_var: tASSOC lhs
1641
+ {
1642
+ result = [ val[0], val[1] ]
1643
+ }
1644
+ | none
1645
+
1646
+ opt_ensure: kENSURE compstmt
1647
+ {
1648
+ result = [ val[0], val[1] ]
1649
+ }
1650
+ | none
1651
+
1652
+ literal: numeric
1653
+ | symbol
1654
+ | dsym
1655
+
1656
+ strings: string
1657
+ {
1658
+ result = @builder.string_compose(nil, val[0], nil)
1659
+ }
1660
+
1661
+ string: string1
1662
+ {
1663
+ result = [ val[0] ]
1664
+ }
1665
+ | string string1
1666
+ {
1667
+ result = val[0] << val[1]
1668
+ }
1669
+
1670
+ string1: tSTRING_BEG string_contents tSTRING_END
1671
+ {
1672
+ result = @builder.string_compose(val[0], val[1], val[2])
1673
+ }
1674
+ | tSTRING
1675
+ {
1676
+ result = @builder.string(val[0])
1677
+ }
1678
+ | tCHARACTER
1679
+ {
1680
+ result = @builder.character(val[0])
1681
+ }
1682
+
1683
+ xstring: tXSTRING_BEG xstring_contents tSTRING_END
1684
+ {
1685
+ result = @builder.xstring_compose(val[0], val[1], val[2])
1686
+ }
1687
+
1688
+ regexp: tREGEXP_BEG regexp_contents tSTRING_END tREGEXP_OPT
1689
+ {
1690
+ opts = @builder.regexp_options(val[3])
1691
+ result = @builder.regexp_compose(val[0], val[1], val[2], opts)
1692
+ }
1693
+
1694
+ words: tWORDS_BEG word_list tSTRING_END
1695
+ {
1696
+ result = @builder.words_compose(val[0], val[1], val[2])
1697
+ }
1698
+
1699
+ word_list: # nothing
1700
+ {
1701
+ result = []
1702
+ }
1703
+ | word_list word tSPACE
1704
+ {
1705
+ result = val[0] << @builder.word(val[1])
1706
+ }
1707
+
1708
+ word: string_content
1709
+ {
1710
+ result = [ val[0] ]
1711
+ }
1712
+ | word string_content
1713
+ {
1714
+ result = val[0] << val[1]
1715
+ }
1716
+
1717
+ symbols: tSYMBOLS_BEG symbol_list tSTRING_END
1718
+ {
1719
+ result = @builder.symbols_compose(val[0], val[1], val[2])
1720
+ }
1721
+
1722
+ symbol_list: # nothing
1723
+ {
1724
+ result = []
1725
+ }
1726
+ | symbol_list word tSPACE
1727
+ {
1728
+ result = val[0] << @builder.word(val[1])
1729
+ }
1730
+
1731
+ qwords: tQWORDS_BEG qword_list tSTRING_END
1732
+ {
1733
+ result = @builder.words_compose(val[0], val[1], val[2])
1734
+ }
1735
+
1736
+ qsymbols: tQSYMBOLS_BEG qsym_list tSTRING_END
1737
+ {
1738
+ result = @builder.symbols_compose(val[0], val[1], val[2])
1739
+ }
1740
+
1741
+ qword_list: # nothing
1742
+ {
1743
+ result = []
1744
+ }
1745
+ | qword_list tSTRING_CONTENT tSPACE
1746
+ {
1747
+ result = val[0] << @builder.string_internal(val[1])
1748
+ }
1749
+
1750
+ qsym_list: # nothing
1751
+ {
1752
+ result = []
1753
+ }
1754
+ | qsym_list tSTRING_CONTENT tSPACE
1755
+ {
1756
+ result = val[0] << @builder.symbol_internal(val[1])
1757
+ }
1758
+
1759
+ string_contents: # nothing
1760
+ {
1761
+ result = []
1762
+ }
1763
+ | string_contents string_content
1764
+ {
1765
+ result = val[0] << val[1]
1766
+ }
1767
+
1768
+ xstring_contents: # nothing
1769
+ {
1770
+ result = []
1771
+ }
1772
+ | xstring_contents string_content
1773
+ {
1774
+ result = val[0] << val[1]
1775
+ }
1776
+
1777
+ regexp_contents: # nothing
1778
+ {
1779
+ result = []
1780
+ }
1781
+ | regexp_contents string_content
1782
+ {
1783
+ result = val[0] << val[1]
1784
+ }
1785
+
1786
+ string_content: tSTRING_CONTENT
1787
+ {
1788
+ result = @builder.string_internal(val[0])
1789
+ }
1790
+ | tSTRING_DVAR string_dvar
1791
+ {
1792
+ result = val[1]
1793
+ }
1794
+ | tSTRING_DBEG
1795
+ {
1796
+ @lexer.cond.push(false)
1797
+ @lexer.cmdarg.push(false)
1798
+ }
1799
+ compstmt tSTRING_DEND
1800
+ {
1801
+ @lexer.cond.lexpop
1802
+ @lexer.cmdarg.lexpop
1803
+
1804
+ result = @builder.begin(val[0], val[2], val[3])
1805
+ }
1806
+
1807
+ string_dvar: tGVAR
1808
+ {
1809
+ result = @builder.gvar(val[0])
1810
+ }
1811
+ | tIVAR
1812
+ {
1813
+ result = @builder.ivar(val[0])
1814
+ }
1815
+ | tCVAR
1816
+ {
1817
+ result = @builder.cvar(val[0])
1818
+ }
1819
+ | backref
1820
+
1821
+
1822
+ symbol: tSYMBOL
1823
+ {
1824
+ result = @builder.symbol(val[0])
1825
+ }
1826
+
1827
+ dsym: tSYMBEG xstring_contents tSTRING_END
1828
+ {
1829
+ result = @builder.symbol_compose(val[0], val[1], val[2])
1830
+ }
1831
+
1832
+ numeric: simple_numeric
1833
+ {
1834
+ result = val[0]
1835
+ }
1836
+ | tUMINUS_NUM simple_numeric =tLOWEST
1837
+ {
1838
+ result = @builder.negate(val[0], val[1])
1839
+ }
1840
+
1841
+ simple_numeric: tINTEGER
1842
+ {
1843
+ result = @builder.integer(val[0])
1844
+ }
1845
+ | tFLOAT
1846
+ {
1847
+ result = @builder.float(val[0])
1848
+ }
1849
+ | tRATIONAL
1850
+ {
1851
+ result = @builder.rational(val[0])
1852
+ }
1853
+ | tIMAGINARY
1854
+ {
1855
+ result = @builder.complex(val[0])
1856
+ }
1857
+
1858
+ user_variable: tIDENTIFIER
1859
+ {
1860
+ result = @builder.ident(val[0])
1861
+ }
1862
+ | tIVAR
1863
+ {
1864
+ result = @builder.ivar(val[0])
1865
+ }
1866
+ | tGVAR
1867
+ {
1868
+ result = @builder.gvar(val[0])
1869
+ }
1870
+ | tCONSTANT
1871
+ {
1872
+ result = @builder.const(val[0])
1873
+ }
1874
+ | tCVAR
1875
+ {
1876
+ result = @builder.cvar(val[0])
1877
+ }
1878
+
1879
+ keyword_variable: kNIL
1880
+ {
1881
+ result = @builder.nil(val[0])
1882
+ }
1883
+ | kSELF
1884
+ {
1885
+ result = @builder.self(val[0])
1886
+ }
1887
+ | kTRUE
1888
+ {
1889
+ result = @builder.true(val[0])
1890
+ }
1891
+ | kFALSE
1892
+ {
1893
+ result = @builder.false(val[0])
1894
+ }
1895
+ | k__FILE__
1896
+ {
1897
+ result = @builder.__FILE__(val[0])
1898
+ }
1899
+ | k__LINE__
1900
+ {
1901
+ result = @builder.__LINE__(val[0])
1902
+ }
1903
+ | k__ENCODING__
1904
+ {
1905
+ result = @builder.__ENCODING__(val[0])
1906
+ }
1907
+
1908
+ var_ref: user_variable
1909
+ {
1910
+ result = @builder.accessible(val[0])
1911
+ }
1912
+ | keyword_variable
1913
+ {
1914
+ result = @builder.accessible(val[0])
1915
+ }
1916
+
1917
+ var_lhs: user_variable
1918
+ {
1919
+ result = @builder.assignable(val[0])
1920
+ }
1921
+ | keyword_variable
1922
+ {
1923
+ result = @builder.assignable(val[0])
1924
+ }
1925
+
1926
+ backref: tNTH_REF
1927
+ {
1928
+ result = @builder.nth_ref(val[0])
1929
+ }
1930
+ | tBACK_REF
1931
+ {
1932
+ result = @builder.back_ref(val[0])
1933
+ }
1934
+
1935
+ superclass: term
1936
+ {
1937
+ result = nil
1938
+ }
1939
+ | tLT
1940
+ {
1941
+ @lexer.state = :expr_value
1942
+ }
1943
+ expr_value term
1944
+ {
1945
+ result = [ val[0], val[2] ]
1946
+ }
1947
+ | error term
1948
+ {
1949
+ yyerrok
1950
+ result = nil
1951
+ }
1952
+
1953
+ f_arglist: tLPAREN2 f_args rparen
1954
+ {
1955
+ result = @builder.args(val[0], val[1], val[2])
1956
+
1957
+ @lexer.state = :expr_value
1958
+ }
1959
+ | f_args term
1960
+ {
1961
+ result = @builder.args(nil, val[0], nil)
1962
+ }
1963
+
1964
+ args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
1965
+ {
1966
+ result = val[0].concat(val[2]).concat(val[3])
1967
+ }
1968
+ | f_kwarg opt_f_block_arg
1969
+ {
1970
+ result = val[0].concat(val[1])
1971
+ }
1972
+ | f_kwrest opt_f_block_arg
1973
+ {
1974
+ result = val[0].concat(val[1])
1975
+ }
1976
+ | f_block_arg
1977
+ {
1978
+ result = [ val[0] ]
1979
+ }
1980
+
1981
+ opt_args_tail: tCOMMA args_tail
1982
+ {
1983
+ result = val[1]
1984
+ }
1985
+ | # nothing
1986
+ {
1987
+ result = []
1988
+ }
1989
+
1990
+ f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
1991
+ {
1992
+ result = val[0].
1993
+ concat(val[2]).
1994
+ concat(val[4]).
1995
+ concat(val[5])
1996
+ }
1997
+ | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
1998
+ {
1999
+ result = val[0].
2000
+ concat(val[2]).
2001
+ concat(val[4]).
2002
+ concat(val[6]).
2003
+ concat(val[7])
2004
+ }
2005
+ | f_arg tCOMMA f_optarg opt_args_tail
2006
+ {
2007
+ result = val[0].
2008
+ concat(val[2]).
2009
+ concat(val[3])
2010
+ }
2011
+ | f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
2012
+ {
2013
+ result = val[0].
2014
+ concat(val[2]).
2015
+ concat(val[4]).
2016
+ concat(val[5])
2017
+ }
2018
+ | f_arg tCOMMA f_rest_arg opt_args_tail
2019
+ {
2020
+ result = val[0].
2021
+ concat(val[2]).
2022
+ concat(val[3])
2023
+ }
2024
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2025
+ {
2026
+ result = val[0].
2027
+ concat(val[2]).
2028
+ concat(val[4]).
2029
+ concat(val[5])
2030
+ }
2031
+ | f_arg opt_args_tail
2032
+ {
2033
+ result = val[0].
2034
+ concat(val[1])
2035
+ }
2036
+ | f_optarg tCOMMA f_rest_arg opt_args_tail
2037
+ {
2038
+ result = val[0].
2039
+ concat(val[2]).
2040
+ concat(val[3])
2041
+ }
2042
+ | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2043
+ {
2044
+ result = val[0].
2045
+ concat(val[2]).
2046
+ concat(val[4]).
2047
+ concat(val[5])
2048
+ }
2049
+ | f_optarg opt_args_tail
2050
+ {
2051
+ result = val[0].
2052
+ concat(val[1])
2053
+ }
2054
+ | f_optarg tCOMMA f_arg opt_args_tail
2055
+ {
2056
+ result = val[0].
2057
+ concat(val[2]).
2058
+ concat(val[3])
2059
+ }
2060
+ | f_rest_arg opt_args_tail
2061
+ {
2062
+ result = val[0].
2063
+ concat(val[1])
2064
+ }
2065
+ | f_rest_arg tCOMMA f_arg opt_args_tail
2066
+ {
2067
+ result = val[0].
2068
+ concat(val[2]).
2069
+ concat(val[3])
2070
+ }
2071
+ | args_tail
2072
+ {
2073
+ result = val[0]
2074
+ }
2075
+ | # nothing
2076
+ {
2077
+ result = []
2078
+ }
2079
+
2080
+ f_bad_arg: tCONSTANT
2081
+ {
2082
+ diagnostic :error, :argument_const, nil, val[0]
2083
+ }
2084
+ | tIVAR
2085
+ {
2086
+ diagnostic :error, :argument_ivar, nil, val[0]
2087
+ }
2088
+ | tGVAR
2089
+ {
2090
+ diagnostic :error, :argument_gvar, nil, val[0]
2091
+ }
2092
+ | tCVAR
2093
+ {
2094
+ diagnostic :error, :argument_cvar, nil, val[0]
2095
+ }
2096
+
2097
+ f_norm_arg: f_bad_arg
2098
+ | tIDENTIFIER
2099
+ {
2100
+ @static_env.declare val[0][0]
2101
+
2102
+ result = val[0]
2103
+ }
2104
+
2105
+ f_arg_asgn: f_norm_arg
2106
+ {
2107
+ result = val[0]
2108
+ }
2109
+
2110
+ f_arg_item: f_arg_asgn
2111
+ {
2112
+ result = @builder.arg(val[0])
2113
+ }
2114
+ | tLPAREN f_margs rparen
2115
+ {
2116
+ result = @builder.multi_lhs(val[0], val[1], val[2])
2117
+ }
2118
+
2119
+ f_arg: f_arg_item
2120
+ {
2121
+ result = [ val[0] ]
2122
+ }
2123
+ | f_arg tCOMMA f_arg_item
2124
+ {
2125
+ result = val[0] << val[2]
2126
+ }
2127
+
2128
+ f_label: tLABEL
2129
+ {
2130
+ check_kwarg_name(val[0])
2131
+
2132
+ @static_env.declare val[0][0]
2133
+
2134
+ result = val[0]
2135
+ }
2136
+
2137
+ f_kw: f_label arg_value
2138
+ {
2139
+ result = @builder.kwoptarg(val[0], val[1])
2140
+ }
2141
+ | f_label
2142
+ {
2143
+ result = @builder.kwarg(val[0])
2144
+ }
2145
+
2146
+ f_block_kw: f_label primary_value
2147
+ {
2148
+ result = @builder.kwoptarg(val[0], val[1])
2149
+ }
2150
+ | f_label
2151
+ {
2152
+ result = @builder.kwarg(val[0])
2153
+ }
2154
+
2155
+ f_block_kwarg: f_block_kw
2156
+ {
2157
+ result = [ val[0] ]
2158
+ }
2159
+ | f_block_kwarg tCOMMA f_block_kw
2160
+ {
2161
+ result = val[0] << val[2]
2162
+ }
2163
+
2164
+ f_kwarg: f_kw
2165
+ {
2166
+ result = [ val[0] ]
2167
+ }
2168
+ | f_kwarg tCOMMA f_kw
2169
+ {
2170
+ result = val[0] << val[2]
2171
+ }
2172
+
2173
+ kwrest_mark: tPOW | tDSTAR
2174
+
2175
+ f_kwrest: kwrest_mark tIDENTIFIER
2176
+ {
2177
+ @static_env.declare val[1][0]
2178
+
2179
+ result = [ @builder.kwrestarg(val[0], val[1]) ]
2180
+ }
2181
+ | kwrest_mark
2182
+ {
2183
+ result = [ @builder.kwrestarg(val[0]) ]
2184
+ }
2185
+
2186
+ f_opt: f_arg_asgn tEQL arg_value
2187
+ {
2188
+ result = @builder.optarg(val[0], val[1], val[2])
2189
+ }
2190
+
2191
+ f_block_opt: f_arg_asgn tEQL primary_value
2192
+ {
2193
+ result = @builder.optarg(val[0], val[1], val[2])
2194
+ }
2195
+
2196
+ f_block_optarg: f_block_opt
2197
+ {
2198
+ result = [ val[0] ]
2199
+ }
2200
+ | f_block_optarg tCOMMA f_block_opt
2201
+ {
2202
+ result = val[0] << val[2]
2203
+ }
2204
+
2205
+ f_optarg: f_opt
2206
+ {
2207
+ result = [ val[0] ]
2208
+ }
2209
+ | f_optarg tCOMMA f_opt
2210
+ {
2211
+ result = val[0] << val[2]
2212
+ }
2213
+
2214
+ restarg_mark: tSTAR2 | tSTAR
2215
+
2216
+ f_rest_arg: restarg_mark tIDENTIFIER
2217
+ {
2218
+ @static_env.declare val[1][0]
2219
+
2220
+ result = [ @builder.restarg(val[0], val[1]) ]
2221
+ }
2222
+ | restarg_mark
2223
+ {
2224
+ result = [ @builder.restarg(val[0]) ]
2225
+ }
2226
+
2227
+ blkarg_mark: tAMPER2 | tAMPER
2228
+
2229
+ f_block_arg: blkarg_mark tIDENTIFIER
2230
+ {
2231
+ @static_env.declare val[1][0]
2232
+
2233
+ result = @builder.blockarg(val[0], val[1])
2234
+ }
2235
+
2236
+ opt_f_block_arg: tCOMMA f_block_arg
2237
+ {
2238
+ result = [ val[1] ]
2239
+ }
2240
+ |
2241
+ {
2242
+ result = []
2243
+ }
2244
+
2245
+ singleton: var_ref
2246
+ | tLPAREN2 expr rparen
2247
+ {
2248
+ result = val[1]
2249
+ }
2250
+
2251
+ assoc_list: # nothing
2252
+ {
2253
+ result = []
2254
+ }
2255
+ | assocs trailer
2256
+
2257
+ assocs: assoc
2258
+ {
2259
+ result = [ val[0] ]
2260
+ }
2261
+ | assocs tCOMMA assoc
2262
+ {
2263
+ result = val[0] << val[2]
2264
+ }
2265
+
2266
+ assoc: arg_value tASSOC arg_value
2267
+ {
2268
+ result = @builder.pair(val[0], val[1], val[2])
2269
+ }
2270
+ | tLABEL arg_value
2271
+ {
2272
+ result = @builder.pair_keyword(val[0], val[1])
2273
+ }
2274
+ | tDSTAR arg_value
2275
+ {
2276
+ result = @builder.kwsplat(val[0], val[1])
2277
+ }
2278
+
2279
+ operation: tIDENTIFIER | tCONSTANT | tFID
2280
+ operation2: tIDENTIFIER | tCONSTANT | tFID | op
2281
+ operation3: tIDENTIFIER | tFID | op
2282
+ dot_or_colon: tDOT | tCOLON2
2283
+ opt_terms: | terms
2284
+ opt_nl: | tNL
2285
+ rparen: opt_nl tRPAREN
2286
+ {
2287
+ result = val[1]
2288
+ }
2289
+ rbracket: opt_nl tRBRACK
2290
+ {
2291
+ result = val[1]
2292
+ }
2293
+ trailer: | tNL | tCOMMA
2294
+
2295
+ term: tSEMI
2296
+ {
2297
+ yyerrok
2298
+ }
2299
+ | tNL
2300
+
2301
+ terms: term
2302
+ | terms tSEMI
2303
+
2304
+ none: # nothing
2305
+ {
2306
+ result = nil
2307
+ }
2308
+ end
2309
+
2310
+ ---- header
2311
+
2312
+ require 'parser'
2313
+
2314
+ warn "warning: you are loading parser/ruby22 from #{caller[0]}."
2315
+ warn "warning: Ruby 2.2 is not released yet and parser support may be incomplete."
2316
+
2317
+ Parser.check_for_encoding_support
2318
+
2319
+ ---- inner
2320
+
2321
+ def version
2322
+ 22
2323
+ end
2324
+
2325
+ def default_encoding
2326
+ Encoding::UTF_8
2327
+ end