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