racc 1.4.14 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/COPYING +22 -515
  3. data/README.ja.rdoc +3 -4
  4. data/README.rdoc +6 -8
  5. data/Rakefile +32 -53
  6. data/bin/racc +39 -27
  7. data/ext/racc/com/headius/racc/Cparse.java +66 -23
  8. data/ext/racc/{cparse.c → cparse/cparse.c} +82 -47
  9. data/ext/racc/{extconf.rb → cparse/extconf.rb} +2 -1
  10. data/lib/racc/compat.rb +5 -4
  11. data/lib/racc/debugflags.rb +5 -4
  12. data/lib/racc/exception.rb +5 -4
  13. data/lib/racc/grammar.rb +25 -22
  14. data/lib/racc/grammarfileparser.rb +10 -8
  15. data/lib/racc/info.rb +6 -5
  16. data/lib/racc/iset.rb +6 -5
  17. data/lib/racc/logfilegenerator.rb +6 -5
  18. data/lib/racc/parser-text.rb +20 -23
  19. data/lib/racc/parser.rb +20 -23
  20. data/lib/racc/parserfilegenerator.rb +10 -10
  21. data/lib/racc/sourcetext.rb +5 -4
  22. data/lib/racc/state.rb +13 -12
  23. data/lib/racc/statetransitiontable.rb +7 -6
  24. data/rdoc/ja/command.ja.html +1 -1
  25. data/sample/array.y +1 -1
  26. data/sample/array2.y +1 -1
  27. data/sample/calc-ja.y +2 -2
  28. data/sample/calc.y +2 -2
  29. data/sample/conflict.y +1 -1
  30. data/sample/hash.y +1 -1
  31. data/sample/lalr.y +1 -1
  32. data/sample/lists.y +1 -1
  33. data/sample/syntax.y +1 -1
  34. data/sample/yyerr.y +1 -1
  35. data/test/assets/cadenza.y +170 -0
  36. data/test/assets/cast.y +926 -0
  37. data/test/assets/csspool.y +729 -0
  38. data/test/assets/edtf.y +583 -0
  39. data/test/assets/huia.y +318 -0
  40. data/test/assets/intp.y +4 -4
  41. data/test/assets/journey.y +47 -0
  42. data/test/assets/liquor.y +313 -0
  43. data/test/assets/machete.y +423 -0
  44. data/test/assets/macruby.y +2197 -0
  45. data/test/assets/mailp.y +27 -27
  46. data/test/assets/mediacloth.y +599 -0
  47. data/test/assets/mof.y +649 -0
  48. data/test/assets/namae.y +302 -0
  49. data/test/assets/nasl.y +626 -0
  50. data/test/assets/nokogiri-css.y +255 -0
  51. data/test/assets/nullbug2.y +2 -2
  52. data/test/assets/opal.y +1807 -0
  53. data/test/assets/php_serialization.y +98 -0
  54. data/test/assets/recv.y +20 -20
  55. data/test/assets/riml.y +665 -0
  56. data/test/assets/ruby18.y +1943 -0
  57. data/test/assets/ruby19.y +2174 -0
  58. data/test/assets/ruby20.y +2350 -0
  59. data/test/assets/ruby21.y +2359 -0
  60. data/test/assets/ruby22.y +2381 -0
  61. data/test/assets/syntax.y +1 -1
  62. data/test/assets/tp_plus.y +622 -0
  63. data/test/assets/twowaysql.y +278 -0
  64. data/test/helper.rb +68 -41
  65. data/test/regress/cadenza +796 -0
  66. data/test/regress/cast +3428 -0
  67. data/test/regress/csspool +2314 -0
  68. data/test/regress/edtf +1794 -0
  69. data/test/regress/huia +1392 -0
  70. data/test/regress/journey +222 -0
  71. data/test/regress/liquor +885 -0
  72. data/test/regress/machete +833 -0
  73. data/test/regress/mediacloth +1463 -0
  74. data/test/regress/mof +1368 -0
  75. data/test/regress/namae +634 -0
  76. data/test/regress/nasl +2058 -0
  77. data/test/regress/nokogiri-css +836 -0
  78. data/test/regress/opal +6431 -0
  79. data/test/regress/php_serialization +336 -0
  80. data/test/regress/riml +3283 -0
  81. data/test/regress/ruby18 +6344 -0
  82. data/test/regress/ruby22 +7460 -0
  83. data/test/regress/tp_plus +1933 -0
  84. data/test/regress/twowaysql +556 -0
  85. data/test/test_chk_y.rb +1 -0
  86. data/test/test_racc_command.rb +177 -2
  87. data/test/test_scan_y.rb +1 -0
  88. data/test/testscanner.rb +1 -1
  89. metadata +59 -83
  90. data/DEPENDS +0 -4
  91. data/Manifest.txt +0 -102
  92. data/bin/racc2y +0 -195
  93. data/bin/y2racc +0 -339
  94. data/ext/racc/depend +0 -1
  95. data/fastcache/extconf.rb +0 -2
  96. data/fastcache/fastcache.c +0 -185
  97. data/misc/dist.sh +0 -31
  98. data/setup.rb +0 -1587
  99. data/tasks/doc.rb +0 -12
  100. data/tasks/email.rb +0 -55
