ruby_parser 3.9.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +17 -0
- data/Rakefile +2 -2
- data/lib/rp_extensions.rb +5 -1
- data/lib/ruby18_parser.rb +15 -9
- data/lib/ruby18_parser.y +15 -9
- data/lib/ruby19_parser.rb +19 -15
- data/lib/ruby19_parser.y +19 -15
- data/lib/ruby20_parser.rb +2229 -2223
- data/lib/ruby20_parser.y +34 -23
- data/lib/ruby21_parser.rb +2546 -2530
- data/lib/ruby21_parser.y +34 -23
- data/lib/ruby22_parser.rb +2567 -2552
- data/lib/ruby22_parser.y +35 -24
- data/lib/ruby23_parser.rb +2505 -2483
- data/lib/ruby23_parser.y +35 -24
- data/lib/ruby24_parser.rb +2505 -2483
- data/lib/ruby24_parser.y +35 -24
- data/lib/ruby_lexer.rb +84 -11
- data/lib/ruby_parser.yy +35 -24
- data/lib/ruby_parser_extras.rb +112 -89
- data/test/test_ruby_lexer.rb +67 -0
- data/test/test_ruby_parser.rb +32 -1
- metadata +6 -6
- metadata.gz.sig +0 -0
data/lib/ruby24_parser.y
CHANGED
@@ -185,7 +185,7 @@ rule
|
|
185
185
|
{
|
186
186
|
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
187
187
|
if val[1] == '&.'
|
188
|
-
result
|
188
|
+
result.sexp_type = :safe_op_asgn
|
189
189
|
end
|
190
190
|
result.line = val[0].line
|
191
191
|
}
|
@@ -193,7 +193,7 @@ rule
|
|
193
193
|
{
|
194
194
|
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
195
195
|
if val[1] == '&.'
|
196
|
-
result
|
196
|
+
result.sexp_type = :safe_op_asgn
|
197
197
|
end
|
198
198
|
result.line = val[0].line
|
199
199
|
}
|
@@ -287,11 +287,11 @@ rule
|
|
287
287
|
|
288
288
|
command: fcall command_args =tLOWEST
|
289
289
|
{
|
290
|
-
result = val[0].concat val[1]
|
290
|
+
result = val[0].concat val[1].sexp_body # REFACTOR pattern
|
291
291
|
}
|
292
292
|
| fcall command_args cmd_brace_block
|
293
293
|
{
|
294
|
-
result = val[0].concat val[1]
|
294
|
+
result = val[0].concat val[1].sexp_body
|
295
295
|
if val[2] then
|
296
296
|
block_dup_check result, val[2]
|
297
297
|
|
@@ -380,7 +380,7 @@ rule
|
|
380
380
|
ary1, _, splat, _, ary2 = val
|
381
381
|
|
382
382
|
result = list_append ary1, s(:splat, splat)
|
383
|
-
result.concat ary2
|
383
|
+
result.concat ary2.sexp_body
|
384
384
|
result = s(:masgn, result)
|
385
385
|
}
|
386
386
|
| mlhs_head tSTAR
|
@@ -390,7 +390,7 @@ rule
|
|
390
390
|
| mlhs_head tSTAR tCOMMA mlhs_post
|
391
391
|
{
|
392
392
|
ary = list_append val[0], s(:splat)
|
393
|
-
ary.concat val[3]
|
393
|
+
ary.concat val[3].sexp_body
|
394
394
|
result = s(:masgn, ary)
|
395
395
|
}
|
396
396
|
| tSTAR mlhs_node
|
@@ -400,7 +400,7 @@ rule
|
|
400
400
|
| tSTAR mlhs_node tCOMMA mlhs_post
|
401
401
|
{
|
402
402
|
ary = s(:array, s(:splat, val[1]))
|
403
|
-
ary.concat val[3]
|
403
|
+
ary.concat val[3].sexp_body
|
404
404
|
result = s(:masgn, ary)
|
405
405
|
}
|
406
406
|
| tSTAR
|
@@ -409,7 +409,7 @@ rule
|
|
409
409
|
}
|
410
410
|
| tSTAR tCOMMA mlhs_post
|
411
411
|
{
|
412
|
-
result = s(:masgn, s(:array, s(:splat), *val[2]
|
412
|
+
result = s(:masgn, s(:array, s(:splat), *val[2].sexp_body))
|
413
413
|
}
|
414
414
|
|
415
415
|
mlhs_item: mlhs_node
|
@@ -620,7 +620,7 @@ rule
|
|
620
620
|
}
|
621
621
|
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
|
622
622
|
{
|
623
|
-
val[2]
|
623
|
+
val[2].sexp_type = :arglist if val[2]
|
624
624
|
result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
|
625
625
|
}
|
626
626
|
| primary_value call_op tIDENTIFIER tOP_ASGN arg
|
@@ -956,14 +956,20 @@ rule
|
|
956
956
|
{
|
957
957
|
debug20 13, val, result
|
958
958
|
}
|
959
|
-
| tLPAREN_ARG
|
959
|
+
| tLPAREN_ARG
|
960
|
+
{
|
961
|
+
result = self.lexer.cmdarg.stack.dup
|
962
|
+
lexer.cmdarg.stack.replace [false] # TODO add api for these
|
963
|
+
}
|
964
|
+
expr
|
960
965
|
{
|
961
966
|
lexer.lex_state = :expr_endarg
|
962
967
|
}
|
963
968
|
rparen
|
964
969
|
{
|
965
970
|
warning "(...) interpreted as grouped expression"
|
966
|
-
|
971
|
+
lexer.cmdarg.stack.replace val[1]
|
972
|
+
result = val[2]
|
967
973
|
}
|
968
974
|
| tLPAREN compstmt tRPAREN
|
969
975
|
{
|
@@ -981,7 +987,7 @@ rule
|
|
981
987
|
| tLBRACK aref_args tRBRACK
|
982
988
|
{
|
983
989
|
result = val[1] || s(:array)
|
984
|
-
result
|
990
|
+
result.sexp_type = :array # aref_args is :args
|
985
991
|
}
|
986
992
|
| tLBRACE
|
987
993
|
{
|
@@ -1182,12 +1188,16 @@ rule
|
|
1182
1188
|
self.in_single += 1
|
1183
1189
|
self.env.extend
|
1184
1190
|
lexer.lex_state = :expr_endfn # force for args
|
1185
|
-
result = lexer.lineno
|
1191
|
+
result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
|
1192
|
+
lexer.cmdarg.stack.replace [false]
|
1186
1193
|
}
|
1187
1194
|
f_arglist bodystmt kEND
|
1188
1195
|
{
|
1196
|
+
line, cmdarg = val[5]
|
1189
1197
|
result = new_defs val
|
1190
|
-
result[3].line
|
1198
|
+
result[3].line line
|
1199
|
+
|
1200
|
+
lexer.cmdarg.stack.replace cmdarg
|
1191
1201
|
|
1192
1202
|
self.env.unextend
|
1193
1203
|
self.in_single -= 1
|
@@ -1543,7 +1553,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1543
1553
|
paren_args
|
1544
1554
|
{
|
1545
1555
|
args = self.call_args val[2..-1]
|
1546
|
-
result = val[0].concat args
|
1556
|
+
result = val[0].concat args.sexp_body
|
1547
1557
|
}
|
1548
1558
|
| primary_value call_op operation2 opt_paren_args
|
1549
1559
|
{
|
@@ -1630,10 +1640,11 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1630
1640
|
|
1631
1641
|
opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
|
1632
1642
|
{
|
1633
|
-
_, klasses, var, _, body, rest = val
|
1643
|
+
(_, line), klasses, var, _, body, rest = val
|
1634
1644
|
|
1635
1645
|
klasses ||= s(:array)
|
1636
1646
|
klasses << new_assign(var, s(:gvar, :"$!")) if var
|
1647
|
+
klasses.line line
|
1637
1648
|
|
1638
1649
|
result = new_resbody(klasses, body)
|
1639
1650
|
result << rest if rest # UGH, rewritten above
|
@@ -1676,7 +1687,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1676
1687
|
|
1677
1688
|
strings: string
|
1678
1689
|
{
|
1679
|
-
val[0] = s(:dstr, val[0].value) if val[0]
|
1690
|
+
val[0] = s(:dstr, val[0].value) if val[0].sexp_type == :evstr
|
1680
1691
|
result = val[0]
|
1681
1692
|
}
|
1682
1693
|
|
@@ -1864,7 +1875,7 @@ regexp_contents: none
|
|
1864
1875
|
|
1865
1876
|
case stmt
|
1866
1877
|
when Sexp then
|
1867
|
-
case stmt
|
1878
|
+
case stmt.sexp_type
|
1868
1879
|
when :str, :dstr, :evstr then
|
1869
1880
|
result = stmt
|
1870
1881
|
else
|
@@ -1902,9 +1913,9 @@ regexp_contents: none
|
|
1902
1913
|
|
1903
1914
|
result ||= s(:str, "")
|
1904
1915
|
|
1905
|
-
case result
|
1916
|
+
case result.sexp_type
|
1906
1917
|
when :dstr then
|
1907
|
-
result
|
1918
|
+
result.sexp_type = :dsym
|
1908
1919
|
when :str then
|
1909
1920
|
result = s(:lit, result.last.to_sym)
|
1910
1921
|
when :evstr then
|
@@ -2288,7 +2299,7 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2288
2299
|
{
|
2289
2300
|
result = val[2]
|
2290
2301
|
yyerror "Can't define single method for literals." if
|
2291
|
-
result
|
2302
|
+
result.sexp_type == :lit
|
2292
2303
|
}
|
2293
2304
|
|
2294
2305
|
assoc_list: none # [!nil]
|
@@ -2304,10 +2315,10 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2304
2315
|
| assocs tCOMMA assoc
|
2305
2316
|
{
|
2306
2317
|
list = val[0].dup
|
2307
|
-
more = val[2]
|
2318
|
+
more = val[2].sexp_body
|
2308
2319
|
list.push(*more) unless more.empty?
|
2309
2320
|
result = list
|
2310
|
-
result
|
2321
|
+
result.sexp_type = :hash
|
2311
2322
|
}
|
2312
2323
|
|
2313
2324
|
assoc: arg_value tASSOC arg_value
|
@@ -2321,7 +2332,7 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2321
2332
|
| tSTRING_BEG string_contents tLABEL_END arg_value
|
2322
2333
|
{
|
2323
2334
|
_, sym, _, value = val
|
2324
|
-
sym
|
2335
|
+
sym.sexp_type = :dsym
|
2325
2336
|
result = s(:array, sym, value)
|
2326
2337
|
}
|
2327
2338
|
| tSYMBOL arg_value
|
data/lib/ruby_lexer.rb
CHANGED
@@ -22,6 +22,7 @@ class RubyLexer
|
|
22
22
|
STR_FUNC_QWORDS = 0x08
|
23
23
|
STR_FUNC_SYMBOL = 0x10
|
24
24
|
STR_FUNC_INDENT = 0x20 # <<-HEREDOC
|
25
|
+
STR_FUNC_ICNTNT = 0x40 # <<~HEREDOC
|
25
26
|
|
26
27
|
STR_SQUOTE = STR_FUNC_BORING
|
27
28
|
STR_DQUOTE = STR_FUNC_BORING | STR_FUNC_EXPAND
|
@@ -62,6 +63,8 @@ class RubyLexer
|
|
62
63
|
"->" => :tLAMBDA,
|
63
64
|
}
|
64
65
|
|
66
|
+
TAB_WIDTH = 8
|
67
|
+
|
65
68
|
@@regexp_cache = Hash.new { |h,k| h[k] = Regexp.new(Regexp.escape(k)) }
|
66
69
|
@@regexp_cache[nil] = nil
|
67
70
|
|
@@ -89,6 +92,17 @@ class RubyLexer
|
|
89
92
|
attr_accessor :string_buffer
|
90
93
|
attr_accessor :string_nest
|
91
94
|
|
95
|
+
if $DEBUG then
|
96
|
+
alias lex_state= lex_state=
|
97
|
+
def lex_state=o
|
98
|
+
return if @lex_state == o
|
99
|
+
c = caller.first
|
100
|
+
c = caller[1] if c =~ /\bresult\b/
|
101
|
+
warn "lex_state: %p -> %p from %s" % [@lex_state, o, c.clean_caller]
|
102
|
+
@lex_state = o
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
92
106
|
# Last token read via next_token.
|
93
107
|
attr_accessor :token
|
94
108
|
|
@@ -102,6 +116,10 @@ class RubyLexer
|
|
102
116
|
|
103
117
|
def initialize v = 18
|
104
118
|
self.version = v
|
119
|
+
@lex_state = :expr_none
|
120
|
+
|
121
|
+
self.cmdarg = RubyParserStuff::StackState.new(:cmdarg, $DEBUG)
|
122
|
+
self.cond = RubyParserStuff::StackState.new(:cond, $DEBUG)
|
105
123
|
|
106
124
|
reset
|
107
125
|
end
|
@@ -146,10 +164,11 @@ class RubyLexer
|
|
146
164
|
def heredoc here # TODO: rewrite / remove
|
147
165
|
_, eos, func, last_line = here
|
148
166
|
|
149
|
-
indent
|
150
|
-
|
151
|
-
|
152
|
-
|
167
|
+
indent = (func & STR_FUNC_INDENT) != 0 ? "[ \t]*" : nil
|
168
|
+
content_indent = (func & STR_FUNC_ICNTNT) != 0
|
169
|
+
expand = (func & STR_FUNC_EXPAND) != 0
|
170
|
+
eos_re = /#{indent}#{Regexp.escape eos}(\r*\n|\z)/
|
171
|
+
err_msg = "can't match #{eos_re.inspect} anywhere in "
|
153
172
|
|
154
173
|
rb_compile_error err_msg if end_of_stream?
|
155
174
|
|
@@ -195,17 +214,64 @@ class RubyLexer
|
|
195
214
|
|
196
215
|
self.lex_strterm = [:heredoc, eos, func, last_line]
|
197
216
|
|
198
|
-
|
217
|
+
string_content = string_buffer.join.delete("\r")
|
218
|
+
|
219
|
+
string_content = heredoc_dedent(string_content) if content_indent && ruby23?
|
220
|
+
|
221
|
+
return :tSTRING_CONTENT, string_content
|
222
|
+
end
|
223
|
+
|
224
|
+
def heredoc_dedent(string_content)
|
225
|
+
width = string_content.scan(/^[ \t]*(?=\S)/).map do |whitespace|
|
226
|
+
heredoc_whitespace_indent_size whitespace
|
227
|
+
end.min || 0
|
228
|
+
|
229
|
+
string_content.split("\n", -1).map do |line|
|
230
|
+
dedent_string line, width
|
231
|
+
end.join "\n"
|
232
|
+
end
|
233
|
+
|
234
|
+
def dedent_string(string, width)
|
235
|
+
characters_skipped = 0
|
236
|
+
indentation_skipped = 0
|
237
|
+
|
238
|
+
string.chars.each do |char|
|
239
|
+
break if indentation_skipped >= width
|
240
|
+
if char == ' '
|
241
|
+
characters_skipped += 1
|
242
|
+
indentation_skipped += 1
|
243
|
+
elsif char == "\t"
|
244
|
+
proposed = TAB_WIDTH * (indentation_skipped / TAB_WIDTH + 1)
|
245
|
+
break if (proposed > width)
|
246
|
+
characters_skipped += 1
|
247
|
+
indentation_skipped = proposed
|
248
|
+
end
|
249
|
+
end
|
250
|
+
string[characters_skipped..-1]
|
251
|
+
end
|
252
|
+
|
253
|
+
def heredoc_whitespace_indent_size(whitespace)
|
254
|
+
whitespace.chars.inject 0 do |size, char|
|
255
|
+
if char == "\t"
|
256
|
+
size + TAB_WIDTH
|
257
|
+
else
|
258
|
+
size + 1
|
259
|
+
end
|
260
|
+
end
|
199
261
|
end
|
200
262
|
|
201
263
|
def heredoc_identifier # TODO: remove / rewrite
|
202
264
|
term, func = nil, STR_FUNC_BORING
|
203
265
|
self.string_buffer = []
|
204
266
|
|
267
|
+
heredoc_indent_mods = '-'
|
268
|
+
heredoc_indent_mods += '\~' if ruby23?
|
269
|
+
|
205
270
|
case
|
206
|
-
when scan(/(
|
271
|
+
when scan(/([#{heredoc_indent_mods}]?)([\'\"\`])(.*?)\2/) then
|
207
272
|
term = ss[2]
|
208
273
|
func |= STR_FUNC_INDENT unless ss[1].empty?
|
274
|
+
func |= STR_FUNC_ICNTNT if ss[1] == '~'
|
209
275
|
func |= case term
|
210
276
|
when "\'" then
|
211
277
|
STR_SQUOTE
|
@@ -215,13 +281,14 @@ class RubyLexer
|
|
215
281
|
STR_XQUOTE
|
216
282
|
end
|
217
283
|
string_buffer << ss[3]
|
218
|
-
when scan(
|
284
|
+
when scan(/[#{heredoc_indent_mods}]?([\'\"\`])(?!\1*\Z)/) then
|
219
285
|
rb_compile_error "unterminated here document identifier"
|
220
|
-
when scan(/(
|
286
|
+
when scan(/([#{heredoc_indent_mods}]?)(#{IDENT_CHAR}+)/) then
|
221
287
|
term = '"'
|
222
288
|
func |= STR_DQUOTE
|
223
289
|
unless ss[1].empty? then
|
224
290
|
func |= STR_FUNC_INDENT
|
291
|
+
func |= STR_FUNC_ICNTNT if ss[1] == '~'
|
225
292
|
end
|
226
293
|
string_buffer << ss[2]
|
227
294
|
else
|
@@ -507,6 +574,7 @@ class RubyLexer
|
|
507
574
|
|
508
575
|
self.paren_nest += 1
|
509
576
|
|
577
|
+
# TODO: add :expr_label to :expr_beg (set in expr_result below)
|
510
578
|
return expr_result(token, "(")
|
511
579
|
end
|
512
580
|
|
@@ -817,6 +885,7 @@ class RubyLexer
|
|
817
885
|
when scan(/\\/) then # Backslash
|
818
886
|
'\\'
|
819
887
|
when scan(/n/) then # newline
|
888
|
+
self.extra_lineno -= 1
|
820
889
|
"\n"
|
821
890
|
when scan(/t/) then # horizontal tab
|
822
891
|
"\t"
|
@@ -888,7 +957,7 @@ class RubyLexer
|
|
888
957
|
self.brace_nest = 0
|
889
958
|
self.command_start = true
|
890
959
|
self.comments = []
|
891
|
-
self.lex_state =
|
960
|
+
self.lex_state = :expr_none
|
892
961
|
self.lex_strterm = nil
|
893
962
|
self.lineno = 1
|
894
963
|
self.lpar_beg = nil
|
@@ -898,8 +967,8 @@ class RubyLexer
|
|
898
967
|
self.token = nil
|
899
968
|
self.extra_lineno = 0
|
900
969
|
|
901
|
-
self.cmdarg
|
902
|
-
self.cond
|
970
|
+
self.cmdarg.reset
|
971
|
+
self.cond.reset
|
903
972
|
end
|
904
973
|
|
905
974
|
def result lex_state, token, text # :nodoc:
|
@@ -1106,6 +1175,10 @@ class RubyLexer
|
|
1106
1175
|
parser.class.version >= 22
|
1107
1176
|
end
|
1108
1177
|
|
1178
|
+
def ruby23?
|
1179
|
+
Ruby23Parser === parser
|
1180
|
+
end
|
1181
|
+
|
1109
1182
|
def process_string # TODO: rewrite / remove
|
1110
1183
|
token = if lex_strterm[0] == :heredoc then
|
1111
1184
|
self.heredoc lex_strterm
|
data/lib/ruby_parser.yy
CHANGED
@@ -203,7 +203,7 @@ rule
|
|
203
203
|
{
|
204
204
|
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
205
205
|
if val[1] == '&.'
|
206
|
-
result
|
206
|
+
result.sexp_type = :safe_op_asgn
|
207
207
|
end
|
208
208
|
result.line = val[0].line
|
209
209
|
}
|
@@ -211,7 +211,7 @@ rule
|
|
211
211
|
{
|
212
212
|
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
213
213
|
if val[1] == '&.'
|
214
|
-
result
|
214
|
+
result.sexp_type = :safe_op_asgn
|
215
215
|
end
|
216
216
|
result.line = val[0].line
|
217
217
|
}
|
@@ -313,11 +313,11 @@ rule
|
|
313
313
|
|
314
314
|
command: fcall command_args =tLOWEST
|
315
315
|
{
|
316
|
-
result = val[0].concat val[1]
|
316
|
+
result = val[0].concat val[1].sexp_body # REFACTOR pattern
|
317
317
|
}
|
318
318
|
| fcall command_args cmd_brace_block
|
319
319
|
{
|
320
|
-
result = val[0].concat val[1]
|
320
|
+
result = val[0].concat val[1].sexp_body
|
321
321
|
if val[2] then
|
322
322
|
block_dup_check result, val[2]
|
323
323
|
|
@@ -406,7 +406,7 @@ rule
|
|
406
406
|
ary1, _, splat, _, ary2 = val
|
407
407
|
|
408
408
|
result = list_append ary1, s(:splat, splat)
|
409
|
-
result.concat ary2
|
409
|
+
result.concat ary2.sexp_body
|
410
410
|
result = s(:masgn, result)
|
411
411
|
}
|
412
412
|
| mlhs_head tSTAR
|
@@ -416,7 +416,7 @@ rule
|
|
416
416
|
| mlhs_head tSTAR tCOMMA mlhs_post
|
417
417
|
{
|
418
418
|
ary = list_append val[0], s(:splat)
|
419
|
-
ary.concat val[3]
|
419
|
+
ary.concat val[3].sexp_body
|
420
420
|
result = s(:masgn, ary)
|
421
421
|
}
|
422
422
|
| tSTAR mlhs_node
|
@@ -426,7 +426,7 @@ rule
|
|
426
426
|
| tSTAR mlhs_node tCOMMA mlhs_post
|
427
427
|
{
|
428
428
|
ary = s(:array, s(:splat, val[1]))
|
429
|
-
ary.concat val[3]
|
429
|
+
ary.concat val[3].sexp_body
|
430
430
|
result = s(:masgn, ary)
|
431
431
|
}
|
432
432
|
| tSTAR
|
@@ -435,7 +435,7 @@ rule
|
|
435
435
|
}
|
436
436
|
| tSTAR tCOMMA mlhs_post
|
437
437
|
{
|
438
|
-
result = s(:masgn, s(:array, s(:splat), *val[2]
|
438
|
+
result = s(:masgn, s(:array, s(:splat), *val[2].sexp_body))
|
439
439
|
}
|
440
440
|
|
441
441
|
mlhs_item: mlhs_node
|
@@ -649,7 +649,7 @@ rule
|
|
649
649
|
}
|
650
650
|
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
|
651
651
|
{
|
652
|
-
val[2]
|
652
|
+
val[2].sexp_type = :arglist if val[2]
|
653
653
|
result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
|
654
654
|
}
|
655
655
|
| primary_value call_op tIDENTIFIER tOP_ASGN arg
|
@@ -999,14 +999,20 @@ rule
|
|
999
999
|
{
|
1000
1000
|
debug20 13, val, result
|
1001
1001
|
}
|
1002
|
-
| tLPAREN_ARG
|
1002
|
+
| tLPAREN_ARG
|
1003
|
+
{
|
1004
|
+
result = self.lexer.cmdarg.stack.dup
|
1005
|
+
lexer.cmdarg.stack.replace [false] # TODO add api for these
|
1006
|
+
}
|
1007
|
+
expr
|
1003
1008
|
{
|
1004
1009
|
lexer.lex_state = :expr_endarg
|
1005
1010
|
}
|
1006
1011
|
rparen
|
1007
1012
|
{
|
1008
1013
|
warning "(...) interpreted as grouped expression"
|
1009
|
-
|
1014
|
+
lexer.cmdarg.stack.replace val[1]
|
1015
|
+
result = val[2]
|
1010
1016
|
}
|
1011
1017
|
| tLPAREN compstmt tRPAREN
|
1012
1018
|
{
|
@@ -1024,7 +1030,7 @@ rule
|
|
1024
1030
|
| tLBRACK aref_args tRBRACK
|
1025
1031
|
{
|
1026
1032
|
result = val[1] || s(:array)
|
1027
|
-
result
|
1033
|
+
result.sexp_type = :array # aref_args is :args
|
1028
1034
|
}
|
1029
1035
|
| tLBRACE
|
1030
1036
|
{
|
@@ -1225,12 +1231,16 @@ rule
|
|
1225
1231
|
self.in_single += 1
|
1226
1232
|
self.env.extend
|
1227
1233
|
lexer.lex_state = :expr_endfn # force for args
|
1228
|
-
result = lexer.lineno
|
1234
|
+
result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
|
1235
|
+
lexer.cmdarg.stack.replace [false]
|
1229
1236
|
}
|
1230
1237
|
f_arglist bodystmt kEND
|
1231
1238
|
{
|
1239
|
+
line, cmdarg = val[5]
|
1232
1240
|
result = new_defs val
|
1233
|
-
result[3].line
|
1241
|
+
result[3].line line
|
1242
|
+
|
1243
|
+
lexer.cmdarg.stack.replace cmdarg
|
1234
1244
|
|
1235
1245
|
self.env.unextend
|
1236
1246
|
self.in_single -= 1
|
@@ -1586,7 +1596,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1586
1596
|
paren_args
|
1587
1597
|
{
|
1588
1598
|
args = self.call_args val[2..-1]
|
1589
|
-
result = val[0].concat args
|
1599
|
+
result = val[0].concat args.sexp_body
|
1590
1600
|
}
|
1591
1601
|
| primary_value call_op operation2 opt_paren_args
|
1592
1602
|
{
|
@@ -1673,10 +1683,11 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1673
1683
|
|
1674
1684
|
opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
|
1675
1685
|
{
|
1676
|
-
_, klasses, var, _, body, rest = val
|
1686
|
+
(_, line), klasses, var, _, body, rest = val
|
1677
1687
|
|
1678
1688
|
klasses ||= s(:array)
|
1679
1689
|
klasses << new_assign(var, s(:gvar, :"$!")) if var
|
1690
|
+
klasses.line line
|
1680
1691
|
|
1681
1692
|
result = new_resbody(klasses, body)
|
1682
1693
|
result << rest if rest # UGH, rewritten above
|
@@ -1719,7 +1730,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1719
1730
|
|
1720
1731
|
strings: string
|
1721
1732
|
{
|
1722
|
-
val[0] = s(:dstr, val[0].value) if val[0]
|
1733
|
+
val[0] = s(:dstr, val[0].value) if val[0].sexp_type == :evstr
|
1723
1734
|
result = val[0]
|
1724
1735
|
}
|
1725
1736
|
|
@@ -1911,7 +1922,7 @@ regexp_contents: none
|
|
1911
1922
|
|
1912
1923
|
case stmt
|
1913
1924
|
when Sexp then
|
1914
|
-
case stmt
|
1925
|
+
case stmt.sexp_type
|
1915
1926
|
when :str, :dstr, :evstr then
|
1916
1927
|
result = stmt
|
1917
1928
|
else
|
@@ -1949,9 +1960,9 @@ regexp_contents: none
|
|
1949
1960
|
|
1950
1961
|
result ||= s(:str, "")
|
1951
1962
|
|
1952
|
-
case result
|
1963
|
+
case result.sexp_type
|
1953
1964
|
when :dstr then
|
1954
|
-
result
|
1965
|
+
result.sexp_type = :dsym
|
1955
1966
|
when :str then
|
1956
1967
|
result = s(:lit, result.last.to_sym)
|
1957
1968
|
when :evstr then
|
@@ -2381,7 +2392,7 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2381
2392
|
{
|
2382
2393
|
result = val[2]
|
2383
2394
|
yyerror "Can't define single method for literals." if
|
2384
|
-
result
|
2395
|
+
result.sexp_type == :lit
|
2385
2396
|
}
|
2386
2397
|
|
2387
2398
|
assoc_list: none # [!nil]
|
@@ -2397,10 +2408,10 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2397
2408
|
| assocs tCOMMA assoc
|
2398
2409
|
{
|
2399
2410
|
list = val[0].dup
|
2400
|
-
more = val[2]
|
2411
|
+
more = val[2].sexp_body
|
2401
2412
|
list.push(*more) unless more.empty?
|
2402
2413
|
result = list
|
2403
|
-
result
|
2414
|
+
result.sexp_type = :hash
|
2404
2415
|
}
|
2405
2416
|
|
2406
2417
|
assoc: arg_value tASSOC arg_value
|
@@ -2415,7 +2426,7 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2415
2426
|
| tSTRING_BEG string_contents tLABEL_END arg_value
|
2416
2427
|
{
|
2417
2428
|
_, sym, _, value = val
|
2418
|
-
sym
|
2429
|
+
sym.sexp_type = :dsym
|
2419
2430
|
result = s(:array, sym, value)
|
2420
2431
|
}
|
2421
2432
|
| tSYMBOL arg_value
|