racc 1.4.14 → 1.4.15

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