@@ -0,0 +1,255 @@
1
+ class Nokogiri::CSS::Parser
2
+
3
+ token FUNCTION INCLUDES DASHMATCH LBRACE HASH PLUS GREATER S STRING IDENT
4
+ token COMMA NUMBER PREFIXMATCH SUFFIXMATCH SUBSTRINGMATCH TILDE NOT_EQUAL
5
+ token SLASH DOUBLESLASH NOT EQUAL RPAREN LSQUARE RSQUARE HAS
6
+
7
+ rule
8
+ selector
9
+ : selector COMMA simple_selector_1toN {
10
+ result = [val.first, val.last].flatten
11
+ }
12
+ | prefixless_combinator_selector { result = val.flatten }
13
+ | optional_S simple_selector_1toN { result = [val.last].flatten }
14
+ ;
15
+ combinator
16
+ : PLUS { result = :DIRECT_ADJACENT_SELECTOR }
17
+ | GREATER { result = :CHILD_SELECTOR }
18
+ | TILDE { result = :FOLLOWING_SELECTOR }
19
+ | DOUBLESLASH { result = :DESCENDANT_SELECTOR }
20
+ | SLASH { result = :CHILD_SELECTOR }
21
+ ;
22
+ simple_selector
23
+ : element_name hcap_0toN {
24
+ result = if val[1].nil?
25
+ val.first
26
+ else
27
+ Node.new(:CONDITIONAL_SELECTOR, [val.first, val[1]])
28
+ end
29
+ }
30
+ | function
31
+ | function pseudo {
32
+ result = Node.new(:CONDITIONAL_SELECTOR, val)
33
+ }
34
+ | function attrib {
35
+ result = Node.new(:CONDITIONAL_SELECTOR, val)
36
+ }
37
+ | hcap_1toN {
38
+ result = Node.new(:CONDITIONAL_SELECTOR,
39
+ [Node.new(:ELEMENT_NAME, ['*']), val.first]
40
+ )
41
+ }
42
+ ;
43
+ prefixless_combinator_selector
44
+ : combinator simple_selector_1toN {
45
+ result = Node.new(val.first, [nil, val.last])
46
+ }
47
+ ;
48
+ simple_selector_1toN
49
+ : simple_selector combinator simple_selector_1toN {
50
+ result = Node.new(val[1], [val.first, val.last])
51
+ }
52
+ | simple_selector S simple_selector_1toN {
53
+ result = Node.new(:DESCENDANT_SELECTOR, [val.first, val.last])
54
+ }
55
+ | simple_selector
56
+ ;
57
+ class
58
+ : '.' IDENT { result = Node.new(:CLASS_CONDITION, [val[1]]) }
59
+ ;
60
+ element_name
61
+ : namespaced_ident
62
+ | '*' { result = Node.new(:ELEMENT_NAME, val) }
63
+ ;
64
+ namespaced_ident
65
+ : namespace '|' IDENT {
66
+ result = Node.new(:ELEMENT_NAME,
67
+ [[val.first, val.last].compact.join(':')]
68
+ )
69
+ }
70
+ | IDENT {
71
+ name = @namespaces.key?('xmlns') ? "xmlns:#{val.first}" : val.first
72
+ result = Node.new(:ELEMENT_NAME, [name])
73
+ }
74
+ ;
75
+ namespace
76
+ : IDENT { result = val[0] }
77
+ |
78
+ ;
79
+ attrib
80
+ : LSQUARE attrib_name attrib_val_0or1 RSQUARE {
81
+ result = Node.new(:ATTRIBUTE_CONDITION,
82
+ [val[1]] + (val[2] || [])
83
+ )
84
+ }
85
+ | LSQUARE function attrib_val_0or1 RSQUARE {
86
+ result = Node.new(:ATTRIBUTE_CONDITION,
87
+ [val[1]] + (val[2] || [])
88
+ )
89
+ }
90
+ | LSQUARE NUMBER RSQUARE {
91
+ # Non standard, but hpricot supports it.
92
+ result = Node.new(:PSEUDO_CLASS,
93
+ [Node.new(:FUNCTION, ['nth-child(', val[1]])]
94
+ )
95
+ }
96
+ ;
97
+ attrib_name
98
+ : namespace '|' IDENT {
99
+ result = Node.new(:ELEMENT_NAME,
100
+ [[val.first, val.last].compact.join(':')]
101
+ )
102
+ }
103
+ | IDENT {
104
+ # Default namespace is not applied to attributes.
105
+ # So we don't add prefix "xmlns:" as in namespaced_ident.
106
+ result = Node.new(:ELEMENT_NAME, [val.first])
107
+ }
108
+ ;
109
+ function
110
+ : FUNCTION RPAREN {
111
+ result = Node.new(:FUNCTION, [val.first.strip])
112
+ }
113
+ | FUNCTION expr RPAREN {
114
+ result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
115
+ }
116
+ | FUNCTION nth RPAREN {
117
+ result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
118
+ }
119
+ | NOT expr RPAREN {
120
+ result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
121
+ }
122
+ | HAS selector RPAREN {
123
+ result = Node.new(:FUNCTION, [val.first.strip, val[1]].flatten)
124
+ }
125
+ ;
126
+ expr
127
+ : NUMBER COMMA expr { result = [val.first, val.last] }
128
+ | STRING COMMA expr { result = [val.first, val.last] }
129
+ | IDENT COMMA expr { result = [val.first, val.last] }
130
+ | NUMBER
131
+ | STRING
132
+ | IDENT # even, odd
133
+ {
134
+ case val[0]
135
+ when 'even'
136
+ result = Node.new(:NTH, ['2','n','+','0'])
137
+ when 'odd'
138
+ result = Node.new(:NTH, ['2','n','+','1'])
139
+ when 'n'
140
+ result = Node.new(:NTH, ['1','n','+','0'])
141
+ else
142
+ # This is not CSS standard. It allows us to support this:
143
+ # assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)'))
144
+ # assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))
145
+ # assert_xpath("//a[foo(., a, 10)]", @parser.parse('a:foo(a, 10)'))
146
+ result = val
147
+ end
148
+ }
149
+ ;
150
+ nth
151
+ : NUMBER IDENT PLUS NUMBER # 5n+3 -5n+3
152
+ {
153
+ if val[1] == 'n'
154
+ result = Node.new(:NTH, val)
155
+ else
156
+ raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
157
+ end
158
+ }
159
+ | IDENT PLUS NUMBER { # n+3, -n+3
160
+ if val[0] == 'n'
161
+ val.unshift("1")
162
+ result = Node.new(:NTH, val)
163
+ elsif val[0] == '-n'
164
+ val[0] = 'n'
165
+ val.unshift("-1")
166
+ result = Node.new(:NTH, val)
167
+ else
168
+ raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
169
+ end
170
+ }
171
+ | NUMBER IDENT { # 5n, -5n, 10n-1
172
+ n = val[1]
173
+ if n[0, 2] == 'n-'
174
+ val[1] = 'n'
175
+ val << "-"
176
+ # b is contained in n as n is the string "n-b"
177
+ val << n[2, n.size]
178
+ result = Node.new(:NTH, val)
179
+ elsif n == 'n'
180
+ val << "+"
181
+ val << "0"
182
+ result = Node.new(:NTH, val)
183
+ else
184
+ raise Racc::ParseError, "parse error on IDENT '#{val[1]}'"
185
+ end
186
+ }
187
+ ;
188
+ pseudo
189
+ : ':' function {
190
+ result = Node.new(:PSEUDO_CLASS, [val[1]])
191
+ }
192
+ | ':' IDENT { result = Node.new(:PSEUDO_CLASS, [val[1]]) }
193
+ ;
194
+ hcap_0toN
195
+ : hcap_1toN
196
+ |
197
+ ;
198
+ hcap_1toN
199
+ : attribute_id hcap_1toN {
200
+ result = Node.new(:COMBINATOR, val)
201
+ }
202
+ | class hcap_1toN {
203
+ result = Node.new(:COMBINATOR, val)
204
+ }
205
+ | attrib hcap_1toN {
206
+ result = Node.new(:COMBINATOR, val)
207
+ }
208
+ | pseudo hcap_1toN {
209
+ result = Node.new(:COMBINATOR, val)
210
+ }
211
+ | negation hcap_1toN {
212
+ result = Node.new(:COMBINATOR, val)
213
+ }
214
+ | attribute_id
215
+ | class
216
+ | attrib
217
+ | pseudo
218
+ | negation
219
+ ;
220
+ attribute_id
221
+ : HASH { result = Node.new(:ID, val) }
222
+ ;
223
+ attrib_val_0or1
224
+ : eql_incl_dash IDENT { result = [val.first, val[1]] }
225
+ | eql_incl_dash STRING { result = [val.first, val[1]] }
226
+ |
227
+ ;
228
+ eql_incl_dash
229
+ : EQUAL { result = :equal }
230
+ | PREFIXMATCH { result = :prefix_match }
231
+ | SUFFIXMATCH { result = :suffix_match }
232
+ | SUBSTRINGMATCH { result = :substring_match }
233
+ | NOT_EQUAL { result = :not_equal }
234
+ | INCLUDES { result = :includes }
235
+ | DASHMATCH { result = :dash_match }
236
+ ;
237
+ negation
238
+ : NOT negation_arg RPAREN {
239
+ result = Node.new(:NOT, [val[1]])
240
+ }
241
+ ;
242
+ negation_arg
243
+ : element_name
244
+ | element_name hcap_1toN
245
+ | hcap_1toN
246
+ ;
247
+ optional_S
248
+ : S
249
+ |
250
+ ;
251
+ end
252
+
253
+ ---- header
254
+
255
+ require 'nokogiri/css/parser_extras'
@@ -6,10 +6,10 @@ class A
6
6
  rule
7
7
  targ: operation voidhead
8
8
  | variable
9
-
9
+
10
10
  voidhead : void B
11
11
  void:
12
-
12
+
13
13
  operation: A
14
14
  variable : A
15
15
  end
