parser 2.0.0.beta5 → 2.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +3 -4
- data/doc/AST_FORMAT.md +37 -8
- data/lib/parser/ast/processor.rb +20 -68
- data/lib/parser/builders/default.rb +71 -25
- data/lib/parser/lexer.rl +4 -4
- data/lib/parser/ruby18.y +8 -5
- data/lib/parser/ruby19.y +11 -8
- data/lib/parser/ruby20.y +11 -8
- data/lib/parser/ruby21.y +11 -8
- data/lib/parser/runner/ruby_parse.rb +5 -9
- data/lib/parser/source/comment/associator.rb +2 -0
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +1 -1
- data/test/test_lexer.rb +8 -0
- data/test/test_parser.rb +204 -92
- data/test/test_source_comment_associator.rb +23 -5
- metadata +4 -4
data/lib/parser/lexer.rl
CHANGED
@@ -677,7 +677,7 @@ class Parser::Lexer
|
|
677
677
|
# After every heredoc was parsed, @herebody_s contains the
|
678
678
|
# position of next token after all heredocs.
|
679
679
|
if @herebody_s
|
680
|
-
p = @herebody_s
|
680
|
+
p = @herebody_s
|
681
681
|
@herebody_s = nil
|
682
682
|
end
|
683
683
|
};
|
@@ -819,9 +819,9 @@ class Parser::Lexer
|
|
819
819
|
if literal
|
820
820
|
if literal.end_interp_brace_and_try_closing
|
821
821
|
if version?(18, 19)
|
822
|
-
emit(:tRCURLY, '}')
|
822
|
+
emit(:tRCURLY, '}', p - 1, p)
|
823
823
|
else
|
824
|
-
emit(:tSTRING_DEND, '}')
|
824
|
+
emit(:tSTRING_DEND, '}', p - 1, p)
|
825
825
|
end
|
826
826
|
|
827
827
|
if literal.saved_herebody_s
|
@@ -1056,7 +1056,7 @@ class Parser::Lexer
|
|
1056
1056
|
|
1057
1057
|
global_var
|
1058
1058
|
=> { p = @ts - 1
|
1059
|
-
fcall expr_variable; };
|
1059
|
+
fnext expr_end; fcall expr_variable; };
|
1060
1060
|
|
1061
1061
|
# If the handling was to be delegated to expr_end,
|
1062
1062
|
# these cases would transition to something else than
|
data/lib/parser/ruby18.y
CHANGED
@@ -227,11 +227,11 @@ rule
|
|
227
227
|
}
|
228
228
|
| kNOT expr
|
229
229
|
{
|
230
|
-
result = @builder.not_op(val[0], val[1])
|
230
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
231
231
|
}
|
232
232
|
| tBANG command_call
|
233
233
|
{
|
234
|
-
result = @builder.not_op(val[0], val[1])
|
234
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
235
235
|
}
|
236
236
|
| arg
|
237
237
|
|
@@ -714,7 +714,7 @@ rule
|
|
714
714
|
}
|
715
715
|
| tBANG arg
|
716
716
|
{
|
717
|
-
result = @builder.not_op(val[0], val[1])
|
717
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
718
718
|
}
|
719
719
|
| tTILDE arg
|
720
720
|
{
|
@@ -1001,7 +1001,7 @@ rule
|
|
1001
1001
|
}
|
1002
1002
|
| kBEGIN bodystmt kEND
|
1003
1003
|
{
|
1004
|
-
result = @builder.
|
1004
|
+
result = @builder.begin_keyword(val[0], val[1], val[2])
|
1005
1005
|
}
|
1006
1006
|
| tLPAREN_ARG expr
|
1007
1007
|
{
|
@@ -1253,6 +1253,9 @@ rule
|
|
1253
1253
|
| tCOLON
|
1254
1254
|
| kTHEN
|
1255
1255
|
| term kTHEN
|
1256
|
+
{
|
1257
|
+
result = val[1]
|
1258
|
+
}
|
1256
1259
|
|
1257
1260
|
do: term
|
1258
1261
|
| tCOLON
|
@@ -1611,7 +1614,7 @@ xstring_contents: # nothing
|
|
1611
1614
|
@lexer.cond.lexpop
|
1612
1615
|
@lexer.cmdarg.lexpop
|
1613
1616
|
|
1614
|
-
result = val[2]
|
1617
|
+
result = @builder.begin(val[0], val[2], val[3])
|
1615
1618
|
}
|
1616
1619
|
|
1617
1620
|
string_dvar: tGVAR
|
data/lib/parser/ruby19.y
CHANGED
@@ -258,11 +258,11 @@ rule
|
|
258
258
|
}
|
259
259
|
| kNOT opt_nl expr
|
260
260
|
{
|
261
|
-
result = @builder.not_op(val[0], val[2])
|
261
|
+
result = @builder.not_op(val[0], nil, val[2], nil)
|
262
262
|
}
|
263
263
|
| tBANG command_call
|
264
264
|
{
|
265
|
-
result = @builder.not_op(val[0], val[1])
|
265
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
266
266
|
}
|
267
267
|
| arg
|
268
268
|
|
@@ -777,7 +777,7 @@ rule
|
|
777
777
|
}
|
778
778
|
| arg tMATCH arg
|
779
779
|
{
|
780
|
-
result = @builder.
|
780
|
+
result = @builder.match_op(val[0], val[1], val[2])
|
781
781
|
}
|
782
782
|
| arg tNMATCH arg
|
783
783
|
{
|
@@ -785,7 +785,7 @@ rule
|
|
785
785
|
}
|
786
786
|
| tBANG arg
|
787
787
|
{
|
788
|
-
result = @builder.not_op(val[0], val[1])
|
788
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
789
789
|
}
|
790
790
|
| tTILDE arg
|
791
791
|
{
|
@@ -954,7 +954,7 @@ rule
|
|
954
954
|
}
|
955
955
|
| kBEGIN bodystmt kEND
|
956
956
|
{
|
957
|
-
result = @builder.
|
957
|
+
result = @builder.begin_keyword(val[0], val[1], val[2])
|
958
958
|
}
|
959
959
|
| tLPAREN_ARG expr
|
960
960
|
{
|
@@ -1007,11 +1007,11 @@ rule
|
|
1007
1007
|
}
|
1008
1008
|
| kNOT tLPAREN2 expr rparen
|
1009
1009
|
{
|
1010
|
-
result = @builder.not_op(val[0], val[2])
|
1010
|
+
result = @builder.not_op(val[0], val[1], val[2], val[3])
|
1011
1011
|
}
|
1012
1012
|
| kNOT tLPAREN2 rparen
|
1013
1013
|
{
|
1014
|
-
result = @builder.not_op(val[0])
|
1014
|
+
result = @builder.not_op(val[0], val[1], nil, val[2])
|
1015
1015
|
}
|
1016
1016
|
| operation brace_block
|
1017
1017
|
{
|
@@ -1209,6 +1209,9 @@ rule
|
|
1209
1209
|
then: term
|
1210
1210
|
| kTHEN
|
1211
1211
|
| term kTHEN
|
1212
|
+
{
|
1213
|
+
result = val[1]
|
1214
|
+
}
|
1212
1215
|
|
1213
1216
|
do: term
|
1214
1217
|
| kDO_COND
|
@@ -1727,7 +1730,7 @@ regexp_contents: # nothing
|
|
1727
1730
|
@lexer.cond.lexpop
|
1728
1731
|
@lexer.cmdarg.lexpop
|
1729
1732
|
|
1730
|
-
result = val[2]
|
1733
|
+
result = @builder.begin(val[0], val[2], val[3])
|
1731
1734
|
}
|
1732
1735
|
|
1733
1736
|
string_dvar: tGVAR
|
data/lib/parser/ruby20.y
CHANGED
@@ -269,11 +269,11 @@ rule
|
|
269
269
|
}
|
270
270
|
| kNOT opt_nl expr
|
271
271
|
{
|
272
|
-
result = @builder.not_op(val[0], val[2])
|
272
|
+
result = @builder.not_op(val[0], nil, val[2], nil)
|
273
273
|
}
|
274
274
|
| tBANG command_call
|
275
275
|
{
|
276
|
-
result = @builder.not_op(val[0], val[1])
|
276
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
277
277
|
}
|
278
278
|
| arg
|
279
279
|
|
@@ -797,7 +797,7 @@ rule
|
|
797
797
|
}
|
798
798
|
| arg tMATCH arg
|
799
799
|
{
|
800
|
-
result = @builder.
|
800
|
+
result = @builder.match_op(val[0], val[1], val[2])
|
801
801
|
}
|
802
802
|
| arg tNMATCH arg
|
803
803
|
{
|
@@ -805,7 +805,7 @@ rule
|
|
805
805
|
}
|
806
806
|
| tBANG arg
|
807
807
|
{
|
808
|
-
result = @builder.not_op(val[0], val[1])
|
808
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
809
809
|
}
|
810
810
|
| tTILDE arg
|
811
811
|
{
|
@@ -983,7 +983,7 @@ rule
|
|
983
983
|
{
|
984
984
|
@lexer.cmdarg = val[1]
|
985
985
|
|
986
|
-
result = @builder.
|
986
|
+
result = @builder.begin_keyword(val[0], val[2], val[3])
|
987
987
|
}
|
988
988
|
| tLPAREN_ARG expr
|
989
989
|
{
|
@@ -1044,11 +1044,11 @@ rule
|
|
1044
1044
|
}
|
1045
1045
|
| kNOT tLPAREN2 expr rparen
|
1046
1046
|
{
|
1047
|
-
result = @builder.not_op(val[0], val[2])
|
1047
|
+
result = @builder.not_op(val[0], val[1], val[2], val[3])
|
1048
1048
|
}
|
1049
1049
|
| kNOT tLPAREN2 rparen
|
1050
1050
|
{
|
1051
|
-
result = @builder.not_op(val[0])
|
1051
|
+
result = @builder.not_op(val[0], val[1], nil, val[2])
|
1052
1052
|
}
|
1053
1053
|
| fcall brace_block
|
1054
1054
|
{
|
@@ -1246,6 +1246,9 @@ rule
|
|
1246
1246
|
then: term
|
1247
1247
|
| kTHEN
|
1248
1248
|
| term kTHEN
|
1249
|
+
{
|
1250
|
+
result = val[1]
|
1251
|
+
}
|
1249
1252
|
|
1250
1253
|
do: term
|
1251
1254
|
| kDO_COND
|
@@ -1829,7 +1832,7 @@ regexp_contents: # nothing
|
|
1829
1832
|
@lexer.cond.lexpop
|
1830
1833
|
@lexer.cmdarg.lexpop
|
1831
1834
|
|
1832
|
-
result = val[2]
|
1835
|
+
result = @builder.begin(val[0], val[2], val[3])
|
1833
1836
|
}
|
1834
1837
|
|
1835
1838
|
string_dvar: tGVAR
|
data/lib/parser/ruby21.y
CHANGED
@@ -264,11 +264,11 @@ rule
|
|
264
264
|
}
|
265
265
|
| kNOT opt_nl expr
|
266
266
|
{
|
267
|
-
result = @builder.not_op(val[0], val[2])
|
267
|
+
result = @builder.not_op(val[0], nil, val[2], nil)
|
268
268
|
}
|
269
269
|
| tBANG command_call
|
270
270
|
{
|
271
|
-
result = @builder.not_op(val[0], val[1])
|
271
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
272
272
|
}
|
273
273
|
| arg
|
274
274
|
|
@@ -792,7 +792,7 @@ rule
|
|
792
792
|
}
|
793
793
|
| arg tMATCH arg
|
794
794
|
{
|
795
|
-
result = @builder.
|
795
|
+
result = @builder.match_op(val[0], val[1], val[2])
|
796
796
|
}
|
797
797
|
| arg tNMATCH arg
|
798
798
|
{
|
@@ -800,7 +800,7 @@ rule
|
|
800
800
|
}
|
801
801
|
| tBANG arg
|
802
802
|
{
|
803
|
-
result = @builder.not_op(val[0], val[1])
|
803
|
+
result = @builder.not_op(val[0], nil, val[1], nil)
|
804
804
|
}
|
805
805
|
| tTILDE arg
|
806
806
|
{
|
@@ -984,7 +984,7 @@ rule
|
|
984
984
|
{
|
985
985
|
@lexer.cmdarg = val[1]
|
986
986
|
|
987
|
-
result = @builder.
|
987
|
+
result = @builder.begin_keyword(val[0], val[2], val[3])
|
988
988
|
}
|
989
989
|
| tLPAREN_ARG expr
|
990
990
|
{
|
@@ -1045,11 +1045,11 @@ rule
|
|
1045
1045
|
}
|
1046
1046
|
| kNOT tLPAREN2 expr rparen
|
1047
1047
|
{
|
1048
|
-
result = @builder.not_op(val[0], val[2])
|
1048
|
+
result = @builder.not_op(val[0], val[1], val[2], val[3])
|
1049
1049
|
}
|
1050
1050
|
| kNOT tLPAREN2 rparen
|
1051
1051
|
{
|
1052
|
-
result = @builder.not_op(val[0])
|
1052
|
+
result = @builder.not_op(val[0], val[1], nil, val[2])
|
1053
1053
|
}
|
1054
1054
|
| fcall brace_block
|
1055
1055
|
{
|
@@ -1247,6 +1247,9 @@ rule
|
|
1247
1247
|
then: term
|
1248
1248
|
| kTHEN
|
1249
1249
|
| term kTHEN
|
1250
|
+
{
|
1251
|
+
result = val[1]
|
1252
|
+
}
|
1250
1253
|
|
1251
1254
|
do: term
|
1252
1255
|
| kDO_COND
|
@@ -1830,7 +1833,7 @@ regexp_contents: # nothing
|
|
1830
1833
|
@lexer.cond.lexpop
|
1831
1834
|
@lexer.cmdarg.lexpop
|
1832
1835
|
|
1833
|
-
result = val[2]
|
1836
|
+
result = @builder.begin(val[0], val[2], val[3])
|
1834
1837
|
}
|
1835
1838
|
|
1836
1839
|
string_dvar: tGVAR
|
@@ -7,13 +7,9 @@ module Parser
|
|
7
7
|
|
8
8
|
class LocationProcessor < Parser::AST::Processor
|
9
9
|
def process(node)
|
10
|
-
|
10
|
+
if node
|
11
|
+
p node
|
11
12
|
|
12
|
-
if node.src.nil?
|
13
|
-
puts "\e[31m[no location info]\e[0m"
|
14
|
-
elsif node.src.expression.nil?
|
15
|
-
puts "\e[31m[location info present but empty]\e[0m"
|
16
|
-
else
|
17
13
|
source_line_no = nil
|
18
14
|
source_line = ""
|
19
15
|
hilight_line = ""
|
@@ -33,7 +29,7 @@ module Parser
|
|
33
29
|
source_line
|
34
30
|
end
|
35
31
|
|
36
|
-
node.
|
32
|
+
node.loc.to_hash.
|
37
33
|
sort_by do |name, range|
|
38
34
|
[(range ? range.line : 0),
|
39
35
|
(name == :expression ? 1 : 0)]
|
@@ -112,11 +108,11 @@ module Parser
|
|
112
108
|
end
|
113
109
|
|
114
110
|
def process_all_input
|
115
|
-
super
|
116
|
-
|
117
111
|
if input_size > 1
|
118
112
|
puts "Using #{@parser_class} to parse #{input_size} files."
|
119
113
|
end
|
114
|
+
|
115
|
+
super
|
120
116
|
end
|
121
117
|
|
122
118
|
def process(buffer)
|
data/lib/parser/version.rb
CHANGED
data/parser.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
|
-
spec.add_dependency 'ast', '~> 1.
|
27
|
+
spec.add_dependency 'ast', '~> 1.1'
|
28
28
|
spec.add_dependency 'slop', '~> 3.4'
|
29
29
|
|
30
30
|
spec.add_development_dependency 'bundler', '~> 1.2'
|
data/test/test_lexer.rb
CHANGED
@@ -2565,6 +2565,14 @@ class TestLexer < Minitest::Test
|
|
2565
2565
|
:tNL, nil)
|
2566
2566
|
end
|
2567
2567
|
|
2568
|
+
def test_bug_heredoc_lshft
|
2569
|
+
util_lex_token("<<RULES << CLEANINGS\nRULES",
|
2570
|
+
:tSTRING_BEG, '"',
|
2571
|
+
:tSTRING_END, 'RULES',
|
2572
|
+
:tLSHFT, '<<',
|
2573
|
+
:tCONSTANT, 'CLEANINGS')
|
2574
|
+
end
|
2575
|
+
|
2568
2576
|
def test_bug_expr_dot_comment
|
2569
2577
|
util_lex_token("foo. #bar\nbaz",
|
2570
2578
|
:tIDENTIFIER, 'foo',
|
data/test/test_parser.rb
CHANGED
@@ -42,7 +42,7 @@ class TestParser < Minitest::Test
|
|
42
42
|
|
43
43
|
def test_empty_stmt
|
44
44
|
assert_parses(
|
45
|
-
|
45
|
+
nil,
|
46
46
|
%q{})
|
47
47
|
end
|
48
48
|
|
@@ -120,11 +120,14 @@ class TestParser < Minitest::Test
|
|
120
120
|
assert_parses(
|
121
121
|
s(:dstr,
|
122
122
|
s(:str, 'foo'),
|
123
|
-
s(:lvar, :bar),
|
123
|
+
s(:begin, s(:lvar, :bar)),
|
124
124
|
s(:str, 'baz')),
|
125
125
|
%q{"foo#{bar}baz"},
|
126
126
|
%q{^ begin
|
127
127
|
| ^ end
|
128
|
+
| ^^ begin (begin)
|
129
|
+
| ^ end (begin)
|
130
|
+
| ~~~~~~ expression (begin)
|
128
131
|
|~~~~~~~~~~~~~~ expression})
|
129
132
|
end
|
130
133
|
|
@@ -181,11 +184,14 @@ class TestParser < Minitest::Test
|
|
181
184
|
assert_parses(
|
182
185
|
s(:dsym,
|
183
186
|
s(:str, 'foo'),
|
184
|
-
s(:lvar, :bar),
|
187
|
+
s(:begin, s(:lvar, :bar)),
|
185
188
|
s(:str, 'baz')),
|
186
189
|
%q{:"foo#{bar}baz"},
|
187
190
|
%q{^^ begin
|
188
191
|
| ^ end
|
192
|
+
| ^^ begin (begin)
|
193
|
+
| ^ end (begin)
|
194
|
+
| ~~~~~~ expression (begin)
|
189
195
|
|~~~~~~~~~~~~~~~ expression})
|
190
196
|
end
|
191
197
|
|
@@ -218,11 +224,14 @@ class TestParser < Minitest::Test
|
|
218
224
|
assert_parses(
|
219
225
|
s(:xstr,
|
220
226
|
s(:str, 'foo'),
|
221
|
-
s(:lvar, :bar),
|
227
|
+
s(:begin, s(:lvar, :bar)),
|
222
228
|
s(:str, 'baz')),
|
223
229
|
%q{`foo#{bar}baz`},
|
224
230
|
%q{^ begin
|
225
231
|
| ^ end
|
232
|
+
| ^^ begin (begin)
|
233
|
+
| ^ end (begin)
|
234
|
+
| ~~~~~~ expression (begin)
|
226
235
|
|~~~~~~~~~~~~~~ expression})
|
227
236
|
end
|
228
237
|
|
@@ -242,11 +251,14 @@ class TestParser < Minitest::Test
|
|
242
251
|
assert_parses(
|
243
252
|
s(:regexp,
|
244
253
|
s(:str, 'foo'),
|
245
|
-
s(:lvar, :bar),
|
254
|
+
s(:begin, s(:lvar, :bar)),
|
246
255
|
s(:str, 'baz'),
|
247
256
|
s(:regopt)),
|
248
257
|
%q{/foo#{bar}baz/},
|
249
258
|
%q{^ begin
|
259
|
+
| ^^ begin (begin)
|
260
|
+
| ^ end (begin)
|
261
|
+
| ~~~~~~ expression (begin)
|
250
262
|
| ^ end
|
251
263
|
|~~~~~~~~~~~~~~ expression})
|
252
264
|
end
|
@@ -325,18 +337,24 @@ class TestParser < Minitest::Test
|
|
325
337
|
assert_parses(
|
326
338
|
s(:array,
|
327
339
|
s(:str, "foo"),
|
328
|
-
s(:dstr, s(:lvar, :bar))),
|
340
|
+
s(:dstr, s(:begin, s(:lvar, :bar)))),
|
329
341
|
%q{%W[foo #{bar}]},
|
330
342
|
%q{^^^ begin
|
343
|
+
| ^^ begin (dstr.begin)
|
344
|
+
| ^ end (dstr.begin)
|
345
|
+
| ~~~~~~ expression (dstr.begin)
|
331
346
|
| ^ end
|
332
347
|
| ~~~ expression (str)
|
333
|
-
| ~~~ expression (dstr.lvar)
|
348
|
+
| ~~~ expression (dstr.begin.lvar)
|
334
349
|
|~~~~~~~~~~~~~~ expression})
|
335
350
|
|
336
351
|
assert_parses(
|
337
352
|
s(:array,
|
338
353
|
s(:str, "foo"),
|
339
|
-
s(:dstr,
|
354
|
+
s(:dstr,
|
355
|
+
s(:begin, s(:lvar, :bar)),
|
356
|
+
s(:str, 'foo'),
|
357
|
+
s(:ivar, :@baz))),
|
340
358
|
%q{%W[foo #{bar}foo#@baz]})
|
341
359
|
end
|
342
360
|
|
@@ -368,17 +386,23 @@ class TestParser < Minitest::Test
|
|
368
386
|
assert_parses(
|
369
387
|
s(:array,
|
370
388
|
s(:sym, :foo),
|
371
|
-
s(:dsym, s(:lvar, :bar))),
|
389
|
+
s(:dsym, s(:begin, s(:lvar, :bar)))),
|
372
390
|
%q{%I[foo #{bar}]},
|
373
391
|
%q{^^^ begin
|
374
392
|
| ^ end
|
375
393
|
| ~~~ expression (sym)
|
376
|
-
|
|
394
|
+
| ^^ begin (dsym.begin)
|
395
|
+
| ^ end (dsym.begin)
|
396
|
+
| ~~~~~~ expression (dsym.begin)
|
397
|
+
| ~~~ expression (dsym.begin.lvar)
|
377
398
|
|~~~~~~~~~~~~~~ expression},
|
378
399
|
ALL_VERSIONS - %w(1.8 1.9))
|
379
400
|
|
380
401
|
assert_parses(
|
381
|
-
s(:array,
|
402
|
+
s(:array,
|
403
|
+
s(:dsym,
|
404
|
+
s(:str, "foo"),
|
405
|
+
s(:begin, s(:lvar, :bar)))),
|
382
406
|
%q{%I[foo#{bar}]},
|
383
407
|
%q{},
|
384
408
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -1280,11 +1304,11 @@ class TestParser < Minitest::Test
|
|
1280
1304
|
assert_parses(
|
1281
1305
|
s(:module,
|
1282
1306
|
s(:const, nil, :Foo),
|
1283
|
-
|
1284
|
-
%q{module Foo;
|
1307
|
+
nil),
|
1308
|
+
%q{module Foo; end},
|
1285
1309
|
%q{~~~~~~ keyword
|
1286
1310
|
| ~~~ name
|
1287
|
-
|
|
1311
|
+
| ~~~ end})
|
1288
1312
|
end
|
1289
1313
|
|
1290
1314
|
def test_module_invalid
|
@@ -1297,20 +1321,20 @@ class TestParser < Minitest::Test
|
|
1297
1321
|
assert_parses(
|
1298
1322
|
s(:module,
|
1299
1323
|
s(:const, s(:cbase), :Foo),
|
1300
|
-
|
1301
|
-
%q{module ::Foo;
|
1324
|
+
nil),
|
1325
|
+
%q{module ::Foo; end})
|
1302
1326
|
|
1303
1327
|
assert_parses(
|
1304
1328
|
s(:module,
|
1305
1329
|
s(:const, s(:const, nil, :Bar), :Foo),
|
1306
|
-
|
1307
|
-
%q{module Bar::Foo;
|
1330
|
+
nil),
|
1331
|
+
%q{module Bar::Foo; end})
|
1308
1332
|
end
|
1309
1333
|
|
1310
1334
|
def test_cpath_invalid
|
1311
1335
|
assert_diagnoses(
|
1312
1336
|
[:error, :module_name_const],
|
1313
|
-
%q{module foo;
|
1337
|
+
%q{module foo; end})
|
1314
1338
|
end
|
1315
1339
|
|
1316
1340
|
def test_class
|
@@ -1318,11 +1342,11 @@ class TestParser < Minitest::Test
|
|
1318
1342
|
s(:class,
|
1319
1343
|
s(:const, nil, :Foo),
|
1320
1344
|
nil,
|
1321
|
-
|
1322
|
-
%q{class Foo;
|
1345
|
+
nil),
|
1346
|
+
%q{class Foo; end},
|
1323
1347
|
%q{~~~~~ keyword
|
1324
1348
|
| ~~~ name
|
1325
|
-
|
|
1349
|
+
| ~~~ end})
|
1326
1350
|
end
|
1327
1351
|
|
1328
1352
|
def test_class_super
|
@@ -1330,11 +1354,11 @@ class TestParser < Minitest::Test
|
|
1330
1354
|
s(:class,
|
1331
1355
|
s(:const, nil, :Foo),
|
1332
1356
|
s(:const, nil, :Bar),
|
1333
|
-
|
1334
|
-
%q{class Foo < Bar;
|
1357
|
+
nil),
|
1358
|
+
%q{class Foo < Bar; end},
|
1335
1359
|
%q{~~~~~ keyword
|
1336
1360
|
| ^ operator
|
1337
|
-
|
|
1361
|
+
| ~~~ end})
|
1338
1362
|
end
|
1339
1363
|
|
1340
1364
|
def test_class_super_label
|
@@ -1343,7 +1367,7 @@ class TestParser < Minitest::Test
|
|
1343
1367
|
s(:const, nil, :Foo),
|
1344
1368
|
s(:send, nil, :a,
|
1345
1369
|
s(:sym, :b)),
|
1346
|
-
|
1370
|
+
nil),
|
1347
1371
|
%q{class Foo < a:b; end},
|
1348
1372
|
%q{},
|
1349
1373
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -1372,50 +1396,50 @@ class TestParser < Minitest::Test
|
|
1372
1396
|
|
1373
1397
|
def test_def
|
1374
1398
|
assert_parses(
|
1375
|
-
s(:def, :foo, s(:args),
|
1376
|
-
%q{def foo;
|
1399
|
+
s(:def, :foo, s(:args), nil),
|
1400
|
+
%q{def foo; end},
|
1377
1401
|
%q{~~~ keyword
|
1378
1402
|
| ~~~ name
|
1379
|
-
|
|
1403
|
+
| ~~~ end})
|
1380
1404
|
|
1381
1405
|
assert_parses(
|
1382
|
-
s(:def, :String, s(:args),
|
1406
|
+
s(:def, :String, s(:args), nil),
|
1383
1407
|
%q{def String; end})
|
1384
1408
|
|
1385
1409
|
assert_parses(
|
1386
|
-
s(:def, :String=, s(:args),
|
1410
|
+
s(:def, :String=, s(:args), nil),
|
1387
1411
|
%q{def String=; end})
|
1388
1412
|
end
|
1389
1413
|
|
1390
1414
|
def test_defs
|
1391
1415
|
assert_parses(
|
1392
|
-
s(:defs, s(:self), :foo, s(:args),
|
1393
|
-
%q{def self.foo;
|
1416
|
+
s(:defs, s(:self), :foo, s(:args), nil),
|
1417
|
+
%q{def self.foo; end},
|
1394
1418
|
%q{~~~ keyword
|
1395
1419
|
| ^ operator
|
1396
1420
|
| ~~~ name
|
1397
|
-
|
|
1421
|
+
| ~~~ end})
|
1398
1422
|
|
1399
1423
|
assert_parses(
|
1400
|
-
s(:defs, s(:self), :foo, s(:args),
|
1401
|
-
%q{def self::foo;
|
1424
|
+
s(:defs, s(:self), :foo, s(:args), nil),
|
1425
|
+
%q{def self::foo; end},
|
1402
1426
|
%q{~~~ keyword
|
1403
1427
|
| ^^ operator
|
1404
1428
|
| ~~~ name
|
1405
|
-
|
|
1429
|
+
| ~~~ end})
|
1406
1430
|
|
1407
1431
|
assert_parses(
|
1408
|
-
s(:defs, s(:lvar, :foo), :foo, s(:args),
|
1432
|
+
s(:defs, s(:lvar, :foo), :foo, s(:args), nil),
|
1409
1433
|
%q{def (foo).foo; end})
|
1410
1434
|
|
1411
1435
|
assert_parses(
|
1412
1436
|
s(:defs, s(:const, nil, :String), :foo,
|
1413
|
-
s(:args),
|
1437
|
+
s(:args), nil),
|
1414
1438
|
%q{def String.foo; end})
|
1415
1439
|
|
1416
1440
|
assert_parses(
|
1417
1441
|
s(:defs, s(:const, nil, :String), :foo,
|
1418
|
-
s(:args),
|
1442
|
+
s(:args), nil),
|
1419
1443
|
%q{def String::foo; end})
|
1420
1444
|
end
|
1421
1445
|
|
@@ -1466,7 +1490,7 @@ class TestParser < Minitest::Test
|
|
1466
1490
|
s(:undef,
|
1467
1491
|
s(:sym, :foo),
|
1468
1492
|
s(:sym, :bar),
|
1469
|
-
s(:dsym, s(:str, "foo"), s(:int, 1))),
|
1493
|
+
s(:dsym, s(:str, "foo"), s(:begin, s(:int, 1)))),
|
1470
1494
|
%q{undef foo, :bar, :"foo#{1}"},
|
1471
1495
|
%q{~~~~~ keyword
|
1472
1496
|
| ~~~ expression (sym/1)
|
@@ -1862,7 +1886,7 @@ class TestParser < Minitest::Test
|
|
1862
1886
|
assert_parses(
|
1863
1887
|
s(:block,
|
1864
1888
|
s(:send, nil, :f),
|
1865
|
-
ast,
|
1889
|
+
ast, nil),
|
1866
1890
|
%Q{f{ #{code} }},
|
1867
1891
|
%q{},
|
1868
1892
|
versions)
|
@@ -2246,7 +2270,7 @@ class TestParser < Minitest::Test
|
|
2246
2270
|
assert_parses(
|
2247
2271
|
s(:def, :foo,
|
2248
2272
|
s(:args, s(:arg, :_), s(:arg, :_)),
|
2249
|
-
|
2273
|
+
nil),
|
2250
2274
|
%q{def foo(_, _); end},
|
2251
2275
|
%q{},
|
2252
2276
|
ALL_VERSIONS - %w(1.8))
|
@@ -2260,7 +2284,7 @@ class TestParser < Minitest::Test
|
|
2260
2284
|
assert_parses(
|
2261
2285
|
s(:def, :foo,
|
2262
2286
|
s(:args, s(:arg, :_a), s(:arg, :_a)),
|
2263
|
-
|
2287
|
+
nil),
|
2264
2288
|
%q{def foo(_a, _a); end},
|
2265
2289
|
%q{},
|
2266
2290
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -2336,19 +2360,19 @@ class TestParser < Minitest::Test
|
|
2336
2360
|
|
2337
2361
|
def test_send_self_block
|
2338
2362
|
assert_parses(
|
2339
|
-
s(:block, s(:send, nil, :fun), s(:args),
|
2363
|
+
s(:block, s(:send, nil, :fun), s(:args), nil),
|
2340
2364
|
%q{fun { }})
|
2341
2365
|
|
2342
2366
|
assert_parses(
|
2343
|
-
s(:block, s(:send, nil, :fun), s(:args),
|
2367
|
+
s(:block, s(:send, nil, :fun), s(:args), nil),
|
2344
2368
|
%q{fun() { }})
|
2345
2369
|
|
2346
2370
|
assert_parses(
|
2347
|
-
s(:block, s(:send, nil, :fun, s(:int, 1)), s(:args),
|
2371
|
+
s(:block, s(:send, nil, :fun, s(:int, 1)), s(:args), nil),
|
2348
2372
|
%q{fun(1) { }})
|
2349
2373
|
|
2350
2374
|
assert_parses(
|
2351
|
-
s(:block, s(:send, nil, :fun), s(:args),
|
2375
|
+
s(:block, s(:send, nil, :fun), s(:args), nil),
|
2352
2376
|
%q{fun do end})
|
2353
2377
|
end
|
2354
2378
|
|
@@ -2440,7 +2464,7 @@ class TestParser < Minitest::Test
|
|
2440
2464
|
s(:send,
|
2441
2465
|
s(:block,
|
2442
2466
|
s(:send, nil, :meth, s(:int, 1)),
|
2443
|
-
s(:args),
|
2467
|
+
s(:args), nil),
|
2444
2468
|
:fun, s(:lvar, :bar)),
|
2445
2469
|
%q{meth 1 do end.fun bar},
|
2446
2470
|
%q{ ~~~ selector
|
@@ -2451,7 +2475,7 @@ class TestParser < Minitest::Test
|
|
2451
2475
|
s(:send,
|
2452
2476
|
s(:block,
|
2453
2477
|
s(:send, nil, :meth, s(:int, 1)),
|
2454
|
-
s(:args),
|
2478
|
+
s(:args), nil),
|
2455
2479
|
:fun, s(:lvar, :bar)),
|
2456
2480
|
%q{meth 1 do end.fun(bar)},
|
2457
2481
|
%q{ ~~~ selector
|
@@ -2464,7 +2488,7 @@ class TestParser < Minitest::Test
|
|
2464
2488
|
s(:send,
|
2465
2489
|
s(:block,
|
2466
2490
|
s(:send, nil, :meth, s(:int, 1)),
|
2467
|
-
s(:args),
|
2491
|
+
s(:args), nil),
|
2468
2492
|
:fun, s(:lvar, :bar)),
|
2469
2493
|
%q{meth 1 do end::fun bar},
|
2470
2494
|
%q{ ~~~ selector
|
@@ -2475,7 +2499,7 @@ class TestParser < Minitest::Test
|
|
2475
2499
|
s(:send,
|
2476
2500
|
s(:block,
|
2477
2501
|
s(:send, nil, :meth, s(:int, 1)),
|
2478
|
-
s(:args),
|
2502
|
+
s(:args), nil),
|
2479
2503
|
:fun, s(:lvar, :bar)),
|
2480
2504
|
%q{meth 1 do end::fun(bar)},
|
2481
2505
|
%q{ ~~~ selector
|
@@ -2489,9 +2513,9 @@ class TestParser < Minitest::Test
|
|
2489
2513
|
s(:send,
|
2490
2514
|
s(:block,
|
2491
2515
|
s(:send, nil, :meth, s(:int, 1)),
|
2492
|
-
s(:args),
|
2516
|
+
s(:args), nil),
|
2493
2517
|
:fun, s(:lvar, :bar)),
|
2494
|
-
s(:args),
|
2518
|
+
s(:args), nil),
|
2495
2519
|
%q{meth 1 do end.fun bar do end},
|
2496
2520
|
%q{},
|
2497
2521
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -2501,9 +2525,9 @@ class TestParser < Minitest::Test
|
|
2501
2525
|
s(:send,
|
2502
2526
|
s(:block,
|
2503
2527
|
s(:send, nil, :meth, s(:int, 1)),
|
2504
|
-
s(:args),
|
2528
|
+
s(:args), nil),
|
2505
2529
|
:fun, s(:lvar, :bar)),
|
2506
|
-
s(:args),
|
2530
|
+
s(:args), nil),
|
2507
2531
|
%q{meth 1 do end.fun(bar) {}},
|
2508
2532
|
%q{},
|
2509
2533
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -2513,9 +2537,9 @@ class TestParser < Minitest::Test
|
|
2513
2537
|
s(:send,
|
2514
2538
|
s(:block,
|
2515
2539
|
s(:send, nil, :meth, s(:int, 1)),
|
2516
|
-
s(:args),
|
2540
|
+
s(:args), nil),
|
2517
2541
|
:fun),
|
2518
|
-
s(:args),
|
2542
|
+
s(:args), nil),
|
2519
2543
|
%q{meth 1 do end.fun {}},
|
2520
2544
|
%q{},
|
2521
2545
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -2526,7 +2550,7 @@ class TestParser < Minitest::Test
|
|
2526
2550
|
s(:send, nil, :foo,
|
2527
2551
|
s(:block,
|
2528
2552
|
s(:send, nil, :meth, s(:int, 1)),
|
2529
|
-
s(:args),
|
2553
|
+
s(:args), nil)),
|
2530
2554
|
%q{foo(meth 1 do end)},
|
2531
2555
|
%q{},
|
2532
2556
|
%w(1.8))
|
@@ -2536,7 +2560,7 @@ class TestParser < Minitest::Test
|
|
2536
2560
|
s(:int, 1),
|
2537
2561
|
s(:block,
|
2538
2562
|
s(:send, nil, :meth, s(:int, 1)),
|
2539
|
-
s(:args),
|
2563
|
+
s(:args), nil)),
|
2540
2564
|
%q{foo(1, meth 1 do end)},
|
2541
2565
|
%q{},
|
2542
2566
|
%w(1.8))
|
@@ -2710,7 +2734,7 @@ class TestParser < Minitest::Test
|
|
2710
2734
|
ALL_VERSIONS - %w(1.8))
|
2711
2735
|
|
2712
2736
|
assert_parses(
|
2713
|
-
s(:send, s(:
|
2737
|
+
s(:send, s(:begin), :'!'),
|
2714
2738
|
%q{not()},
|
2715
2739
|
%{},
|
2716
2740
|
ALL_VERSIONS - %w(1.8))
|
@@ -2803,7 +2827,7 @@ class TestParser < Minitest::Test
|
|
2803
2827
|
def test_send_lambda
|
2804
2828
|
assert_parses(
|
2805
2829
|
s(:block, s(:send, nil, :lambda),
|
2806
|
-
s(:args),
|
2830
|
+
s(:args), nil),
|
2807
2831
|
%q{->{ }},
|
2808
2832
|
%q{~~ selector (send)
|
2809
2833
|
| ^ begin
|
@@ -2813,7 +2837,7 @@ class TestParser < Minitest::Test
|
|
2813
2837
|
|
2814
2838
|
assert_parses(
|
2815
2839
|
s(:block, s(:send, nil, :lambda),
|
2816
|
-
s(:args),
|
2840
|
+
s(:args), nil),
|
2817
2841
|
%q{-> do end},
|
2818
2842
|
%q{~~ selector (send)
|
2819
2843
|
| ^^ begin
|
@@ -2827,7 +2851,7 @@ class TestParser < Minitest::Test
|
|
2827
2851
|
s(:block, s(:send, nil, :lambda),
|
2828
2852
|
s(:args,
|
2829
2853
|
s(:arg, :a)),
|
2830
|
-
|
2854
|
+
nil),
|
2831
2855
|
%q{->(a) { }},
|
2832
2856
|
%q{~~ selector (send)
|
2833
2857
|
| ^ begin (args)
|
@@ -2841,7 +2865,7 @@ class TestParser < Minitest::Test
|
|
2841
2865
|
s(:block, s(:send, nil, :lambda),
|
2842
2866
|
s(:args,
|
2843
2867
|
s(:arg, :a)),
|
2844
|
-
|
2868
|
+
nil),
|
2845
2869
|
%q{-> (a) { }},
|
2846
2870
|
%q{},
|
2847
2871
|
ALL_VERSIONS - %w(1.8 1.9))
|
@@ -2854,7 +2878,7 @@ class TestParser < Minitest::Test
|
|
2854
2878
|
s(:arg, :a),
|
2855
2879
|
s(:shadowarg, :foo),
|
2856
2880
|
s(:shadowarg, :bar)),
|
2857
|
-
|
2881
|
+
nil),
|
2858
2882
|
%q{->(a; foo, bar) { }},
|
2859
2883
|
%q{ ~~~ expression (args.shadowarg)},
|
2860
2884
|
ALL_VERSIONS - %w(1.8))
|
@@ -2882,6 +2906,32 @@ class TestParser < Minitest::Test
|
|
2882
2906
|
ALL_VERSIONS - %w(1.8))
|
2883
2907
|
end
|
2884
2908
|
|
2909
|
+
def test_lvar_injecting_match
|
2910
|
+
assert_parses(
|
2911
|
+
s(:begin,
|
2912
|
+
s(:match_with_lvasgn,
|
2913
|
+
s(:regexp,
|
2914
|
+
s(:str, '(?<match>bar)'),
|
2915
|
+
s(:regopt)),
|
2916
|
+
s(:str, 'bar')),
|
2917
|
+
s(:lvar, :match)),
|
2918
|
+
%q{/(?<match>bar)/ =~ 'bar'; match},
|
2919
|
+
%q{ ~~ selector (match_with_lvasgn)
|
2920
|
+
|~~~~~~~~~~~~~~~~~~~~~~~~ expression (match_with_lvasgn)},
|
2921
|
+
ALL_VERSIONS - %w(1.8))
|
2922
|
+
end
|
2923
|
+
|
2924
|
+
def test_non_lvar_injecting_match
|
2925
|
+
assert_parses(
|
2926
|
+
s(:send,
|
2927
|
+
s(:regexp,
|
2928
|
+
s(:begin, s(:str, '(?<match>bar)')),
|
2929
|
+
s(:regopt)),
|
2930
|
+
:=~,
|
2931
|
+
s(:str, 'bar')),
|
2932
|
+
%q{/#{'(?<match>bar)'}/ =~ 'bar'})
|
2933
|
+
end
|
2934
|
+
|
2885
2935
|
# To superclass
|
2886
2936
|
|
2887
2937
|
def test_super
|
@@ -3105,19 +3155,19 @@ class TestParser < Minitest::Test
|
|
3105
3155
|
assert_parses(
|
3106
3156
|
s(:block,
|
3107
3157
|
s(:send, nil, :fun, s(:begin, s(:int, 1))),
|
3108
|
-
s(:args),
|
3158
|
+
s(:args), nil),
|
3109
3159
|
%q{fun (1) {}})
|
3110
3160
|
|
3111
3161
|
assert_parses(
|
3112
3162
|
s(:block,
|
3113
3163
|
s(:send, s(:lvar, :foo), :fun, s(:begin, s(:int, 1))),
|
3114
|
-
s(:args),
|
3164
|
+
s(:args), nil),
|
3115
3165
|
%q{foo.fun (1) {}})
|
3116
3166
|
|
3117
3167
|
assert_parses(
|
3118
3168
|
s(:block,
|
3119
3169
|
s(:send, s(:lvar, :foo), :fun, s(:begin, s(:int, 1))),
|
3120
|
-
s(:args),
|
3170
|
+
s(:args), nil),
|
3121
3171
|
%q{foo::fun (1) {}})
|
3122
3172
|
end
|
3123
3173
|
|
@@ -3342,7 +3392,7 @@ class TestParser < Minitest::Test
|
|
3342
3392
|
assert_parses(
|
3343
3393
|
s(:block,
|
3344
3394
|
s(:send, nil, :fun),
|
3345
|
-
s(:args),
|
3395
|
+
s(:args), nil),
|
3346
3396
|
%q{fun () {}},
|
3347
3397
|
%q{ ^ begin (send)
|
3348
3398
|
| ^ end (send)},
|
@@ -3351,7 +3401,7 @@ class TestParser < Minitest::Test
|
|
3351
3401
|
assert_parses(
|
3352
3402
|
s(:block,
|
3353
3403
|
s(:send, s(:lvar, :foo), :fun),
|
3354
|
-
s(:args),
|
3404
|
+
s(:args), nil),
|
3355
3405
|
%q{foo.fun () {}},
|
3356
3406
|
%q{ ^ begin (send)
|
3357
3407
|
| ^ end (send)},
|
@@ -3360,7 +3410,7 @@ class TestParser < Minitest::Test
|
|
3360
3410
|
assert_parses(
|
3361
3411
|
s(:block,
|
3362
3412
|
s(:send, s(:lvar, :foo), :fun),
|
3363
|
-
s(:args),
|
3413
|
+
s(:args), nil),
|
3364
3414
|
%q{foo::fun () {}},
|
3365
3415
|
%q{ ^ begin (send)
|
3366
3416
|
| ^ end (send)},
|
@@ -3369,10 +3419,10 @@ class TestParser < Minitest::Test
|
|
3369
3419
|
assert_parses(
|
3370
3420
|
s(:block,
|
3371
3421
|
s(:send, nil, :fun,
|
3372
|
-
s(:
|
3373
|
-
s(:args),
|
3422
|
+
s(:begin)),
|
3423
|
+
s(:args), nil),
|
3374
3424
|
%q{fun () {}},
|
3375
|
-
%q{ ~~ expression (send.
|
3425
|
+
%q{ ~~ expression (send.begin)},
|
3376
3426
|
ALL_VERSIONS - %w(1.8 1.9))
|
3377
3427
|
end
|
3378
3428
|
|
@@ -3410,13 +3460,23 @@ class TestParser < Minitest::Test
|
|
3410
3460
|
|~~~~~~~~~~ expression})
|
3411
3461
|
end
|
3412
3462
|
|
3413
|
-
def
|
3414
|
-
|
3415
|
-
|
3463
|
+
def test_and_or_masgn
|
3464
|
+
assert_parses(
|
3465
|
+
s(:and,
|
3466
|
+
s(:lvar, :foo),
|
3467
|
+
s(:begin,
|
3468
|
+
s(:masgn,
|
3469
|
+
s(:mlhs, s(:lvasgn, :a), s(:lvasgn, :b)),
|
3470
|
+
s(:lvar, :bar)))),
|
3416
3471
|
%q{foo && (a, b = bar)})
|
3417
3472
|
|
3418
|
-
|
3419
|
-
|
3473
|
+
assert_parses(
|
3474
|
+
s(:or,
|
3475
|
+
s(:lvar, :foo),
|
3476
|
+
s(:begin,
|
3477
|
+
s(:masgn,
|
3478
|
+
s(:mlhs, s(:lvasgn, :a), s(:lvasgn, :b)),
|
3479
|
+
s(:lvar, :bar)))),
|
3420
3480
|
%q{foo || (a, b = bar)})
|
3421
3481
|
end
|
3422
3482
|
|
@@ -3439,6 +3499,13 @@ class TestParser < Minitest::Test
|
|
3439
3499
|
|~~~~~~~~~~~~~~~~ expression})
|
3440
3500
|
end
|
3441
3501
|
|
3502
|
+
def test_if_nl_then
|
3503
|
+
assert_parses(
|
3504
|
+
s(:if, s(:lvar, :foo), s(:lvar, :bar), nil),
|
3505
|
+
%Q{if foo\nthen bar end},
|
3506
|
+
%q{ ~~~~ begin})
|
3507
|
+
end
|
3508
|
+
|
3442
3509
|
def test_if_mod
|
3443
3510
|
assert_parses(
|
3444
3511
|
s(:if, s(:lvar, :foo), s(:lvar, :bar), nil),
|
@@ -3554,10 +3621,56 @@ class TestParser < Minitest::Test
|
|
3554
3621
|
end
|
3555
3622
|
|
3556
3623
|
def test_cond_begin_masgn
|
3624
|
+
assert_parses(
|
3625
|
+
s(:if,
|
3626
|
+
s(:begin,
|
3627
|
+
s(:lvar, :bar),
|
3628
|
+
s(:masgn,
|
3629
|
+
s(:mlhs, s(:lvasgn, :a), s(:lvasgn, :b)),
|
3630
|
+
s(:lvar, :foo))),
|
3631
|
+
nil, nil),
|
3632
|
+
%q{if (bar; a, b = foo); end})
|
3633
|
+
end
|
3634
|
+
|
3635
|
+
def test_cond_begin_and_or_masgn
|
3557
3636
|
assert_diagnoses(
|
3558
3637
|
[:error, :masgn_as_condition],
|
3559
|
-
%q{if (
|
3560
|
-
%q{
|
3638
|
+
%q{if foo && (a, b = bar); end},
|
3639
|
+
%q{ ~~~~~~~~~~ location})
|
3640
|
+
|
3641
|
+
assert_diagnoses(
|
3642
|
+
[:error, :masgn_as_condition],
|
3643
|
+
%q{if foo || (a, b = bar); end},
|
3644
|
+
%q{ ~~~~~~~~~~ location})
|
3645
|
+
end
|
3646
|
+
|
3647
|
+
def test_cond_iflipflop
|
3648
|
+
assert_parses(
|
3649
|
+
s(:if, s(:iflipflop, s(:lvar, :foo), s(:lvar, :bar)),
|
3650
|
+
nil, nil),
|
3651
|
+
%q{if foo..bar; end},
|
3652
|
+
%q{ ~~~~~~~~ expression (iflipflop)
|
3653
|
+
| ~~ operator (iflipflop)})
|
3654
|
+
end
|
3655
|
+
|
3656
|
+
def test_cond_eflipflop
|
3657
|
+
assert_parses(
|
3658
|
+
s(:if, s(:eflipflop, s(:lvar, :foo), s(:lvar, :bar)),
|
3659
|
+
nil, nil),
|
3660
|
+
%q{if foo...bar; end},
|
3661
|
+
%q{ ~~~~~~~~~ expression (eflipflop)
|
3662
|
+
| ~~~ operator (eflipflop)})
|
3663
|
+
end
|
3664
|
+
|
3665
|
+
def test_cond_match_current_line
|
3666
|
+
assert_parses(
|
3667
|
+
s(:if,
|
3668
|
+
s(:match_current_line,
|
3669
|
+
s(:regexp,
|
3670
|
+
s(:str, 'wat'),
|
3671
|
+
s(:regopt))),
|
3672
|
+
nil, nil),
|
3673
|
+
%q{if /wat/; end})
|
3561
3674
|
end
|
3562
3675
|
|
3563
3676
|
# Case matching
|
@@ -3659,7 +3772,7 @@ class TestParser < Minitest::Test
|
|
3659
3772
|
s(:lvar, :bar)),
|
3660
3773
|
s(:when,
|
3661
3774
|
s(:splat, s(:lvar, :foo)),
|
3662
|
-
|
3775
|
+
nil),
|
3663
3776
|
nil),
|
3664
3777
|
%q{case foo; when 1, *baz; bar; when *foo; end},
|
3665
3778
|
%q{ ^ operator (when/1.splat)
|
@@ -3803,7 +3916,7 @@ class TestParser < Minitest::Test
|
|
3803
3916
|
|~~~~~~~~~ expression})
|
3804
3917
|
|
3805
3918
|
assert_parses(
|
3806
|
-
s(:break, s(:
|
3919
|
+
s(:break, s(:begin)),
|
3807
3920
|
%q{break()},
|
3808
3921
|
%q{~~~~~ keyword
|
3809
3922
|
|~~~~~~~ expression},
|
@@ -3838,7 +3951,7 @@ class TestParser < Minitest::Test
|
|
3838
3951
|
|~~~~~~~~~~ expression})
|
3839
3952
|
|
3840
3953
|
assert_parses(
|
3841
|
-
s(:return, s(:
|
3954
|
+
s(:return, s(:begin)),
|
3842
3955
|
%q{return()},
|
3843
3956
|
%q{~~~~~~ keyword
|
3844
3957
|
|~~~~~~~~ expression},
|
@@ -3873,7 +3986,7 @@ class TestParser < Minitest::Test
|
|
3873
3986
|
|~~~~~~~~ expression})
|
3874
3987
|
|
3875
3988
|
assert_parses(
|
3876
|
-
s(:next, s(:
|
3989
|
+
s(:next, s(:begin)),
|
3877
3990
|
%q{next()},
|
3878
3991
|
%q{~~~~ keyword
|
3879
3992
|
|~~~~~~ expression},
|
@@ -3945,8 +4058,7 @@ class TestParser < Minitest::Test
|
|
3945
4058
|
def test_ensure_empty
|
3946
4059
|
assert_parses(
|
3947
4060
|
s(:begin,
|
3948
|
-
s(:ensure,
|
3949
|
-
s(:nil))),
|
4061
|
+
s(:ensure, nil, nil)),
|
3950
4062
|
%q{begin ensure end},
|
3951
4063
|
%q{~~~~~ begin
|
3952
4064
|
| ~~~~~~ keyword (ensure)
|
@@ -4280,23 +4392,23 @@ class TestParser < Minitest::Test
|
|
4280
4392
|
s(:block,
|
4281
4393
|
s(:send, nil, :desc,
|
4282
4394
|
s(:str, "foo")),
|
4283
|
-
s(:args),
|
4395
|
+
s(:args), nil),
|
4284
4396
|
%q{desc "foo" do end})
|
4285
4397
|
end
|
4286
4398
|
|
4287
4399
|
def test_bug_interp_single
|
4288
4400
|
assert_parses(
|
4289
|
-
s(:dstr, s(:int, 1)),
|
4401
|
+
s(:dstr, s(:begin, s(:int, 1))),
|
4290
4402
|
%q{"#{1}"})
|
4291
4403
|
|
4292
4404
|
assert_parses(
|
4293
|
-
s(:array, s(:dstr, s(:int, 1))),
|
4405
|
+
s(:array, s(:dstr, s(:begin, s(:int, 1)))),
|
4294
4406
|
%q{%W"#{1}"})
|
4295
4407
|
end
|
4296
4408
|
|
4297
4409
|
def test_bug_def_no_paren_eql_begin
|
4298
4410
|
assert_parses(
|
4299
|
-
s(:def, :foo, s(:args),
|
4411
|
+
s(:def, :foo, s(:args), nil),
|
4300
4412
|
%Q{def foo\n=begin\n=end\nend})
|
4301
4413
|
end
|
4302
4414
|
end
|