parser 2.6.0.0 → 2.6.2.0

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