@@ -0,0 +1,1807 @@
1
+ # Copyright (C) 2013 by Adam Beynon
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ class Opal::Parser
22
+
23
+ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
24
+ kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
25
+ kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kDO_LAMBDA kRETURN kYIELD kSUPER
26
+ kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
27
+ kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
28
+ k__FILE__ k__ENCODING__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT
29
+ tLABEL tCVAR tNTH_REF tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT
30
+ tREGEXP_END tUPLUS tUMINUS tUMINUS_NUM tPOW tCMP tEQ tEQQ tNEQ tGEQ tLEQ tANDOP
31
+ tOROP tMATCH tNMATCH tJSDOT tDOT tDOT2 tDOT3 tAREF tASET tLSHFT tRSHFT
32
+ tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN tLPAREN2 tRPAREN tLPAREN_ARG
33
+ ARRAY_BEG tRBRACK tLBRACE tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2
34
+ tTILDE tPERCENT tDIVIDE tPLUS tMINUS tLT tGT tPIPE tBANG tCARET
35
+ tLCURLY tRCURLY tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
36
+ tWORDS_BEG tAWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END tSTRING
37
+ tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA tLAMBEG
38
+ tLBRACK2 tLBRACK tJSLBRACK tDSTAR
39
+
40
+ prechigh
41
+ right tBANG tTILDE tUPLUS
42
+ right tPOW
43
+ right tUMINUS_NUM tUMINUS
44
+ left tSTAR2 tDIVIDE tPERCENT
45
+ left tPLUS tMINUS
46
+ left tLSHFT tRSHFT
47
+ left tAMPER2
48
+ left tPIPE tCARET
49
+ left tGT tGEQ tLT tLEQ
50
+ nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
51
+ left tANDOP
52
+ left tOROP
53
+ nonassoc tDOT2 tDOT3
54
+ right tEH tCOLON
55
+ left kRESCUE_MOD
56
+ right tEQL tOP_ASGN
57
+ nonassoc kDEFINED
58
+ right kNOT
59
+ left kOR kAND
60
+ nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
61
+ nonassoc tLBRACE_ARG
62
+ nonassoc tLOWEST
63
+ preclow
64
+
65
+ rule
66
+
67
+ program: top_compstmt
68
+
69
+ top_compstmt: top_stmts opt_terms
70
+ {
71
+ result = new_compstmt val[0]
72
+ }
73
+
74
+ top_stmts: # none
75
+ {
76
+ result = new_block
77
+ }
78
+ | top_stmt
79
+ {
80
+ result = new_block val[0]
81
+ }
82
+ | top_stmts terms top_stmt
83
+ {
84
+ val[0] << val[2]
85
+ result = val[0]
86
+ }
87
+
88
+ top_stmt: stmt
89
+ | klBEGIN tLCURLY top_compstmt tRCURLY
90
+ {
91
+ result = val[2]
92
+ }
93
+
94
+ bodystmt: compstmt opt_rescue opt_else opt_ensure
95
+ {
96
+ result = new_body(val[0], val[1], val[2], val[3])
97
+ }
98
+
99
+ compstmt: stmts opt_terms
100
+ {
101
+ result = new_compstmt val[0]
102
+ }
103
+
104
+ stmts: # none
105
+ {
106
+ result = new_block
107
+ }
108
+ | stmt
109
+ {
110
+ result = new_block val[0]
111
+ }
112
+ | stmts terms stmt
113
+ {
114
+ val[0] << val[2]
115
+ result = val[0]
116
+ }
117
+
118
+ stmt: kALIAS fitem
119
+ {
120
+ lexer.lex_state = :expr_fname
121
+ }
122
+ fitem
123
+ {
124
+ result = new_alias(val[0], val[1], val[3])
125
+ }
126
+ | kALIAS tGVAR tGVAR
127
+ {
128
+ result = s(:valias, value(val[1]).to_sym, value(val[2]).to_sym)
129
+ }
130
+ | kALIAS tGVAR tBACK_REF
131
+ | kALIAS tGVAR tNTH_REF
132
+ {
133
+ result = s(:valias, value(val[1]).to_sym, value(val[2]).to_sym)
134
+ }
135
+ | kUNDEF undef_list
136
+ {
137
+ result = val[1]
138
+ }
139
+ | stmt kIF_MOD expr_value
140
+ {
141
+ result = new_if(val[1], val[2], val[0], nil)
142
+ }
143
+ | stmt kUNLESS_MOD expr_value
144
+ {
145
+ result = new_if(val[1], val[2], nil, val[0])
146
+ }
147
+ | stmt kWHILE_MOD expr_value
148
+ {
149
+ result = new_while(val[1], val[2], val[0])
150
+ }
151
+ | stmt kUNTIL_MOD expr_value
152
+ {
153
+ result = new_until(val[1], val[2], val[0])
154
+ }
155
+ | stmt kRESCUE_MOD stmt
156
+ {
157
+ result = new_rescue_mod(val[1], val[0], val[2])
158
+ }
159
+ | klEND tLCURLY compstmt tRCURLY
160
+ | lhs tEQL command_call
161
+ {
162
+ result = new_assign(val[0], val[1], val[2])
163
+ }
164
+ | mlhs tEQL command_call
165
+ {
166
+ result = s(:masgn, val[0], s(:to_ary, val[2]))
167
+ }
168
+ | var_lhs tOP_ASGN command_call
169
+ {
170
+ result = new_op_asgn val[1], val[0], val[2]
171
+ }
172
+ | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN command_call
173
+ | primary_value tJSLBRACK aref_args tRBRACK tOP_ASGN command_call
174
+ | primary_value tDOT tIDENTIFIER tOP_ASGN command_call
175
+ {
176
+ result = s(:op_asgn2, val[0], op_to_setter(val[2]), value(val[3]).to_sym, val[4])
177
+ }
178
+ | primary_value tDOT tCONSTANT tOP_ASGN command_call
179
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
180
+ | backref tOP_ASGN command_call
181
+ | lhs tEQL mrhs
182
+ {
183
+ result = new_assign val[0], val[1], s(:svalue, val[2])
184
+ }
185
+ | mlhs tEQL arg_value
186
+ {
187
+ result = s(:masgn, val[0], s(:to_ary, val[2]))
188
+ }
189
+ | mlhs tEQL mrhs
190
+ {
191
+ result = s(:masgn, val[0], val[2])
192
+ }
193
+ | expr
194
+
195
+ expr: command_call
196
+ | expr kAND expr
197
+ {
198
+ result = s(:and, val[0], val[2])
199
+ }
200
+ | expr kOR expr
201
+ {
202
+ result = s(:or, val[0], val[2])
203
+ }
204
+ | kNOT expr
205
+ {
206
+ result = new_unary_call(['!', []], val[1])
207
+ }
208
+ | tBANG command_call
209
+ {
210
+ result = new_unary_call(val[0], val[1])
211
+ }
212
+ | arg
213
+
214
+ expr_value: expr
215
+
216
+ command_call: command
217
+ | block_command
218
+ | kRETURN call_args
219
+ {
220
+ result = new_return(val[0], val[1])
221
+ }
222
+ | kBREAK call_args
223
+ {
224
+ result = new_break(val[0], val[1])
225
+ }
226
+ | kNEXT call_args
227
+ {
228
+ result = new_next(val[0], val[1])
229
+ }
230
+
231
+ block_command: block_call
232
+ | block_call tJSDOT operation2 command_args
233
+ | block_call tDOT operation2 command_args
234
+ | block_call tCOLON2 operation2 command_args
235
+
236
+ cmd_brace_block: tLBRACE_ARG opt_block_var compstmt tRCURLY
237
+
238
+ command: operation command_args =tLOWEST
239
+ {
240
+ result = new_call(nil, val[0], val[1])
241
+ }
242
+ | operation command_args cmd_brace_block
243
+ | primary_value tJSDOT operation2 command_args =tLOWEST
244
+ {
245
+ result = new_js_call(val[0], val[2], val[3])
246
+ }
247
+ | primary_value tJSDOT operation2 command_args cmd_brace_block
248
+ | primary_value tDOT operation2 command_args =tLOWEST
249
+ {
250
+ result = new_call(val[0], val[2], val[3])
251
+ }
252
+ | primary_value tDOT operation2 command_args cmd_brace_block
253
+ | primary_value tCOLON2 operation2 command_args =tLOWEST
254
+ {
255
+ result = new_call(val[0], val[2], val[3])
256
+ }
257
+ | primary_value tCOLON2 operation2 command_args cmd_brace_block
258
+ | kSUPER command_args
259
+ {
260
+ result = new_super(val[0], val[1])
261
+ }
262
+ | kYIELD command_args
263
+ {
264
+ result = new_yield val[1]
265
+ }
266
+
267
+ mlhs: mlhs_basic
268
+ {
269
+ result = val[0]
270
+ }
271
+ | tLPAREN mlhs_entry tRPAREN
272
+ {
273
+ result = val[1]
274
+ }
275
+
276
+ mlhs_entry: mlhs_basic
277
+ {
278
+ result = val[0]
279
+ }
280
+ | tLPAREN mlhs_entry tRPAREN
281
+ {
282
+ result = val[1]
283
+ }
284
+
285
+ mlhs_basic: mlhs_head
286
+ {
287
+ result = val[0]
288
+ }
289
+ | mlhs_head mlhs_item
290
+ {
291
+ result = val[0] << val[1]
292
+ }
293
+ | mlhs_head tSTAR mlhs_node
294
+ {
295
+ result = val[0] << s(:splat, val[2])
296
+ }
297
+ | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
298
+ | mlhs_head tSTAR
299
+ {
300
+ result = val[0] << s(:splat)
301
+ }
302
+ | mlhs_head tSTAR tCOMMA mlhs_post
303
+ | tSTAR mlhs_node
304
+ {
305
+ result = s(:array, s(:splat, val[1]))
306
+ }
307
+ | tSTAR
308
+ {
309
+ result = s(:array, s(:splat))
310
+ }
311
+ | tSTAR tCOMMA mlhs_post
312
+
313
+ mlhs_item: mlhs_node
314
+ {
315
+ result = val[0]
316
+ }
317
+ | tLPAREN mlhs_entry tRPAREN
318
+ {
319
+ result = val[1]
320
+ }
321
+
322
+ mlhs_head: mlhs_item tCOMMA
323
+ {
324
+ result = s(:array, val[0])
325
+ }
326
+ | mlhs_head mlhs_item tCOMMA
327
+ {
328
+ result = val[0] << val[1]
329
+ }
330
+
331
+ mlhs_post: mlhs_item
332
+ | mlhs_post tCOMMA mlhs_item
333
+
334
+ mlhs_node: variable
335
+ {
336
+ result = new_assignable val[0]
337
+ }
338
+ | primary_value tLBRACK2 aref_args tRBRACK
339
+ {
340
+ args = val[2] ? val[2] : []
341
+ result = s(:attrasgn, val[0], :[]=, s(:arglist, *args))
342
+ }
343
+ | primary_value tDOT tIDENTIFIER
344
+ {
345
+ result = new_call val[0], val[2], []
346
+ }
347
+ | primary_value tCOLON2 tIDENTIFIER
348
+ | primary_value tDOT tCONSTANT
349
+ | primary_value tCOLON2 tCONSTANT
350
+ | tCOLON3 tCONSTANT
351
+ | backref
352
+
353
+ lhs: variable
354
+ {
355
+ result = new_assignable val[0]
356
+ }
357
+ | primary_value tJSLBRACK aref_args tRBRACK
358
+ {
359
+ result = new_js_attrasgn(val[0], val[2])
360
+ }
361
+ | primary_value tLBRACK2 aref_args tRBRACK
362
+ {
363
+ result = new_attrasgn(val[0], :[]=, val[2])
364
+ }
365
+ | primary_value tDOT tIDENTIFIER
366
+ {
367
+ result = new_attrasgn(val[0], op_to_setter(val[2]))
368
+ }
369
+ | primary_value tCOLON2 tIDENTIFIER
370
+ {
371
+ result = new_attrasgn(val[0], op_to_setter(val[2]))
372
+ }
373
+ | primary_value tDOT tCONSTANT
374
+ {
375
+ result = new_attrasgn(val[0], op_to_setter(val[2]))
376
+ }
377
+ | primary_value tCOLON2 tCONSTANT
378
+ {
379
+ result = new_colon2(val[0], val[1], val[2])
380
+ }
381
+ | tCOLON3 tCONSTANT
382
+ {
383
+ result = new_colon3(val[0], val[1])
384
+ }
385
+ | backref
386
+
387
+ cname: tCONSTANT
388
+
389
+ cpath: tCOLON3 cname
390
+ {
391
+ result = new_colon3(val[0], val[1])
392
+ }
393
+ | cname
394
+ {
395
+ result = new_const(val[0])
396
+ }
397
+ | primary_value tCOLON2 cname
398
+ {
399
+ result = new_colon2(val[0], val[1], val[2])
400
+ }
401
+
402
+ fname: tIDENTIFIER
403
+ | tCONSTANT
404
+ | tFID
405
+ | op
406
+ {
407
+ lexer.lex_state = :expr_end
408
+ result = val[0]
409
+ }
410
+ | reswords
411
+ {
412
+ lexer.lex_state = :expr_end
413
+ result = val[0]
414
+ }
415
+
416
+ fitem: fname
417
+ {
418
+ result = new_sym(val[0])
419
+ }
420
+ | symbol
421
+
422
+ undef_list: fitem
423
+ {
424
+ result = s(:undef, val[0])
425
+ }
426
+ | undef_list tCOMMA fitem
427
+ {
428
+ result = val[0] << val[2]
429
+ }
430
+
431
+ op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
432
+ | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
433
+ | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
434
+ | tSTAR | tDIVIDE | tPERCENT | tPOW | tBANG | tTILDE
435
+ | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
436
+
437
+ reswords: k__LINE__ | k__FILE__ | klBEGIN | klEND | kALIAS | kAND
438
+ | kBEGIN | kBREAK | kCASE | kCLASS | kDEF | kDEFINED
439
+ | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
440
+ | kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
441
+ | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF
442
+ | kSUPER | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
443
+ | kIF_MOD | kUNLESS_MOD | kWHILE_MOD | kUNTIL_MOD | kRESCUE_MOD
444
+ | kIF | kWHILE | kUNTIL | kUNLESS
445
+
446
+ arg: lhs tEQL arg
447
+ {
448
+ result = new_assign(val[0], val[1], val[2])
449
+ }
450
+ | lhs tEQL arg kRESCUE_MOD arg
451
+ {
452
+ result = new_assign val[0], val[1], s(:rescue_mod, val[2], val[4])
453
+ }
454
+ | var_lhs tOP_ASGN arg
455
+ {
456
+ result = new_op_asgn val[1], val[0], val[2]
457
+ }
458
+ | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN arg
459
+ {
460
+ result = new_op_asgn1(val[0], val[2], val[4], val[5])
461
+ }
462
+ | primary_value tJSLBRACK aref_args tRBRACK tOP_ASGN arg
463
+ {
464
+ raise ".JS[...] #{val[4]} is not supported"
465
+ }
466
+ | primary_value tDOT tIDENTIFIER tOP_ASGN arg
467
+ {
468
+ result = s(:op_asgn2, val[0], op_to_setter(val[2]), value(val[3]).to_sym, val[4])
469
+ }
470
+ | primary_value tDOT tCONSTANT tOP_ASGN arg
471
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
472
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
473
+ | tCOLON3 tCONSTANT tOP_ASGN arg
474
+ | backref tOP_ASGN arg
475
+ | arg tDOT2 arg
476
+ {
477
+ result = new_irange(val[0], val[1], val[2])
478
+ }
479
+ | arg tDOT3 arg
480
+ {
481
+ result = new_erange(val[0], val[1], val[2])
482
+ }
483
+ | arg tPLUS arg
484
+ {
485
+ result = new_binary_call(val[0], val[1], val[2])
486
+ }
487
+ | arg tMINUS arg
488
+ {
489
+ result = new_binary_call(val[0], val[1], val[2])
490
+ }
491
+ | arg tSTAR2 arg
492
+ {
493
+ result = new_binary_call(val[0], val[1], val[2])
494
+ }
495
+ | arg tDIVIDE arg
496
+ {
497
+ result = new_binary_call(val[0], val[1], val[2])
498
+ }
499
+ | arg tPERCENT arg
500
+ {
501
+ result = new_binary_call(val[0], val[1], val[2])
502
+ }
503
+ | arg tPOW arg
504
+ {
505
+ result = new_binary_call(val[0], val[1], val[2])
506
+ }
507
+ | '-@NUM' tINTEGER tPOW arg
508
+ {
509
+ result = new_call new_binary_call(new_int(val[1]), val[2], val[3]), [:"-@", []], []
510
+ }
511
+ | '-@NUM' tFLOAT tPOW arg
512
+ {
513
+ result = new_call new_binary_call(new_float(val[1]), val[2], val[3]), [:"-@", []], []
514
+ }
515
+ | tUPLUS arg
516
+ {
517
+ result = new_call val[1], [:"+@", []], []
518
+ if [:int, :float].include? val[1].type
519
+ result = val[1]
520
+ end
521
+ }
522
+ | tUMINUS arg
523
+ {
524
+ result = new_call val[1], [:"-@", []], []
525
+ if val[1].type == :int
526
+ val[1][1] = -val[1][1]
527
+ result = val[1]
528
+ elsif val[1].type == :float
529
+ val[1][1] = -val[1][1].to_f
530
+ result = val[1]
531
+ end
532
+ }
533
+ | arg tPIPE arg
534
+ {
535
+ result = new_binary_call(val[0], val[1], val[2])
536
+ }
537
+ | arg tCARET arg
538
+ {
539
+ result = new_binary_call(val[0], val[1], val[2])
540
+ }
541
+ | arg tAMPER2 arg
542
+ {
543
+ result = new_binary_call(val[0], val[1], val[2])
544
+ }
545
+ | arg tCMP arg
546
+ {
547
+ result = new_binary_call(val[0], val[1], val[2])
548
+ }
549
+ | arg tGT arg
550
+ {
551
+ result = new_binary_call(val[0], val[1], val[2])
552
+ }
553
+ | arg tGEQ arg
554
+ {
555
+ result = new_binary_call(val[0], val[1], val[2])
556
+ }
557
+ | arg tLT arg
558
+ {
559
+ result = new_binary_call(val[0], val[1], val[2])
560
+ }
561
+ | arg tLEQ arg
562
+ {
563
+ result = new_binary_call(val[0], val[1], val[2])
564
+ }
565
+ | arg tEQ arg
566
+ {
567
+ result = new_binary_call(val[0], val[1], val[2])
568
+ }
569
+ | arg tEQQ arg
570
+ {
571
+ result = new_binary_call(val[0], val[1], val[2])
572
+ }
573
+ | arg tNEQ arg
574
+ {
575
+ result = new_binary_call(val[0], val[1], val[2])
576
+ }
577
+ | arg tMATCH arg
578
+ {
579
+ result = new_binary_call(val[0], val[1], val[2])
580
+ }
581
+ | arg tNMATCH arg
582
+ {
583
+ result = new_binary_call(val[0], val[1], val[2])
584
+ }
585
+ | tBANG arg
586
+ {
587
+ result = new_unary_call(val[0], val[1])
588
+ }
589
+ | tTILDE arg
590
+ {
591
+ result = new_unary_call(val[0], val[1])
592
+ }
593
+ | arg tLSHFT arg
594
+ {
595
+ result = new_binary_call(val[0], val[1], val[2])
596
+ }
597
+ | arg tRSHFT arg
598
+ {
599
+ result = new_binary_call(val[0], val[1], val[2])
600
+ }
601
+ | arg tANDOP arg
602
+ {
603
+ result = new_and(val[0], val[1], val[2])
604
+ }
605
+ | arg tOROP arg
606
+ {
607
+ result = new_or(val[0], val[1], val[2])
608
+ }
609
+ | kDEFINED opt_nl arg
610
+ {
611
+ result = s(:defined, val[2])
612
+ }
613
+ | arg tEH arg tCOLON arg
614
+ {
615
+ result = new_if(val[1], val[0], val[2], val[4])
616
+ }
617
+ | primary
618
+
619
+ arg_value: arg
620
+
621
+ aref_args: none
622
+ {
623
+ result = nil
624
+ }
625
+ | command opt_nl
626
+ {
627
+ result = [val[0]]
628
+ }
629
+ | args trailer
630
+ {
631
+ result = val[0]
632
+ }
633
+ | args tCOMMA assocs trailer
634
+ {
635
+ val[0] << s(:hash, *val[2])
636
+ result = val[0]
637
+ }
638
+ | assocs trailer
639
+ {
640
+ result = [s(:hash, *val[0])]
641
+ }
642
+
643
+ paren_args: tLPAREN2 opt_call_args rparen
644
+ {
645
+ result = val[1]
646
+ }
647
+
648
+ rparen: opt_nl tRPAREN
649
+
650
+ opt_paren_args: none
651
+ {
652
+ result = []
653
+ }
654
+ | paren_args
655
+
656
+ opt_call_args: none
657
+ {
658
+ result = []
659
+ }
660
+ | call_args
661
+ | args tCOMMA
662
+ {
663
+ result = val[0]
664
+ }
665
+ | args tCOMMA assocs tCOMMA
666
+ {
667
+ result = val[0]
668
+ result << new_hash(nil, val[2], nil)
669
+ }
670
+ | assocs tCOMMA
671
+ {
672
+ result = [new_hash(nil, val[0], nil)]
673
+ }
674
+
675
+ call_args: command
676
+ {
677
+ result = [val[0]]
678
+ }
679
+ | args opt_block_arg
680
+ {
681
+ result = val[0]
682
+ add_block_pass val[0], val[1]
683
+ }
684
+ | assocs opt_block_arg
685
+ {
686
+ result = [new_hash(nil, val[0], nil)]
687
+ add_block_pass result, val[1]
688
+ }
689
+ | args tCOMMA assocs opt_block_arg
690
+ {
691
+ result = val[0]
692
+ result << new_hash(nil, val[2], nil)
693
+ result << val[3] if val[3]
694
+ }
695
+ | block_arg
696
+ {
697
+ result = []
698
+ add_block_pass result, val[0]
699
+ }
700
+
701
+ call_args2: arg_value tCOMMA args opt_block_arg
702
+ | block_arg
703
+
704
+ command_args: {
705
+ lexer.cmdarg_push 1
706
+ }
707
+ open_args
708
+ {
709
+ lexer.cmdarg_pop
710
+ result = val[1]
711
+ }
712
+
713
+ open_args: call_args
714
+ | tLPAREN_ARG tRPAREN
715
+ {
716
+ result = nil
717
+ }
718
+ | tLPAREN_ARG call_args2 tRPAREN
719
+ {
720
+ result = val[1]
721
+ }
722
+
723
+ block_arg: tAMPER arg_value
724
+ {
725
+ result = new_block_pass(val[0], val[1])
726
+ }
727
+
728
+ opt_block_arg: tCOMMA block_arg
729
+ {
730
+ result = val[1]
731
+ }
732
+ | # none
733
+ {
734
+ result = nil
735
+ }
736
+
737
+ args: arg_value
738
+ {
739
+ result = [val[0]]
740
+ }
741
+ | tSTAR arg_value
742
+ {
743
+ result = [new_splat(val[0], val[1])]
744
+ }
745
+ | args tCOMMA arg_value
746
+ {
747
+ result = val[0] << val[2]
748
+ }
749
+ | args tCOMMA tSTAR arg_value
750
+ {
751
+ result = val[0] << new_splat(val[2], val[3])
752
+ }
753
+
754
+ mrhs: args tCOMMA arg_value
755
+ {
756
+ val[0] << val[2]
757
+ result = s(:array, *val[0])
758
+ }
759
+ | args tCOMMA tSTAR arg_value
760
+ {
761
+ val[0] << s(:splat, val[3])
762
+ result = s(:array, *val[0])
763
+ }
764
+ | tSTAR arg_value
765
+ {
766
+ result = s(:splat, val[1])
767
+ }
768
+
769
+ primary: literal
770
+ | strings
771
+ | xstring
772
+ | regexp
773
+ | words
774
+ | awords
775
+ | var_ref
776
+ | backref
777
+ | tFID
778
+ | kBEGIN
779
+ {
780
+ result = lexer.line
781
+ }
782
+ bodystmt kEND
783
+ {
784
+ result = s(:begin, val[2])
785
+ }
786
+ | tLPAREN_ARG expr opt_nl tRPAREN
787
+ {
788
+ result = val[1]
789
+ }
790
+ | tLPAREN compstmt tRPAREN
791
+ {
792
+ result = new_paren(val[0], val[1], val[2])
793
+ }
794
+ | primary_value tCOLON2 tCONSTANT
795
+ {
796
+ result = new_colon2(val[0], val[1], val[2])
797
+ }
798
+ | tCOLON3 tCONSTANT
799
+ {
800
+ result = new_colon3(val[0], val[1])
801
+ }
802
+ | primary_value tLBRACK2 aref_args tRBRACK
803
+ {
804
+ result = new_call val[0], [:[], []], val[2]
805
+ }
806
+ | primary_value tJSLBRACK aref_args tRBRACK
807
+ {
808
+ result = new_js_call val[0], [:[], []], val[2]
809
+ }
810
+ | tLBRACK aref_args tRBRACK
811
+ {
812
+ result = new_array(val[0], val[1], val[2])
813
+ }
814
+ | tLBRACE assoc_list tRCURLY
815
+ {
816
+ result = new_hash(val[0], val[1], val[2])
817
+ }
818
+ | kRETURN
819
+ {
820
+ result = new_return(val[0])
821
+ }
822
+ | kYIELD tLPAREN2 call_args tRPAREN
823
+ {
824
+ result = new_yield val[2]
825
+ }
826
+ | kYIELD tLPAREN2 tRPAREN
827
+ {
828
+ result = s(:yield)
829
+ }
830
+ | kYIELD
831
+ {
832
+ result = s(:yield)
833
+ }
834
+ | kDEFINED opt_nl tLPAREN2 expr tRPAREN
835
+ {
836
+ result = s(:defined, val[3])
837
+ }
838
+ | kNOT tLPAREN2 expr tRPAREN
839
+ {
840
+ result = new_unary_call(['!', []], val[2])
841
+ }
842
+ | kNOT tLPAREN2 tRPAREN
843
+ {
844
+ result = new_unary_call(['!', []], new_nil(val[0]))
845
+ }
846
+ | operation brace_block
847
+ {
848
+ result = new_call(nil, val[0], [])
849
+ result << val[1]
850
+ }
851
+ | method_call
852
+ | method_call brace_block
853
+ {
854
+ val[0] << val[1]
855
+ result = val[0]
856
+ }
857
+ | tLAMBDA lambda
858
+ {
859
+ result = val[1]
860
+ }
861
+ | kIF expr_value then compstmt if_tail kEND
862
+ {
863
+ result = new_if(val[0], val[1], val[3], val[4])
864
+ }
865
+ | kUNLESS expr_value then compstmt opt_else kEND
866
+ {
867
+ result = new_if(val[0], val[1], val[4], val[3])
868
+ }
869
+ | kWHILE
870
+ {
871
+ lexer.cond_push 1
872
+ result = lexer.line
873
+ }
874
+ expr_value do
875
+ {
876
+ lexer.cond_pop
877
+ }
878
+ compstmt kEND
879
+ {
880
+ result = s(:while, val[2], val[5])
881
+ }
882
+ | kUNTIL
883
+ {
884
+ lexer.cond_push 1
885
+ result = lexer.line
886
+ }
887
+ expr_value do
888
+ {
889
+ lexer.cond_pop
890
+ }
891
+ compstmt kEND
892
+ {
893
+ result = s(:until, val[2], val[5])
894
+ }
895
+ | kCASE expr_value opt_terms case_body kEND
896
+ {
897
+ result = s(:case, val[1], *val[3])
898
+ }
899
+ | kCASE opt_terms case_body kEND
900
+ {
901
+ result = s(:case, nil, *val[2])
902
+ }
903
+ | kCASE opt_terms kELSE compstmt kEND
904
+ {
905
+ result = s(:case, nil, val[3])
906
+ }
907
+ | kFOR for_var kIN
908
+ {
909
+ lexer.cond_push 1
910
+ result = lexer.line
911
+ }
912
+ expr_value do
913
+ {
914
+ lexer.cond_pop
915
+ }
916
+ compstmt kEND
917
+ {
918
+ result = s(:for, val[4], val[1], val[7])
919
+ }
920
+ | kCLASS cpath superclass
921
+ {
922
+ # ...
923
+ }
924
+ bodystmt kEND
925
+ {
926
+ result = new_class val[0], val[1], val[2], val[4], val[5]
927
+ }
928
+ | kCLASS tLSHFT
929
+ {
930
+ result = lexer.line
931
+ }
932
+ expr term
933
+ {
934
+ # ...
935
+ }
936
+ bodystmt kEND
937
+ {
938
+ result = new_sclass(val[0], val[3], val[6], val[7])
939
+ }
940
+ | kMODULE
941
+ {
942
+ result = lexer.line
943
+ }
944
+ cpath
945
+ {
946
+ # ...
947
+ }
948
+ bodystmt kEND
949
+ {
950
+ result = new_module(val[0], val[2], val[4], val[5])
951
+ }
952
+ | kDEF fname
953
+ {
954
+ push_scope
955
+ lexer.lex_state = :expr_endfn
956
+ }
957
+ f_arglist bodystmt kEND
958
+ {
959
+ result = new_def(val[0], nil, val[1], val[3], val[4], val[5])
960
+ pop_scope
961
+ }
962
+ | kDEF singleton dot_or_colon
963
+ {
964
+ lexer.lex_state = :expr_fname
965
+ }
966
+ fname
967
+ {
968
+ push_scope
969
+ lexer.lex_state = :expr_endfn
970
+ }
971
+ f_arglist bodystmt kEND
972
+ {
973
+ result = new_def(val[0], val[1], val[4], val[6], val[7], val[8])
974
+ pop_scope
975
+ }
976
+ | kBREAK
977
+ {
978
+ result = new_break(val[0])
979
+ }
980
+ | kNEXT
981
+ {
982
+ result = s(:next)
983
+ }
984
+ | kREDO
985
+ {
986
+ result = s(:redo)
987
+ }
988
+ | kRETRY
989
+
990
+ primary_value: primary
991
+
992
+ then: term
993
+ | tCOLON
994
+ | kTHEN
995
+ | term kTHEN
996
+
997
+ do: term
998
+ | tCOLON
999
+ | kDO_COND
1000
+
1001
+ lambda: f_larglist lambda_body
1002
+ {
1003
+ result = new_call nil, [:lambda, []], []
1004
+ result << new_iter(val[0], val[1])
1005
+ }
1006
+
1007
+ f_larglist: tLPAREN2 block_param tRPAREN
1008
+ {
1009
+ result = val[1]
1010
+ }
1011
+ | tLPAREN2 tRPAREN
1012
+ {
1013
+ result = nil
1014
+ }
1015
+ | block_param
1016
+ | none
1017
+
1018
+ lambda_body: tLAMBEG compstmt tRCURLY
1019
+ {
1020
+ result = val[1]
1021
+ }
1022
+ | kDO_LAMBDA compstmt kEND
1023
+ {
1024
+ result = val[1]
1025
+ }
1026
+
1027
+ if_tail: opt_else
1028
+ {
1029
+ result = val[0]
1030
+ }
1031
+ | kELSIF expr_value then compstmt if_tail
1032
+ {
1033
+ result = new_if(val[0], val[1], val[3], val[4])
1034
+ }
1035
+
1036
+ opt_else: none
1037
+ | kELSE compstmt
1038
+ {
1039
+ result = val[1]
1040
+ }
1041
+
1042
+ f_block_optarg: f_block_opt
1043
+ {
1044
+ result = s(:block, val[0])
1045
+ }
1046
+ | f_block_optarg tCOMMA f_block_opt
1047
+ {
1048
+ val[0] << val[2]
1049
+ result = val[0]
1050
+ }
1051
+
1052
+ f_block_opt: tIDENTIFIER tEQL primary_value
1053
+ {
1054
+ result = new_assign(new_assignable(new_ident(
1055
+ val[0])), val[1], val[2])
1056
+ }
1057
+
1058
+ opt_block_var: none
1059
+ | tPIPE tPIPE
1060
+ {
1061
+ result = nil
1062
+ }
1063
+ | tOROP
1064
+ {
1065
+ result = nil
1066
+ }
1067
+ | tPIPE block_param tPIPE
1068
+ {
1069
+ result = val[1]
1070
+ }
1071
+
1072
+ block_args_tail: f_block_arg
1073
+ {
1074
+ result = val[0]
1075
+ }
1076
+
1077
+ opt_block_args_tail: tCOMMA block_args_tail
1078
+ {
1079
+ result = val[1]
1080
+ }
1081
+ | none
1082
+ {
1083
+ nil
1084
+ }
1085
+
1086
+ block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1087
+ {
1088
+ result = new_block_args(val[0], val[2], val[4], val[5])
1089
+ }
1090
+ | f_arg tCOMMA f_block_optarg opt_block_args_tail
1091
+ {
1092
+ result = new_block_args(val[0], val[2], nil, val[3])
1093
+ }
1094
+ | f_arg tCOMMA f_rest_arg opt_block_args_tail
1095
+ {
1096
+ result = new_block_args(val[0], nil, val[2], val[3])
1097
+ }
1098
+ | f_arg tCOMMA
1099
+ {
1100
+ result = new_block_args(val[0], nil, nil, nil)
1101
+ }
1102
+ | f_arg opt_block_args_tail
1103
+ {
1104
+ result = new_block_args(val[0], nil, nil, val[1])
1105
+ }
1106
+ | f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1107
+ {
1108
+ result = new_block_args(nil, val[0], val[2], val[3])
1109
+ }
1110
+ | f_block_optarg opt_block_args_tail
1111
+ {
1112
+ result = new_block_args(nil, val[0], nil, val[1])
1113
+ }
1114
+ | f_rest_arg opt_block_args_tail
1115
+ {
1116
+ result = new_block_args(nil, nil, val[0], val[1])
1117
+ }
1118
+ | block_args_tail
1119
+ {
1120
+ result = new_block_args(nil, nil, nil, val[0])
1121
+ }
1122
+
1123
+ do_block: kDO_BLOCK
1124
+ {
1125
+ push_scope :block
1126
+ result = lexer.line
1127
+ }
1128
+ opt_block_var compstmt kEND
1129
+ {
1130
+ result = new_iter val[2], val[3]
1131
+ pop_scope
1132
+ }
1133
+
1134
+ block_call: command do_block
1135
+ {
1136
+ val[0] << val[1]
1137
+ result = val[0]
1138
+ }
1139
+ | block_call tJSDOT operation2 opt_paren_args
1140
+ | block_call tDOT operation2 opt_paren_args
1141
+ | block_call tCOLON2 operation2 opt_paren_args
1142
+
1143
+ method_call: operation paren_args
1144
+ {
1145
+ result = new_call(nil, val[0], val[1])
1146
+ }
1147
+ | primary_value tDOT operation2 opt_paren_args
1148
+ {
1149
+ result = new_call(val[0], val[2], val[3])
1150
+ }
1151
+ | primary_value tJSDOT operation2 opt_paren_args
1152
+ {
1153
+ result = new_js_call(val[0], val[2], val[3])
1154
+ }
1155
+ | primary_value tDOT paren_args
1156
+ {
1157
+ result = new_call(val[0], [:call, []], val[2])
1158
+ }
1159
+ | primary_value tCOLON2 operation2 paren_args
1160
+ {
1161
+ result = new_call(val[0], val[2], val[3])
1162
+ }
1163
+ | primary_value tCOLON2 operation3
1164
+ {
1165
+ result = new_call(val[0], val[2])
1166
+ }
1167
+ | kSUPER paren_args
1168
+ {
1169
+ result = new_super(val[0], val[1])
1170
+ }
1171
+ | kSUPER
1172
+ {
1173
+ result = new_super(val[0], nil)
1174
+ }
1175
+
1176
+ brace_block: tLCURLY
1177
+ {
1178
+ push_scope :block
1179
+ result = lexer.line
1180
+ }
1181
+ opt_block_var compstmt tRCURLY
1182
+ {
1183
+ result = new_iter val[2], val[3]
1184
+ pop_scope
1185
+ }
1186
+ | kDO
1187
+ {
1188
+ push_scope :block
1189
+ result = lexer.line
1190
+ }
1191
+ opt_block_var compstmt kEND
1192
+ {
1193
+ result = new_iter val[2], val[3]
1194
+ pop_scope
1195
+ }
1196
+
1197
+ case_body: kWHEN
1198
+ {
1199
+ result = lexer.line
1200
+ }
1201
+ args then compstmt cases
1202
+ {
1203
+ part = s(:when, s(:array, *val[2]), val[4])
1204
+ result = [part]
1205
+ result.push(*val[5]) if val[5]
1206
+ }
1207
+
1208
+ cases: opt_else
1209
+ {
1210
+ result = [val[0]]
1211
+ }
1212
+ | case_body
1213
+
1214
+ opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
1215
+ {
1216
+ exc = val[1] || s(:array)
1217
+ exc << new_assign(val[2], val[2], s(:gvar, '$!'.intern)) if val[2]
1218
+ result = [s(:resbody, exc, val[4])]
1219
+ result.push val[5].first if val[5]
1220
+ }
1221
+ | # none
1222
+ {
1223
+ result = nil
1224
+ }
1225
+
1226
+ exc_list: arg_value
1227
+ {
1228
+ result = s(:array, val[0])
1229
+ }
1230
+ | mrhs
1231
+ | none
1232
+
1233
+ exc_var: tASSOC lhs
1234
+ {
1235
+ result = val[1]
1236
+ }
1237
+ | none
1238
+ {
1239
+ result = nil
1240
+ }
1241
+
1242
+ opt_ensure: kENSURE compstmt
1243
+ {
1244
+ result = val[1].nil? ? s(:nil) : val[1]
1245
+ }
1246
+ | none
1247
+
1248
+ literal: numeric
1249
+ | symbol
1250
+ | dsym
1251
+
1252
+ strings: string
1253
+ {
1254
+ result = new_str val[0]
1255
+ }
1256
+
1257
+ string: string1
1258
+ | string string1
1259
+ {
1260
+ result = str_append val[0], val[1]
1261
+ }
1262
+
1263
+ string1: tSTRING_BEG string_contents tSTRING_END
1264
+ {
1265
+ result = val[1]
1266
+ }
1267
+ | tSTRING
1268
+ {
1269
+ result = s(:str, value(val[0]))
1270
+ }
1271
+
1272
+ xstring: tXSTRING_BEG xstring_contents tSTRING_END
1273
+ {
1274
+ result = new_xstr(val[0], val[1], val[2])
1275
+ }
1276
+
1277
+ regexp: tREGEXP_BEG xstring_contents tREGEXP_END
1278
+ {
1279
+ result = new_regexp val[1], val[2]
1280
+ }
1281
+
1282
+ words: tWORDS_BEG tSPACE tSTRING_END
1283
+ {
1284
+ result = s(:array)
1285
+ }
1286
+ | tWORDS_BEG word_list tSTRING_END
1287
+ {
1288
+ result = val[1]
1289
+ }
1290
+
1291
+ word_list: none
1292
+ {
1293
+ result = s(:array)
1294
+ }
1295
+ | word_list word tSPACE
1296
+ {
1297
+ part = val[1]
1298
+ part = s(:dstr, "", val[1]) if part.type == :evstr
1299
+ result = val[0] << part
1300
+ }
1301
+
1302
+ word: string_content
1303
+ {
1304
+ result = val[0]
1305
+ }
1306
+ | word string_content
1307
+ {
1308
+ result = val[0].concat([val[1]])
1309
+ }
1310
+
1311
+ awords: tAWORDS_BEG tSPACE tSTRING_END
1312
+ {
1313
+ result = s(:array)
1314
+ }
1315
+ | tAWORDS_BEG qword_list tSTRING_END
1316
+ {
1317
+ result = val[1]
1318
+ }
1319
+
1320
+ qword_list: none
1321
+ {
1322
+ result = s(:array)
1323
+ }
1324
+ | qword_list tSTRING_CONTENT tSPACE
1325
+ {
1326
+ result = val[0] << s(:str, value(val[1]))
1327
+ }
1328
+
1329
+ string_contents: none
1330
+ {
1331
+ result = nil
1332
+ }
1333
+ | string_contents string_content
1334
+ {
1335
+ result = str_append val[0], val[1]
1336
+ }
1337
+
1338
+ xstring_contents: none
1339
+ {
1340
+ result = nil
1341
+ }
1342
+ | xstring_contents string_content
1343
+ {
1344
+ result = str_append val[0], val[1]
1345
+ }
1346
+
1347
+ string_content: tSTRING_CONTENT
1348
+ {
1349
+ result = new_str_content(val[0])
1350
+ }
1351
+ | tSTRING_DVAR
1352
+ {
1353
+ result = lexer.strterm
1354
+ lexer.strterm = nil
1355
+ }
1356
+ string_dvar
1357
+ {
1358
+ lexer.strterm = val[1]
1359
+ result = new_evstr(val[2])
1360
+ }
1361
+ | tSTRING_DBEG
1362
+ {
1363
+ lexer.cond_push 0
1364
+ lexer.cmdarg_push 0
1365
+ result = lexer.strterm
1366
+ lexer.strterm = nil
1367
+ lexer.lex_state = :expr_beg
1368
+ }
1369
+ compstmt tRCURLY
1370
+ {
1371
+ lexer.strterm = val[1]
1372
+ lexer.cond_lexpop
1373
+ lexer.cmdarg_lexpop
1374
+ result = new_evstr(val[2])
1375
+ }
1376
+
1377
+ string_dvar: tGVAR
1378
+ {
1379
+ result = new_gvar(val[0])
1380
+ }
1381
+ | tIVAR
1382
+ {
1383
+ result = new_ivar(val[0])
1384
+ }
1385
+ | tCVAR
1386
+ {
1387
+ result = new_cvar(val[0])
1388
+ }
1389
+ | backref
1390
+
1391
+
1392
+ symbol: tSYMBEG sym
1393
+ {
1394
+ result = new_sym(val[1])
1395
+ lexer.lex_state = :expr_end
1396
+ }
1397
+ | tSYMBOL
1398
+ {
1399
+ result = new_sym(val[0])
1400
+ }
1401
+
1402
+ sym: fname
1403
+ | tIVAR
1404
+ | tGVAR
1405
+ | tCVAR
1406
+
1407
+ dsym: tSYMBEG xstring_contents tSTRING_END
1408
+ {
1409
+ result = new_dsym val[1]
1410
+ }
1411
+
1412
+ numeric: tINTEGER
1413
+ {
1414
+ result = new_int(val[0])
1415
+ }
1416
+ | tFLOAT
1417
+ {
1418
+ result = new_float(val[0])
1419
+ }
1420
+ | '-@NUM' tINTEGER =tLOWEST
1421
+ {
1422
+ result = negate_num(new_int(val[1]))
1423
+ }
1424
+ | '-@NUM' tFLOAT =tLOWEST
1425
+ {
1426
+ result = negate_num(new_float(val[1]))
1427
+ }
1428
+ | '+@NUM' tINTEGER =tLOWEST
1429
+ {
1430
+ result = new_int(val[1])
1431
+ }
1432
+ | '+@NUM' tFLOAT =tLOWEST
1433
+ {
1434
+ result = new_float(val[1])
1435
+ }
1436
+
1437
+ variable: tIDENTIFIER
1438
+ {
1439
+ result = new_ident(val[0])
1440
+ }
1441
+ | tIVAR
1442
+ {
1443
+ result = new_ivar(val[0])
1444
+ }
1445
+ | tGVAR
1446
+ {
1447
+ result = new_gvar(val[0])
1448
+ }
1449
+ | tCONSTANT
1450
+ {
1451
+ result = new_const(val[0])
1452
+ }
1453
+ | tCVAR
1454
+ {
1455
+ result = new_cvar(val[0])
1456
+ }
1457
+ | kNIL
1458
+ {
1459
+ result = new_nil(val[0])
1460
+ }
1461
+ | kSELF
1462
+ {
1463
+ result = new_self(val[0])
1464
+ }
1465
+ | kTRUE
1466
+ {
1467
+ result = new_true(val[0])
1468
+ }
1469
+ | kFALSE
1470
+ {
1471
+ result = new_false(val[0])
1472
+ }
1473
+ | k__FILE__
1474
+ {
1475
+ result = new___FILE__(val[0])
1476
+ }
1477
+ | k__LINE__
1478
+ {
1479
+ result = new___LINE__(val[0])
1480
+ }
1481
+
1482
+ var_ref: variable
1483
+ {
1484
+ result = new_var_ref(val[0])
1485
+ }
1486
+
1487
+ var_lhs: variable
1488
+ {
1489
+ result = new_assignable val[0]
1490
+ }
1491
+
1492
+ backref: tNTH_REF
1493
+ {
1494
+ result = s(:nth_ref, value(val[0]))
1495
+ }
1496
+ | tBACK_REF
1497
+
1498
+ superclass: term
1499
+ {
1500
+ result = nil
1501
+ }
1502
+ | tLT expr_value term
1503
+ {
1504
+ result = val[1]
1505
+ }
1506
+ | error term
1507
+ {
1508
+ result = nil
1509
+ }
1510
+
1511
+ f_arglist: tLPAREN2 f_args opt_nl tRPAREN
1512
+ {
1513
+ result = val[1]
1514
+ lexer.lex_state = :expr_beg
1515
+ }
1516
+ | f_args term
1517
+ {
1518
+ result = val[0]
1519
+ lexer.lex_state = :expr_beg
1520
+ }
1521
+
1522
+ kwrest_mark: tPOW
1523
+ | tDSTAR
1524
+
1525
+ f_kwrest: kwrest_mark tIDENTIFIER
1526
+ {
1527
+ result = new_kwrestarg(val[1])
1528
+ }
1529
+ | kwrest_mark
1530
+ {
1531
+ result = new_kwrestarg()
1532
+ }
1533
+
1534
+ f_label: tLABEL
1535
+ {
1536
+ result = new_sym(val[0])
1537
+ }
1538
+
1539
+ f_kw: f_label arg_value
1540
+ {
1541
+ result = new_kwoptarg(val[0], val[1])
1542
+ }
1543
+ | f_label
1544
+ {
1545
+ result = new_kwarg(val[0])
1546
+ }
1547
+
1548
+ f_kwarg: f_kw
1549
+ {
1550
+ result = [val[0]]
1551
+ }
1552
+ | f_kwarg tCOMMA f_kw
1553
+ {
1554
+ result = val[0]
1555
+ result << val[2]
1556
+ }
1557
+
1558
+ args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
1559
+ {
1560
+ result = new_args_tail(val[0], val[2], val[3])
1561
+ }
1562
+ | f_kwarg opt_f_block_arg
1563
+ {
1564
+ result = new_args_tail(val[0], nil, val[1])
1565
+ }
1566
+ | f_kwrest opt_f_block_arg
1567
+ {
1568
+ result = new_args_tail(nil, val[0], val[1])
1569
+ }
1570
+ | f_block_arg
1571
+ {
1572
+ result = new_args_tail(nil, nil, val[0])
1573
+ }
1574
+
1575
+ opt_args_tail: tCOMMA args_tail
1576
+ {
1577
+ result = val[1]
1578
+ }
1579
+ | # none
1580
+ {
1581
+ result = new_args_tail(nil, nil, nil)
1582
+ }
1583
+
1584
+ f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
1585
+ {
1586
+ result = new_args(val[0], val[2], val[4], val[5])
1587
+ }
1588
+ | f_arg tCOMMA f_optarg opt_args_tail
1589
+ {
1590
+ result = new_args(val[0], val[2], nil, val[3])
1591
+ }
1592
+ | f_arg tCOMMA f_rest_arg opt_args_tail
1593
+ {
1594
+ result = new_args(val[0], nil, val[2], val[3])
1595
+ }
1596
+ | f_arg opt_args_tail
1597
+ {
1598
+ result = new_args(val[0], nil, nil, val[1])
1599
+ }
1600
+ | f_optarg tCOMMA f_rest_arg opt_args_tail
1601
+ {
1602
+ result = new_args(nil, val[0], val[2], val[3])
1603
+ }
1604
+ | f_optarg opt_args_tail
1605
+ {
1606
+ result = new_args(nil, val[0], nil, val[1])
1607
+ }
1608
+ | f_rest_arg opt_args_tail
1609
+ {
1610
+ result = new_args(nil, nil, val[0], val[1])
1611
+ }
1612
+ | args_tail
1613
+ {
1614
+ result = new_args(nil, nil, nil, val[0])
1615
+ }
1616
+ | # none
1617
+ {
1618
+ result = new_args(nil, nil, nil, nil)
1619
+ }
1620
+
1621
+ f_norm_arg: f_bad_arg
1622
+ | tIDENTIFIER
1623
+ {
1624
+ result = value(val[0]).to_sym
1625
+ scope.add_local result
1626
+ }
1627
+
1628
+ f_bad_arg: tCONSTANT
1629
+ {
1630
+ raise 'formal argument cannot be a constant'
1631
+ }
1632
+ | tIVAR
1633
+ {
1634
+ raise 'formal argument cannot be an instance variable'
1635
+ }
1636
+ | tCVAR
1637
+ {
1638
+ raise 'formal argument cannot be a class variable'
1639
+ }
1640
+ | tGVAR
1641
+ {
1642
+ raise 'formal argument cannot be a global variable'
1643
+ }
1644
+
1645
+ f_arg_item: f_norm_arg
1646
+ {
1647
+ result = val[0]
1648
+ }
1649
+ | tLPAREN f_margs tRPAREN
1650
+ {
1651
+ result = val[1]
1652
+ }
1653
+
1654
+ for_var: lhs
1655
+ | mlhs
1656
+
1657
+ f_marg: f_norm_arg
1658
+ {
1659
+ result = s(:lasgn, val[0])
1660
+ }
1661
+ | tLPAREN f_margs tRPAREN
1662
+
1663
+ f_marg_list: f_marg
1664
+ {
1665
+ result = s(:array, val[0])
1666
+ }
1667
+ | f_marg_list tCOMMA f_marg
1668
+ {
1669
+ val[0] << val[2]
1670
+ result = val[0]
1671
+ }
1672
+
1673
+ f_margs: f_marg_list
1674
+ | f_marg_list tCOMMA tSTAR f_norm_arg
1675
+ | f_marg_list tCOMMA tSTAR
1676
+ | tSTAR f_norm_arg
1677
+ | tSTAR
1678
+
1679
+ f_arg: f_arg_item
1680
+ {
1681
+ result = [val[0]]
1682
+ }
1683
+ | f_arg tCOMMA f_arg_item
1684
+ {
1685
+ val[0] << val[2]
1686
+ result = val[0]
1687
+ }
1688
+
1689
+ f_opt: tIDENTIFIER tEQL arg_value
1690
+ {
1691
+ result = new_assign(new_assignable(new_ident(val[0])), val[1], val[2])
1692
+ }
1693
+
1694
+ f_optarg: f_opt
1695
+ {
1696
+ result = s(:block, val[0])
1697
+ }
1698
+ | f_optarg tCOMMA f_opt
1699
+ {
1700
+ result = val[0]
1701
+ val[0] << val[2]
1702
+ }
1703
+
1704
+ restarg_mark: tSTAR2
1705
+ | tSTAR
1706
+
1707
+ f_rest_arg: restarg_mark tIDENTIFIER
1708
+ {
1709
+ result = "*#{value(val[1])}".to_sym
1710
+ }
1711
+ | restarg_mark
1712
+ {
1713
+ result = :"*"
1714
+ }
1715
+
1716
+ blkarg_mark: tAMPER2
1717
+ | tAMPER
1718
+
1719
+ f_block_arg: blkarg_mark tIDENTIFIER
1720
+ {
1721
+ result = "&#{value(val[1])}".to_sym
1722
+ }
1723
+
1724
+ opt_f_block_arg: tCOMMA f_block_arg
1725
+ {
1726
+ result = val[1]
1727
+ }
1728
+ | # none
1729
+ {
1730
+ result = nil
1731
+ }
1732
+
1733
+ singleton: var_ref
1734
+ {
1735
+ result = val[0]
1736
+ }
1737
+ | tLPAREN2 expr opt_nl tRPAREN
1738
+ {
1739
+ result = val[1]
1740
+ }
1741
+
1742
+ assoc_list: # none
1743
+ {
1744
+ result = []
1745
+ }
1746
+ | assocs trailer
1747
+ {
1748
+ result = val[0]
1749
+ }
1750
+
1751
+ assocs: assoc
1752
+ {
1753
+ result = val[0]
1754
+ }
1755
+ | assocs tCOMMA assoc
1756
+ {
1757
+ result = val[0].push(*val[2])
1758
+ }
1759
+
1760
+ assoc: arg_value tASSOC arg_value
1761
+ {
1762
+ result = [val[0], val[2]]
1763
+ }
1764
+ | tLABEL arg_value
1765
+ {
1766
+ result = [new_sym(val[0]), val[1]]
1767
+ }
1768
+
1769
+ operation: tIDENTIFIER
1770
+ | tCONSTANT
1771
+ | tFID
1772
+
1773
+ operation2: tIDENTIFIER
1774
+ | tCONSTANT
1775
+ | tFID
1776
+ | op
1777
+
1778
+ operation3: tIDENTIFIER
1779
+ | tFID
1780
+ | op
1781
+
1782
+ dot_or_colon: tDOT
1783
+ | tCOLON2
1784
+
1785
+ opt_terms: # none
1786
+ | terms
1787
+
1788
+ opt_nl: # none
1789
+ | tNL
1790
+
1791
+ trailer: # none
1792
+ | tNL
1793
+ | tCOMMA
1794
+
1795
+ term: tSEMI
1796
+ | tNL
1797
+
1798
+ terms: term
1799
+ | terms tSEMI
1800
+
1801
+ none: # none
1802
+ {
1803
+ result = nil
1804
+ }
1805
+ end
1806
+
1807
+ ---- inner