ruby_parser 3.13.1 → 3.21.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/.autotest +18 -29
- data/History.rdoc +312 -0
- data/Manifest.txt +16 -15
- data/README.rdoc +13 -9
- data/Rakefile +237 -106
- data/bin/ruby_parse +3 -1
- data/bin/ruby_parse_extract_error +9 -4
- data/compare/normalize.rb +54 -6
- data/debugging.md +172 -0
- data/gauntlet.md +107 -0
- data/lib/rp_extensions.rb +15 -36
- data/lib/rp_stringscanner.rb +20 -51
- data/lib/ruby_lexer.rb +515 -812
- data/lib/ruby_lexer.rex +33 -27
- data/lib/ruby_lexer.rex.rb +64 -31
- data/lib/ruby_lexer_strings.rb +638 -0
- data/lib/ruby_parser.rb +46 -36
- data/lib/{ruby_parser.yy → ruby_parser2.yy} +1400 -488
- data/lib/ruby_parser20.rb +10953 -0
- data/lib/ruby_parser21.rb +10978 -0
- data/lib/ruby_parser22.rb +11119 -0
- data/lib/ruby_parser23.rb +11160 -0
- data/lib/ruby_parser24.rb +11209 -0
- data/lib/ruby_parser25.rb +11209 -0
- data/lib/ruby_parser26.rb +11231 -0
- data/lib/ruby_parser27.rb +12960 -0
- data/lib/{ruby26_parser.y → ruby_parser3.yy} +1652 -521
- data/lib/ruby_parser30.rb +13292 -0
- data/lib/ruby_parser31.rb +13625 -0
- data/lib/ruby_parser32.rb +13577 -0
- data/lib/ruby_parser33.rb +13577 -0
- data/lib/ruby_parser_extras.rb +988 -474
- data/test/test_ruby_lexer.rb +1339 -1155
- data/test/test_ruby_parser.rb +4255 -2103
- data/test/test_ruby_parser_extras.rb +39 -4
- data/tools/munge.rb +52 -13
- data/tools/ripper.rb +24 -6
- data.tar.gz.sig +0 -0
- metadata +73 -56
- metadata.gz.sig +0 -0
- data/lib/ruby20_parser.rb +0 -6869
- data/lib/ruby20_parser.y +0 -2431
- data/lib/ruby21_parser.rb +0 -6944
- data/lib/ruby21_parser.y +0 -2449
- data/lib/ruby22_parser.rb +0 -6968
- data/lib/ruby22_parser.y +0 -2458
- data/lib/ruby23_parser.rb +0 -6987
- data/lib/ruby23_parser.y +0 -2460
- data/lib/ruby24_parser.rb +0 -6994
- data/lib/ruby24_parser.y +0 -2466
- data/lib/ruby25_parser.rb +0 -6994
- data/lib/ruby25_parser.y +0 -2466
- data/lib/ruby26_parser.rb +0 -7012
data/test/test_ruby_lexer.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: US-ASCII
|
2
|
-
# TODO: work this out
|
3
|
-
|
4
1
|
require "minitest/autorun"
|
5
2
|
require "ruby_lexer"
|
6
3
|
require "ruby_parser"
|
@@ -10,8 +7,8 @@ class TestRubyLexer < Minitest::Test
|
|
10
7
|
|
11
8
|
attr_accessor :processor, :lex, :parser_class, :lex_state
|
12
9
|
|
13
|
-
alias
|
14
|
-
alias
|
10
|
+
alias lexer lex # lets me copy/paste code from parser
|
11
|
+
alias lexer= lex=
|
15
12
|
|
16
13
|
def setup
|
17
14
|
self.lex_state = EXPR_BEG
|
@@ -21,12 +18,7 @@ class TestRubyLexer < Minitest::Test
|
|
21
18
|
def setup_lexer input, exp_sexp = nil
|
22
19
|
setup_new_parser
|
23
20
|
lex.ss = RPStringScanner.new(input)
|
24
|
-
lex.lex_state =
|
25
|
-
end
|
26
|
-
|
27
|
-
def setup_new_parser
|
28
|
-
self.processor = parser_class.new
|
29
|
-
self.lex = processor.lexer
|
21
|
+
lex.lex_state = lex_state
|
30
22
|
end
|
31
23
|
|
32
24
|
def setup_lexer_class parser_class
|
@@ -35,11 +27,16 @@ class TestRubyLexer < Minitest::Test
|
|
35
27
|
setup_lexer "blah blah"
|
36
28
|
end
|
37
29
|
|
38
|
-
def
|
30
|
+
def setup_new_parser
|
31
|
+
self.processor = parser_class.new
|
32
|
+
self.lex = processor.lexer
|
33
|
+
end
|
34
|
+
|
35
|
+
def assert_lex input, exp_sexp, *args
|
39
36
|
setup_lexer input
|
40
37
|
assert_parse input, exp_sexp if exp_sexp
|
41
38
|
|
42
|
-
|
39
|
+
yield if block_given?
|
43
40
|
|
44
41
|
args.each_slice(5) do |token, value, state, paren, brace|
|
45
42
|
assert_next_lexeme token, value, state, paren, brace
|
@@ -49,13 +46,15 @@ class TestRubyLexer < Minitest::Test
|
|
49
46
|
end
|
50
47
|
|
51
48
|
def assert_lex3 input, exp_sexp, *args, &block
|
49
|
+
# TODO: refute_nil exp_sexp, "Get off your lazy butt and write one"
|
50
|
+
|
52
51
|
args = args.each_slice(3).map { |a, b, c| [a, b, c, nil, nil] }.flatten
|
53
52
|
|
54
53
|
assert_lex(input, exp_sexp, *args, &block)
|
55
54
|
end
|
56
55
|
|
57
|
-
def
|
58
|
-
args = args.each_slice(
|
56
|
+
def refute_lex3 input, *args # TODO: re-sort
|
57
|
+
args = args.each_slice(3).map { |a, b, c| [a, b, c, nil, nil] }.flatten
|
59
58
|
|
60
59
|
assert_raises RubyParser::SyntaxError do
|
61
60
|
assert_lex(input, nil, *args)
|
@@ -73,29 +72,30 @@ class TestRubyLexer < Minitest::Test
|
|
73
72
|
def assert_next_lexeme token=nil, value=nil, state=nil, paren=nil, brace=nil
|
74
73
|
adv = @lex.next_token
|
75
74
|
|
76
|
-
assert adv, "no more tokens"
|
75
|
+
assert adv, "no more tokens, expecting: %p %p %p %p %p" % [token, value, state, paren, brace]
|
77
76
|
|
78
77
|
act_token, act_value = adv
|
79
78
|
|
80
79
|
msg = message {
|
81
|
-
act = [act_token, act_value, @lex.lex_state,
|
82
|
-
@lex.paren_nest, @lex.brace_nest]
|
80
|
+
act = [act_token, act_value, @lex.lex_state, @lex.paren_nest, @lex.brace_nest]
|
83
81
|
exp = [token, value, state, paren, brace]
|
84
82
|
"#{exp.inspect} vs #{act.inspect}"
|
85
83
|
}
|
86
84
|
|
87
85
|
act_value = act_value.first if Array === act_value
|
88
86
|
|
89
|
-
assert_equal token, act_token,
|
87
|
+
assert_equal token, act_token, msg
|
90
88
|
case value
|
91
89
|
when Float then
|
92
90
|
assert_in_epsilon value, act_value, 0.001, msg
|
93
91
|
when NilClass then
|
94
92
|
assert_nil act_value, msg
|
93
|
+
when String then
|
94
|
+
assert_equal value, act_value.b.force_encoding(value.encoding), msg
|
95
95
|
else
|
96
|
-
assert_equal value, act_value,
|
96
|
+
assert_equal value, act_value, msg
|
97
97
|
end
|
98
|
-
|
98
|
+
assert_match state, @lex.lex_state, msg if state
|
99
99
|
assert_equal paren, @lex.paren_nest, msg if paren
|
100
100
|
assert_equal brace, @lex.brace_nest, msg if brace
|
101
101
|
end
|
@@ -105,21 +105,36 @@ class TestRubyLexer < Minitest::Test
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def assert_read_escape expected, input
|
108
|
-
|
109
|
-
|
108
|
+
setup_lexer input
|
109
|
+
enc = expected.encoding
|
110
|
+
assert_equal expected, lex.read_escape.b.force_encoding(enc), input
|
110
111
|
end
|
111
112
|
|
112
113
|
def assert_read_escape_bad input # TODO: rename refute_read_escape
|
113
|
-
|
114
|
+
setup_lexer input
|
115
|
+
assert_raises RubyParser::SyntaxError do
|
116
|
+
lex.read_escape
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def refute_lex input, *args # TODO: re-sort
|
121
|
+
args = args.each_slice(2).map { |a, b| [a, b, nil, nil, nil] }.flatten
|
122
|
+
|
114
123
|
assert_raises RubyParser::SyntaxError do
|
115
|
-
|
124
|
+
assert_lex(input, nil, *args)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def refute_lex5 input, *args
|
129
|
+
assert_raises RubyParser::SyntaxError do
|
130
|
+
assert_lex(input, *args)
|
116
131
|
end
|
117
132
|
end
|
118
133
|
|
119
134
|
def refute_lexeme
|
120
135
|
x = y = @lex.next_token
|
121
136
|
|
122
|
-
refute x, "not empty: #{y.inspect}"
|
137
|
+
refute x, "not empty: #{y.inspect}: #{@lex.rest.inspect}"
|
123
138
|
end
|
124
139
|
|
125
140
|
## Utility Methods:
|
@@ -140,7 +155,7 @@ class TestRubyLexer < Minitest::Test
|
|
140
155
|
yield
|
141
156
|
|
142
157
|
lexer.lex_state = EXPR_ENDARG
|
143
|
-
assert_next_lexeme :tSTRING_DEND, "}",
|
158
|
+
assert_next_lexeme :tSTRING_DEND, "}", EXPR_END|EXPR_ENDARG, 0
|
144
159
|
|
145
160
|
lexer.lex_strterm = lex_strterm
|
146
161
|
lexer.lex_state = EXPR_BEG
|
@@ -154,14 +169,25 @@ class TestRubyLexer < Minitest::Test
|
|
154
169
|
## Tests:
|
155
170
|
|
156
171
|
def test_next_token
|
157
|
-
assert_equal [:tIDENTIFIER, "blah"], @lex.next_token
|
158
|
-
assert_equal [:tIDENTIFIER, "blah"], @lex.next_token
|
172
|
+
assert_equal [:tIDENTIFIER, ["blah", 1]], @lex.next_token
|
173
|
+
assert_equal [:tIDENTIFIER, ["blah", 1]], @lex.next_token
|
159
174
|
assert_nil @lex.next_token
|
160
175
|
end
|
161
176
|
|
162
|
-
def
|
163
|
-
|
164
|
-
|
177
|
+
def test_pct_w_backslashes
|
178
|
+
["\t", "\n", "\r", "\v", "\f"].each do |char|
|
179
|
+
next if !RubyLexer::HAS_ENC and char == "\v"
|
180
|
+
|
181
|
+
assert_lex("%w[foo#{char}bar]",
|
182
|
+
s(:array, s(:str, "foo"), s(:str, "bar")),
|
183
|
+
|
184
|
+
:tQWORDS_BEG, "%w[", EXPR_BEG, 0, 0,
|
185
|
+
:tSTRING_CONTENT, "foo", EXPR_BEG, 0, 0,
|
186
|
+
:tSPACE, " ", EXPR_BEG, 0, 0,
|
187
|
+
:tSTRING_CONTENT, "bar", EXPR_BEG, 0, 0,
|
188
|
+
:tSPACE, "]", EXPR_BEG, 0, 0,
|
189
|
+
:tSTRING_END, "]", EXPR_LIT, 0, 0)
|
190
|
+
end
|
165
191
|
end
|
166
192
|
|
167
193
|
def test_read_escape
|
@@ -217,6 +243,90 @@ class TestRubyLexer < Minitest::Test
|
|
217
243
|
assert_read_escape "\230", 'M-\cx'
|
218
244
|
end
|
219
245
|
|
246
|
+
def test_ruby21_imaginary_literal
|
247
|
+
setup_lexer_class RubyParser::V21
|
248
|
+
|
249
|
+
assert_lex3("1i", nil, :tIMAGINARY, Complex(0, 1), EXPR_NUM)
|
250
|
+
assert_lex3("0x10i", nil, :tIMAGINARY, Complex(0, 16), EXPR_NUM)
|
251
|
+
assert_lex3("0o10i", nil, :tIMAGINARY, Complex(0, 8), EXPR_NUM)
|
252
|
+
assert_lex3("0oi", nil, :tIMAGINARY, Complex(0, 0), EXPR_NUM)
|
253
|
+
assert_lex3("0b10i", nil, :tIMAGINARY, Complex(0, 2), EXPR_NUM)
|
254
|
+
assert_lex3("1.5i", nil, :tIMAGINARY, Complex(0, 1.5), EXPR_NUM)
|
255
|
+
assert_lex3("15e3i", nil, :tIMAGINARY, Complex(0, 15000), EXPR_NUM)
|
256
|
+
assert_lex3("15e-3i", nil, :tIMAGINARY, Complex(0, 0.015), EXPR_NUM)
|
257
|
+
assert_lex3("1.5e3i", nil, :tIMAGINARY, Complex(0, 1500), EXPR_NUM)
|
258
|
+
assert_lex3("1.5e-3i", nil, :tIMAGINARY, Complex(0, 0.0015), EXPR_NUM)
|
259
|
+
|
260
|
+
c010 = Complex(0, 10)
|
261
|
+
assert_lex3("-10i", nil,
|
262
|
+
:tUMINUS_NUM, "-", EXPR_BEG,
|
263
|
+
:tIMAGINARY, c010, EXPR_NUM)
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_ruby21_imaginary_literal_with_succeeding_keyword
|
267
|
+
setup_lexer_class RubyParser::V21
|
268
|
+
|
269
|
+
# 2/4 scenarios are syntax errors on all tested versions so I
|
270
|
+
# deleted them.
|
271
|
+
|
272
|
+
assert_lex3("1if", nil,
|
273
|
+
:tINTEGER, 1, EXPR_NUM,
|
274
|
+
:kIF_MOD, "if", EXPR_PAR)
|
275
|
+
assert_lex3("1.0if", nil,
|
276
|
+
:tFLOAT, 1.0, EXPR_NUM,
|
277
|
+
:kIF_MOD, "if", EXPR_PAR)
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_ruby21_rational_imaginary_literal
|
281
|
+
setup_lexer_class RubyParser::V21
|
282
|
+
|
283
|
+
assert_lex3 "1ri", nil, :tIMAGINARY, Complex(0, Rational(1)), EXPR_NUM
|
284
|
+
assert_lex3 "0x10ri", nil, :tIMAGINARY, Complex(0, Rational(16)), EXPR_NUM
|
285
|
+
assert_lex3 "0o10ri", nil, :tIMAGINARY, Complex(0, Rational(8)), EXPR_NUM
|
286
|
+
assert_lex3 "0ori", nil, :tIMAGINARY, Complex(0, Rational(0)), EXPR_NUM
|
287
|
+
assert_lex3 "0b10ri", nil, :tIMAGINARY, Complex(0, Rational(2)), EXPR_NUM
|
288
|
+
assert_lex3 "1.5ri", nil, :tIMAGINARY, Complex(0, Rational("1.5")), EXPR_NUM
|
289
|
+
assert_lex3 "15e3ri", nil, :tIMAGINARY, Complex(0, Rational("15e3")), EXPR_NUM
|
290
|
+
assert_lex3 "15e-3ri", nil, :tIMAGINARY, Complex(0, Rational("15e-3")), EXPR_NUM
|
291
|
+
assert_lex3 "1.5e3ri", nil, :tIMAGINARY, Complex(0, Rational("1.5e3")), EXPR_NUM
|
292
|
+
assert_lex3 "1.5e-3ri", nil, :tIMAGINARY, Complex(0, Rational("1.5e-3")), EXPR_NUM
|
293
|
+
|
294
|
+
assert_lex3("-10ri", nil,
|
295
|
+
:tUMINUS_NUM, "-", EXPR_BEG,
|
296
|
+
:tIMAGINARY, Complex(0, Rational(10)), EXPR_NUM)
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_ruby21_rational_literal
|
300
|
+
setup_lexer_class RubyParser::V21
|
301
|
+
|
302
|
+
assert_lex3("10r", nil, :tRATIONAL, Rational(10), EXPR_NUM)
|
303
|
+
assert_lex3("0x10r", nil, :tRATIONAL, Rational(16), EXPR_NUM)
|
304
|
+
assert_lex3("0o10r", nil, :tRATIONAL, Rational(8), EXPR_NUM)
|
305
|
+
assert_lex3("0or", nil, :tRATIONAL, Rational(0), EXPR_NUM)
|
306
|
+
assert_lex3("0b10r", nil, :tRATIONAL, Rational(2), EXPR_NUM)
|
307
|
+
assert_lex3("1.5r", nil, :tRATIONAL, Rational(15, 10), EXPR_NUM)
|
308
|
+
assert_lex3("15e3r", nil, :tRATIONAL, Rational(15000), EXPR_NUM)
|
309
|
+
assert_lex3("15e-3r", nil, :tRATIONAL, Rational(15, 1000), EXPR_NUM)
|
310
|
+
assert_lex3("1.5e3r", nil, :tRATIONAL, Rational(1500), EXPR_NUM)
|
311
|
+
assert_lex3("1.5e-3r", nil, :tRATIONAL, Rational(15, 10000), EXPR_NUM)
|
312
|
+
|
313
|
+
r10 = Rational(10)
|
314
|
+
assert_lex3("-10r", nil,
|
315
|
+
:tUMINUS_NUM, "-", EXPR_BEG,
|
316
|
+
:tRATIONAL, r10, EXPR_NUM)
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_unicode_ident
|
320
|
+
s = "@\u1088\u1077\u1093\u1072"
|
321
|
+
assert_lex3(s.dup, nil, :tIVAR, s.dup, EXPR_END)
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_why_does_ruby_hate_me?
|
325
|
+
assert_lex3("\"Nl%\\000\\000A\\000\\999\"", # you should be ashamed
|
326
|
+
nil,
|
327
|
+
:tSTRING, %W[ Nl% \u0000 \u0000 A \u0000 999 ].join, EXPR_END)
|
328
|
+
end
|
329
|
+
|
220
330
|
def test_yylex_ambiguous_uminus
|
221
331
|
assert_lex3("m -3",
|
222
332
|
nil,
|
@@ -248,6 +358,15 @@ class TestRubyLexer < Minitest::Test
|
|
248
358
|
assert_lex3("&&=", nil, :tOP_ASGN, "&&", EXPR_BEG)
|
249
359
|
end
|
250
360
|
|
361
|
+
def test_yylex_and_arg
|
362
|
+
self.lex_state = EXPR_ARG
|
363
|
+
|
364
|
+
assert_lex3(" &y",
|
365
|
+
nil,
|
366
|
+
:tAMPER, "&", EXPR_BEG,
|
367
|
+
:tIDENTIFIER, "y", EXPR_ARG)
|
368
|
+
end
|
369
|
+
|
251
370
|
def test_yylex_and_dot
|
252
371
|
setup_lexer_class RubyParser::V23
|
253
372
|
|
@@ -272,15 +391,6 @@ class TestRubyLexer < Minitest::Test
|
|
272
391
|
:tIDENTIFIER, "y")
|
273
392
|
end
|
274
393
|
|
275
|
-
def test_yylex_and_arg
|
276
|
-
self.lex_state = EXPR_ARG
|
277
|
-
|
278
|
-
assert_lex3(" &y",
|
279
|
-
nil,
|
280
|
-
:tAMPER, "&", EXPR_BEG,
|
281
|
-
:tIDENTIFIER, "y", EXPR_ARG)
|
282
|
-
end
|
283
|
-
|
284
394
|
def test_yylex_and_equals
|
285
395
|
assert_lex3("&=", nil, :tOP_ASGN, "&", EXPR_BEG)
|
286
396
|
end
|
@@ -303,400 +413,104 @@ class TestRubyLexer < Minitest::Test
|
|
303
413
|
assert_lex3 "=>", nil, :tASSOC, "=>", EXPR_BEG
|
304
414
|
end
|
305
415
|
|
306
|
-
def
|
307
|
-
|
308
|
-
|
309
|
-
assert_lex3("{a:",
|
416
|
+
def test_yylex_back_ref
|
417
|
+
assert_lex3("[$&, $`, $', $+]",
|
310
418
|
nil,
|
311
|
-
:
|
312
|
-
:
|
419
|
+
:tLBRACK, "[", EXPR_PAR,
|
420
|
+
:tBACK_REF, :&, EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
421
|
+
:tBACK_REF, :"`", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
422
|
+
:tBACK_REF, :"'", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
423
|
+
:tBACK_REF, :+, EXPR_END,
|
424
|
+
:tRBRACK, "]", EXPR_END)
|
313
425
|
end
|
314
426
|
|
315
|
-
def
|
316
|
-
|
317
|
-
|
318
|
-
assert_lex3("foo(a:",
|
427
|
+
def test_yylex_backslash
|
428
|
+
assert_lex3("1 \\\n+ 2",
|
319
429
|
nil,
|
320
|
-
:
|
321
|
-
:
|
322
|
-
:
|
430
|
+
:tINTEGER, 1, EXPR_NUM,
|
431
|
+
:tPLUS, "+", EXPR_BEG,
|
432
|
+
:tINTEGER, 2, EXPR_NUM)
|
323
433
|
end
|
324
434
|
|
325
|
-
def
|
326
|
-
|
327
|
-
|
328
|
-
"(",
|
329
|
-
s(:evstr, s(:call, nil, :b)),
|
330
|
-
s(:evstr, s(:call, nil, :d)),
|
331
|
-
s(:str, ")")))
|
332
|
-
|
333
|
-
assert_next_lexeme :tSTRING_BEG, "%)", EXPR_BEG, 0, 0
|
334
|
-
assert_next_lexeme :tSTRING_CONTENT, "(", EXPR_BEG, 0, 0
|
335
|
-
assert_next_lexeme :tSTRING_DBEG, nil, EXPR_BEG, 0, 0
|
435
|
+
def test_yylex_backslash_bad
|
436
|
+
refute_lex("1 \\ + 2", :tINTEGER, 1)
|
437
|
+
end
|
336
438
|
|
337
|
-
|
338
|
-
|
339
|
-
|
439
|
+
def test_yylex_backtick
|
440
|
+
assert_lex3("`ls`",
|
441
|
+
nil,
|
442
|
+
:tXSTRING_BEG, "`", EXPR_BEG,
|
443
|
+
:tSTRING_CONTENT, "ls", EXPR_BEG,
|
444
|
+
:tSTRING_END, "`", EXPR_LIT)
|
445
|
+
end
|
340
446
|
|
341
|
-
|
447
|
+
def test_yylex_backtick_cmdarg
|
448
|
+
self.lex_state = EXPR_DOT
|
342
449
|
|
343
|
-
|
344
|
-
|
345
|
-
|
450
|
+
# \n ensures expr_cmd (TODO: why?)
|
451
|
+
assert_lex3("\n`", nil, :tBACK_REF2, "`", EXPR_CMDARG)
|
452
|
+
end
|
346
453
|
|
347
|
-
|
348
|
-
|
454
|
+
def test_yylex_backtick_dot
|
455
|
+
self.lex_state = EXPR_DOT
|
349
456
|
|
350
|
-
|
457
|
+
assert_lex3("a.`(3)",
|
458
|
+
nil,
|
459
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
460
|
+
:tDOT, ".", EXPR_DOT,
|
461
|
+
:tBACK_REF2, "`", EXPR_ARG,
|
462
|
+
:tLPAREN2, "(", EXPR_PAR,
|
463
|
+
:tINTEGER, 3, EXPR_NUM,
|
464
|
+
:tRPAREN, ")", EXPR_ENDFN)
|
351
465
|
end
|
352
466
|
|
353
|
-
def
|
354
|
-
|
355
|
-
s(:dstr, " ", s(:evstr, s(:lit, /abcd/)), s(:str, " ")))
|
467
|
+
def test_yylex_backtick_method
|
468
|
+
self.lex_state = EXPR_FNAME
|
356
469
|
|
357
|
-
|
358
|
-
|
359
|
-
|
470
|
+
assert_lex3("`",
|
471
|
+
nil,
|
472
|
+
:tBACK_REF2, "`", EXPR_END)
|
473
|
+
end
|
360
474
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
assert_next_lexeme :tSTRING_CONTENT, "abcd", EXPR_PAR, 1, 0
|
365
|
-
assert_next_lexeme :tREGEXP_END, "", EXPR_END, 1, 0
|
366
|
-
assert_next_lexeme :tRPAREN, ")", EXPR_ENDFN, 0, 0
|
367
|
-
end
|
475
|
+
def test_yylex_bad_char
|
476
|
+
refute_lex(" \010 ")
|
477
|
+
end
|
368
478
|
|
369
|
-
|
370
|
-
|
479
|
+
def test_yylex_bang
|
480
|
+
assert_lex3("!", nil, :tBANG, "!", EXPR_BEG)
|
481
|
+
end
|
371
482
|
|
372
|
-
|
483
|
+
def test_yylex_bang_equals
|
484
|
+
assert_lex3("!=", nil, :tNEQ, "!=", EXPR_BEG)
|
373
485
|
end
|
374
486
|
|
375
|
-
def
|
376
|
-
|
487
|
+
def test_yylex_bang_tilde
|
488
|
+
assert_lex3("!~", nil, :tNMATCH, "!~", EXPR_BEG)
|
489
|
+
end
|
377
490
|
|
378
|
-
|
379
|
-
|
491
|
+
def test_yylex_bdot2
|
492
|
+
assert_lex3("..42",
|
493
|
+
nil, # TODO: s(:dot2, nil, s(:lit, 42)),
|
380
494
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
:kEND, "end", EXPR_END, 0, 0)
|
495
|
+
:tBDOT2, "..", EXPR_BEG,
|
496
|
+
:tINTEGER, 42, EXPR_END|EXPR_ENDARG)
|
497
|
+
end
|
385
498
|
|
386
|
-
|
387
|
-
|
499
|
+
def test_yylex_bdot3
|
500
|
+
assert_lex3("...42",
|
501
|
+
nil, # TODO: s(:dot2, nil, s(:lit, 42)),
|
388
502
|
|
389
|
-
|
390
|
-
|
391
|
-
:tSEMI, ";", EXPR_BEG, 0, 0,
|
392
|
-
:kEND, "end", EXPR_END, 0, 0)
|
503
|
+
:tBDOT3, "...", EXPR_BEG,
|
504
|
+
:tINTEGER, 42, EXPR_END|EXPR_ENDARG)
|
393
505
|
end
|
394
506
|
|
395
|
-
def
|
396
|
-
|
397
|
-
|
507
|
+
def test_yylex_block_bug_1
|
508
|
+
assert_lex3("a do end",
|
509
|
+
s(:iter, s(:call, nil, :a), 0),
|
398
510
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
def test_yylex_number_times_ident_times_return_number
|
404
|
-
assert_lex("1 * b * 3",
|
405
|
-
s(:call,
|
406
|
-
s(:call, s(:lit, 1), :*, s(:call, nil, :b)),
|
407
|
-
:*, s(:lit, 3)),
|
408
|
-
|
409
|
-
:tINTEGER, 1, EXPR_NUM, 0, 0,
|
410
|
-
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
411
|
-
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
412
|
-
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
413
|
-
:tINTEGER, 3, EXPR_NUM, 0, 0)
|
414
|
-
|
415
|
-
assert_lex("1 * b *\n 3",
|
416
|
-
s(:call,
|
417
|
-
s(:call, s(:lit, 1), :*, s(:call, nil, :b)),
|
418
|
-
:*, s(:lit, 3)),
|
419
|
-
|
420
|
-
:tINTEGER, 1, EXPR_NUM, 0, 0,
|
421
|
-
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
422
|
-
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
423
|
-
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
424
|
-
:tINTEGER, 3, EXPR_NUM, 0, 0)
|
425
|
-
end
|
426
|
-
|
427
|
-
def test_yylex_paren_string_parens_interpolated_regexp
|
428
|
-
setup_lexer('%((#{(/abcd/)}))',
|
429
|
-
s(:dstr, "(", s(:evstr, s(:lit, /abcd/)), s(:str, ")")))
|
430
|
-
|
431
|
-
assert_next_lexeme :tSTRING_BEG, "%)", EXPR_BEG, 0, 0
|
432
|
-
assert_next_lexeme :tSTRING_CONTENT, "(", EXPR_BEG, 0, 0
|
433
|
-
|
434
|
-
assert_next_lexeme :tSTRING_DBEG, nil, EXPR_BEG, 0, 0
|
435
|
-
|
436
|
-
emulate_string_interpolation do
|
437
|
-
assert_next_lexeme :tLPAREN, "(", EXPR_PAR, 1, 0
|
438
|
-
assert_next_lexeme :tREGEXP_BEG, "/", EXPR_PAR, 1, 0
|
439
|
-
assert_next_lexeme :tSTRING_CONTENT, "abcd", EXPR_PAR, 1, 0
|
440
|
-
assert_next_lexeme :tREGEXP_END, "", EXPR_END, 1, 0
|
441
|
-
assert_next_lexeme :tRPAREN, ")", EXPR_ENDFN, 0, 0
|
442
|
-
end
|
443
|
-
|
444
|
-
assert_next_lexeme :tSTRING_CONTENT, ")", EXPR_BEG, 0, 0
|
445
|
-
assert_next_lexeme :tSTRING_END, ")", EXPR_END, 0, 0
|
446
|
-
|
447
|
-
refute_lexeme
|
448
|
-
end
|
449
|
-
|
450
|
-
def test_yylex_method_parens_chevron
|
451
|
-
assert_lex("a()<<1",
|
452
|
-
s(:call, s(:call, nil, :a), :<<, s(:lit, 1)),
|
453
|
-
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
454
|
-
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
455
|
-
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
456
|
-
:tLSHFT, "<<" , EXPR_BEG, 0, 0,
|
457
|
-
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
458
|
-
end
|
459
|
-
|
460
|
-
def test_yylex_lambda_args__20
|
461
|
-
setup_lexer_class RubyParser::V20
|
462
|
-
|
463
|
-
assert_lex("-> (a) { }",
|
464
|
-
s(:iter, s(:call, nil, :lambda),
|
465
|
-
s(:args, :a)),
|
466
|
-
|
467
|
-
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
468
|
-
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
469
|
-
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
470
|
-
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
471
|
-
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
472
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
473
|
-
end
|
474
|
-
|
475
|
-
def test_yylex_lambda_as_args_with_block__20
|
476
|
-
setup_lexer_class RubyParser::V20
|
477
|
-
|
478
|
-
assert_lex3("a -> do end do end",
|
479
|
-
nil,
|
480
|
-
:tIDENTIFIER, "a", EXPR_CMDARG,
|
481
|
-
:tLAMBDA, nil, EXPR_ENDFN,
|
482
|
-
:kDO, "do", EXPR_BEG,
|
483
|
-
:kEND, "end", EXPR_END,
|
484
|
-
:kDO, "do", EXPR_BEG,
|
485
|
-
:kEND, "end", EXPR_END)
|
486
|
-
end
|
487
|
-
|
488
|
-
def test_yylex_lambda_args_opt__20
|
489
|
-
setup_lexer_class RubyParser::V20
|
490
|
-
|
491
|
-
assert_lex("-> (a=nil) { }",
|
492
|
-
s(:iter, s(:call, nil, :lambda),
|
493
|
-
s(:args, s(:lasgn, :a, s(:nil)))),
|
494
|
-
|
495
|
-
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
496
|
-
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
497
|
-
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
498
|
-
:tEQL, "=", EXPR_BEG, 1, 0,
|
499
|
-
:kNIL, "nil", EXPR_END, 1, 0,
|
500
|
-
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
501
|
-
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
502
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
503
|
-
end
|
504
|
-
|
505
|
-
def test_yylex_lambda_hash__20
|
506
|
-
setup_lexer_class RubyParser::V20
|
507
|
-
|
508
|
-
assert_lex("-> (a={}) { }",
|
509
|
-
s(:iter, s(:call, nil, :lambda),
|
510
|
-
s(:args, s(:lasgn, :a, s(:hash)))),
|
511
|
-
|
512
|
-
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
513
|
-
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
514
|
-
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
515
|
-
:tEQL, "=", EXPR_BEG, 1, 0,
|
516
|
-
:tLBRACE, "{", EXPR_PAR, 1, 1,
|
517
|
-
:tRCURLY, "}", EXPR_ENDARG, 1, 0,
|
518
|
-
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
519
|
-
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
520
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
521
|
-
end
|
522
|
-
|
523
|
-
def test_yylex_iter_array_curly
|
524
|
-
assert_lex("f :a, [:b] { |c, d| }", # yes, this is bad code
|
525
|
-
s(:iter,
|
526
|
-
s(:call, nil, :f, s(:lit, :a), s(:array, s(:lit, :b))),
|
527
|
-
s(:args, :c, :d)),
|
528
|
-
|
529
|
-
:tIDENTIFIER, "f", EXPR_CMDARG, 0, 0,
|
530
|
-
:tSYMBOL, "a", EXPR_END, 0, 0,
|
531
|
-
:tCOMMA, ",", EXPR_PAR, 0, 0,
|
532
|
-
:tLBRACK, "[", EXPR_PAR, 1, 0,
|
533
|
-
:tSYMBOL, "b", EXPR_END, 1, 0,
|
534
|
-
:tRBRACK, "]", EXPR_ENDARG, 0, 0,
|
535
|
-
:tLBRACE_ARG, "{", EXPR_BEG, 0, 1,
|
536
|
-
:tPIPE, "|", EXPR_PAR, 0, 1,
|
537
|
-
:tIDENTIFIER, "c", EXPR_ARG, 0, 1,
|
538
|
-
:tCOMMA, ",", EXPR_PAR, 0, 1,
|
539
|
-
:tIDENTIFIER, "d", EXPR_ARG, 0, 1,
|
540
|
-
:tPIPE, "|", EXPR_PAR, 0, 1,
|
541
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
542
|
-
end
|
543
|
-
|
544
|
-
def test_yylex_const_call_same_name
|
545
|
-
assert_lex("X = a { }; b { f :c }",
|
546
|
-
s(:block,
|
547
|
-
s(:cdecl, :X, s(:iter, s(:call, nil, :a), 0)),
|
548
|
-
s(:iter,
|
549
|
-
s(:call, nil, :b),
|
550
|
-
0,
|
551
|
-
s(:call, nil, :f, s(:lit, :c)))),
|
552
|
-
|
553
|
-
:tCONSTANT, "X", EXPR_CMDARG, 0, 0,
|
554
|
-
:tEQL, "=", EXPR_BEG, 0, 0,
|
555
|
-
:tIDENTIFIER, "a", EXPR_ARG, 0, 0,
|
556
|
-
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
557
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0,
|
558
|
-
:tSEMI, ";", EXPR_BEG, 0, 0,
|
559
|
-
|
560
|
-
:tIDENTIFIER, "b", EXPR_CMDARG, 0, 0,
|
561
|
-
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
562
|
-
:tIDENTIFIER, "f", EXPR_CMDARG, 0, 1, # different
|
563
|
-
:tSYMBOL, "c", EXPR_END, 0, 1,
|
564
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
565
|
-
|
566
|
-
assert_lex("X = a { }; b { X :c }",
|
567
|
-
s(:block,
|
568
|
-
s(:cdecl, :X, s(:iter, s(:call, nil, :a), 0)),
|
569
|
-
s(:iter,
|
570
|
-
s(:call, nil, :b),
|
571
|
-
0,
|
572
|
-
s(:call, nil, :X, s(:lit, :c)))),
|
573
|
-
|
574
|
-
:tCONSTANT, "X", EXPR_CMDARG, 0, 0,
|
575
|
-
:tEQL, "=", EXPR_BEG, 0, 0,
|
576
|
-
:tIDENTIFIER, "a", EXPR_ARG, 0, 0,
|
577
|
-
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
578
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0,
|
579
|
-
:tSEMI, ";", EXPR_BEG, 0, 0,
|
580
|
-
|
581
|
-
:tIDENTIFIER, "b", EXPR_CMDARG, 0, 0,
|
582
|
-
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
583
|
-
:tCONSTANT, "X", EXPR_CMDARG, 0, 1, # same
|
584
|
-
:tSYMBOL, "c", EXPR_END, 0, 1,
|
585
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
586
|
-
end
|
587
|
-
|
588
|
-
def test_yylex_lasgn_call_same_name
|
589
|
-
assert_lex("a = b.c :d => 1",
|
590
|
-
s(:lasgn, :a,
|
591
|
-
s(:call, s(:call, nil, :b), :c,
|
592
|
-
s(:hash, s(:lit, :d), s(:lit, 1)))),
|
593
|
-
|
594
|
-
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
595
|
-
:tEQL, "=", EXPR_BEG, 0, 0,
|
596
|
-
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
597
|
-
:tDOT, ".", EXPR_DOT, 0, 0,
|
598
|
-
:tIDENTIFIER, "c", EXPR_ARG, 0, 0, # different
|
599
|
-
:tSYMBOL, "d", EXPR_END, 0, 0,
|
600
|
-
:tASSOC, "=>", EXPR_BEG, 0, 0,
|
601
|
-
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
602
|
-
|
603
|
-
assert_lex("a = b.a :d => 1",
|
604
|
-
s(:lasgn, :a,
|
605
|
-
s(:call, s(:call, nil, :b), :a,
|
606
|
-
s(:hash, s(:lit, :d), s(:lit, 1)))),
|
607
|
-
|
608
|
-
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
609
|
-
:tEQL, "=", EXPR_BEG, 0, 0,
|
610
|
-
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
611
|
-
:tDOT, ".", EXPR_DOT, 0, 0,
|
612
|
-
:tIDENTIFIER, "a", EXPR_ARG, 0, 0, # same as lvar
|
613
|
-
:tSYMBOL, "d", EXPR_END, 0, 0,
|
614
|
-
:tASSOC, "=>", EXPR_BEG, 0, 0,
|
615
|
-
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
616
|
-
end
|
617
|
-
|
618
|
-
def test_yylex_back_ref
|
619
|
-
assert_lex3("[$&, $`, $', $+]",
|
620
|
-
nil,
|
621
|
-
:tLBRACK, "[", EXPR_PAR,
|
622
|
-
:tBACK_REF, :&, EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
623
|
-
:tBACK_REF, :"`", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
624
|
-
:tBACK_REF, :"'", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
625
|
-
:tBACK_REF, :+, EXPR_END,
|
626
|
-
:tRBRACK, "]", EXPR_ENDARG)
|
627
|
-
end
|
628
|
-
|
629
|
-
def test_yylex_backslash
|
630
|
-
assert_lex3("1 \\\n+ 2",
|
631
|
-
nil,
|
632
|
-
:tINTEGER, 1, EXPR_NUM,
|
633
|
-
:tPLUS, "+", EXPR_BEG,
|
634
|
-
:tINTEGER, 2, EXPR_NUM)
|
635
|
-
end
|
636
|
-
|
637
|
-
def test_yylex_backslash_bad
|
638
|
-
refute_lex("1 \\ + 2", :tINTEGER, 1)
|
639
|
-
end
|
640
|
-
|
641
|
-
def test_yylex_backtick
|
642
|
-
assert_lex3("`ls`",
|
643
|
-
nil,
|
644
|
-
:tXSTRING_BEG, "`", EXPR_BEG,
|
645
|
-
:tSTRING_CONTENT, "ls", EXPR_BEG,
|
646
|
-
:tSTRING_END, "`", EXPR_END)
|
647
|
-
end
|
648
|
-
|
649
|
-
def test_yylex_backtick_cmdarg
|
650
|
-
self.lex_state = EXPR_DOT
|
651
|
-
|
652
|
-
# \n ensures expr_cmd (TODO: why?)
|
653
|
-
assert_lex3("\n`", nil, :tBACK_REF2, "`", EXPR_CMDARG)
|
654
|
-
end
|
655
|
-
|
656
|
-
def test_yylex_backtick_dot
|
657
|
-
self.lex_state = EXPR_DOT
|
658
|
-
|
659
|
-
assert_lex3("a.`(3)",
|
660
|
-
nil,
|
661
|
-
:tIDENTIFIER, "a", EXPR_CMDARG,
|
662
|
-
:tDOT, ".", EXPR_DOT,
|
663
|
-
:tBACK_REF2, "`", EXPR_ARG,
|
664
|
-
:tLPAREN2, "(", EXPR_PAR,
|
665
|
-
:tINTEGER, 3, EXPR_NUM,
|
666
|
-
:tRPAREN, ")", EXPR_ENDFN)
|
667
|
-
end
|
668
|
-
|
669
|
-
def test_yylex_backtick_method
|
670
|
-
self.lex_state = EXPR_FNAME
|
671
|
-
|
672
|
-
assert_lex3("`",
|
673
|
-
nil,
|
674
|
-
:tBACK_REF2, "`", EXPR_END)
|
675
|
-
end
|
676
|
-
|
677
|
-
def test_yylex_bad_char
|
678
|
-
refute_lex(" \010 ")
|
679
|
-
end
|
680
|
-
|
681
|
-
def test_yylex_bang
|
682
|
-
assert_lex3("!", nil, :tBANG, "!", EXPR_BEG)
|
683
|
-
end
|
684
|
-
|
685
|
-
def test_yylex_bang_equals
|
686
|
-
assert_lex3("!=", nil, :tNEQ, "!=", EXPR_BEG)
|
687
|
-
end
|
688
|
-
|
689
|
-
def test_yylex_bang_tilde
|
690
|
-
assert_lex3("!~", nil, :tNMATCH, "!~", EXPR_BEG)
|
691
|
-
end
|
692
|
-
|
693
|
-
def test_yylex_block_bug_1
|
694
|
-
assert_lex3("a do end",
|
695
|
-
s(:iter, s(:call, nil, :a), 0),
|
696
|
-
|
697
|
-
:tIDENTIFIER, "a", EXPR_CMDARG,
|
698
|
-
:kDO, "do", EXPR_BEG,
|
699
|
-
:kEND, "end", EXPR_END)
|
511
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
512
|
+
:kDO, "do", EXPR_BEG,
|
513
|
+
:kEND, "end", EXPR_END)
|
700
514
|
end
|
701
515
|
|
702
516
|
def test_yylex_block_bug_2
|
@@ -707,7 +521,7 @@ class TestRubyLexer < Minitest::Test
|
|
707
521
|
|
708
522
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
709
523
|
:tEQL, "=", EXPR_BEG,
|
710
|
-
:tINTEGER, 1,
|
524
|
+
:tINTEGER, 1, EXPR_NUM,
|
711
525
|
:tNL, nil, EXPR_BEG,
|
712
526
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
713
527
|
:kDO, "do", EXPR_BEG,
|
@@ -719,8 +533,8 @@ class TestRubyLexer < Minitest::Test
|
|
719
533
|
s(:iter, s(:call, nil, :a), 0),
|
720
534
|
|
721
535
|
:tIDENTIFIER, "a", EXPR_CMDARG, # verified
|
722
|
-
:tLCURLY, "{",
|
723
|
-
:tRCURLY, "}",
|
536
|
+
:tLCURLY, "{", EXPR_PAR,
|
537
|
+
:tRCURLY, "}", EXPR_END)
|
724
538
|
end
|
725
539
|
|
726
540
|
def test_yylex_carat
|
@@ -766,25 +580,25 @@ class TestRubyLexer < Minitest::Test
|
|
766
580
|
def test_yylex_comment
|
767
581
|
assert_lex3("1 # one\n# two\n2",
|
768
582
|
nil,
|
769
|
-
:tINTEGER, 1,
|
583
|
+
:tINTEGER, 1, EXPR_NUM,
|
770
584
|
:tNL, nil, EXPR_BEG,
|
771
|
-
:tINTEGER, 2,
|
585
|
+
:tINTEGER, 2, EXPR_NUM)
|
772
586
|
|
773
|
-
assert_equal "# one\n# two\n", @lex.
|
587
|
+
assert_equal "# one\n# two\n", @lex.comment
|
774
588
|
end
|
775
589
|
|
776
590
|
def test_yylex_comment_begin
|
777
591
|
assert_lex3("=begin\nblah\nblah\n=end\n42",
|
778
592
|
nil,
|
779
|
-
:tINTEGER, 42,
|
593
|
+
:tINTEGER, 42, EXPR_NUM)
|
780
594
|
|
781
|
-
assert_equal "=begin\nblah\nblah\n=end\n", @lex.
|
595
|
+
assert_equal "=begin\nblah\nblah\n=end\n", @lex.comment
|
782
596
|
end
|
783
597
|
|
784
598
|
def test_yylex_comment_begin_bad
|
785
599
|
refute_lex("=begin\nblah\nblah\n")
|
786
600
|
|
787
|
-
|
601
|
+
assert_nil @lex.comment
|
788
602
|
end
|
789
603
|
|
790
604
|
def test_yylex_comment_begin_not_comment
|
@@ -792,7 +606,7 @@ class TestRubyLexer < Minitest::Test
|
|
792
606
|
nil,
|
793
607
|
:tIDENTIFIER, "beginfoo", EXPR_CMDARG,
|
794
608
|
:tEQL, "=", EXPR_BEG,
|
795
|
-
:tINTEGER, 5,
|
609
|
+
:tINTEGER, 5, EXPR_NUM,
|
796
610
|
:tNL, nil, EXPR_BEG,
|
797
611
|
:tIDENTIFIER, "p", EXPR_CMDARG,
|
798
612
|
:tIDENTIFIER, "x", EXPR_ARG,
|
@@ -803,19 +617,63 @@ class TestRubyLexer < Minitest::Test
|
|
803
617
|
def test_yylex_comment_begin_space
|
804
618
|
assert_lex3("=begin blah\nblah\n=end\n", nil)
|
805
619
|
|
806
|
-
assert_equal "=begin blah\nblah\n=end\n", @lex.
|
620
|
+
assert_equal "=begin blah\nblah\n=end\n", @lex.comment
|
807
621
|
end
|
808
622
|
|
809
623
|
def test_yylex_comment_end_space_and_text
|
810
624
|
assert_lex3("=begin blah\nblah\n=end blab\n", nil)
|
811
625
|
|
812
|
-
assert_equal "=begin blah\nblah\n=end blab\n", @lex.
|
626
|
+
assert_equal "=begin blah\nblah\n=end blab\n", @lex.comment
|
813
627
|
end
|
814
628
|
|
815
629
|
def test_yylex_comment_eos
|
816
630
|
assert_lex3("# comment", nil)
|
817
631
|
end
|
818
632
|
|
633
|
+
def test_yylex_const_call_same_name
|
634
|
+
assert_lex("X = a { }; b { f :c }",
|
635
|
+
s(:block,
|
636
|
+
s(:cdecl, :X, s(:iter, s(:call, nil, :a), 0)),
|
637
|
+
s(:iter,
|
638
|
+
s(:call, nil, :b),
|
639
|
+
0,
|
640
|
+
s(:call, nil, :f, s(:lit, :c)))),
|
641
|
+
|
642
|
+
:tCONSTANT, "X", EXPR_CMDARG, 0, 0,
|
643
|
+
:tEQL, "=", EXPR_BEG, 0, 0,
|
644
|
+
:tIDENTIFIER, "a", EXPR_ARG, 0, 0,
|
645
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
646
|
+
:tRCURLY, "}", EXPR_END, 0, 0,
|
647
|
+
:tSEMI, ";", EXPR_BEG, 0, 0,
|
648
|
+
|
649
|
+
:tIDENTIFIER, "b", EXPR_CMDARG, 0, 0,
|
650
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
651
|
+
:tIDENTIFIER, "f", EXPR_CMDARG, 0, 1, # different
|
652
|
+
:tSYMBOL, "c", EXPR_LIT, 0, 1,
|
653
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
654
|
+
|
655
|
+
assert_lex("X = a { }; b { X :c }",
|
656
|
+
s(:block,
|
657
|
+
s(:cdecl, :X, s(:iter, s(:call, nil, :a), 0)),
|
658
|
+
s(:iter,
|
659
|
+
s(:call, nil, :b),
|
660
|
+
0,
|
661
|
+
s(:call, nil, :X, s(:lit, :c)))),
|
662
|
+
|
663
|
+
:tCONSTANT, "X", EXPR_CMDARG, 0, 0,
|
664
|
+
:tEQL, "=", EXPR_BEG, 0, 0,
|
665
|
+
:tIDENTIFIER, "a", EXPR_ARG, 0, 0,
|
666
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
667
|
+
:tRCURLY, "}", EXPR_END, 0, 0,
|
668
|
+
:tSEMI, ";", EXPR_BEG, 0, 0,
|
669
|
+
|
670
|
+
:tIDENTIFIER, "b", EXPR_CMDARG, 0, 0,
|
671
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
672
|
+
:tCONSTANT, "X", EXPR_CMDARG, 0, 1, # same
|
673
|
+
:tSYMBOL, "c", EXPR_LIT, 0, 1,
|
674
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
675
|
+
end
|
676
|
+
|
819
677
|
def test_yylex_constant
|
820
678
|
assert_lex3("ArgumentError", nil, :tCONSTANT, "ArgumentError", EXPR_CMDARG)
|
821
679
|
end
|
@@ -838,8 +696,8 @@ class TestRubyLexer < Minitest::Test
|
|
838
696
|
end
|
839
697
|
|
840
698
|
def test_yylex_def_bad_name
|
841
|
-
|
842
|
-
|
699
|
+
refute_lex3("def [ ",
|
700
|
+
:kDEF, "def", EXPR_FNAME)
|
843
701
|
end
|
844
702
|
|
845
703
|
def test_yylex_div
|
@@ -847,7 +705,7 @@ class TestRubyLexer < Minitest::Test
|
|
847
705
|
nil,
|
848
706
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
849
707
|
:tDIVIDE, "/", EXPR_BEG,
|
850
|
-
:tINTEGER, 2,
|
708
|
+
:tINTEGER, 2, EXPR_NUM)
|
851
709
|
end
|
852
710
|
|
853
711
|
def test_yylex_div_equals
|
@@ -855,7 +713,7 @@ class TestRubyLexer < Minitest::Test
|
|
855
713
|
nil,
|
856
714
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
857
715
|
:tOP_ASGN, "/", EXPR_BEG,
|
858
|
-
:tINTEGER, 2,
|
716
|
+
:tINTEGER, 2, EXPR_NUM)
|
859
717
|
end
|
860
718
|
|
861
719
|
def test_yylex_do
|
@@ -863,7 +721,7 @@ class TestRubyLexer < Minitest::Test
|
|
863
721
|
nil,
|
864
722
|
:tIDENTIFIER, "x", EXPR_CMDARG,
|
865
723
|
:kDO, "do", EXPR_BEG,
|
866
|
-
:tINTEGER, 42,
|
724
|
+
:tINTEGER, 42, EXPR_NUM,
|
867
725
|
:kEND, "end", EXPR_END)
|
868
726
|
end
|
869
727
|
|
@@ -876,7 +734,7 @@ class TestRubyLexer < Minitest::Test
|
|
876
734
|
:tDOT, ".", EXPR_DOT,
|
877
735
|
:tIDENTIFIER, "y", EXPR_ARG,
|
878
736
|
:kDO_BLOCK, "do", EXPR_BEG,
|
879
|
-
:tINTEGER, 42,
|
737
|
+
:tINTEGER, 42, EXPR_NUM,
|
880
738
|
:kEND, "end", EXPR_END) do
|
881
739
|
@lex.cmdarg.push true
|
882
740
|
end
|
@@ -887,25 +745,17 @@ class TestRubyLexer < Minitest::Test
|
|
887
745
|
|
888
746
|
assert_lex3("do 42 end",
|
889
747
|
nil,
|
890
|
-
:
|
891
|
-
:tINTEGER, 42,
|
748
|
+
:kDO, "do", EXPR_BEG,
|
749
|
+
:tINTEGER, 42, EXPR_NUM,
|
892
750
|
:kEND, "end", EXPR_END)
|
893
751
|
end
|
894
752
|
|
895
|
-
def test_yylex_is_your_spacebar_broken?
|
896
|
-
assert_lex3(":a!=:b",
|
897
|
-
nil,
|
898
|
-
:tSYMBOL, "a", EXPR_END,
|
899
|
-
:tNEQ, "!=", EXPR_BEG,
|
900
|
-
:tSYMBOL, "b", EXPR_END)
|
901
|
-
end
|
902
|
-
|
903
753
|
def test_yylex_do_cond
|
904
754
|
assert_lex3("x do 42 end",
|
905
755
|
nil,
|
906
756
|
:tIDENTIFIER, "x", EXPR_CMDARG,
|
907
757
|
:kDO_COND, "do", EXPR_BEG,
|
908
|
-
:tINTEGER, 42,
|
758
|
+
:tINTEGER, 42, EXPR_NUM,
|
909
759
|
:kEND, "end", EXPR_END) do
|
910
760
|
@lex.cond.push true
|
911
761
|
end
|
@@ -916,19 +766,31 @@ class TestRubyLexer < Minitest::Test
|
|
916
766
|
assert_includes(e.message, "is not allowed as a global variable name")
|
917
767
|
end
|
918
768
|
|
919
|
-
def test_yylex_dollar_eos
|
920
|
-
assert_lex3("$", nil, "$", "$", EXPR_END) # FIX: wtf is this?!?
|
921
|
-
end
|
922
|
-
|
923
769
|
def test_yylex_dot # HINT message sends
|
924
770
|
assert_lex3(".", nil, :tDOT, ".", EXPR_DOT)
|
925
771
|
end
|
926
772
|
|
927
773
|
def test_yylex_dot2
|
774
|
+
assert_lex3("1..2",
|
775
|
+
s(:lit, 1..2),
|
776
|
+
|
777
|
+
:tINTEGER, 1, EXPR_END|EXPR_ENDARG,
|
778
|
+
:tDOT2, "..", EXPR_BEG,
|
779
|
+
:tINTEGER, 2, EXPR_END|EXPR_ENDARG)
|
780
|
+
|
781
|
+
self.lex_state = EXPR_END|EXPR_ENDARG
|
928
782
|
assert_lex3("..", nil, :tDOT2, "..", EXPR_BEG)
|
929
783
|
end
|
930
784
|
|
931
785
|
def test_yylex_dot3
|
786
|
+
assert_lex3("1...2",
|
787
|
+
s(:lit, 1...2),
|
788
|
+
|
789
|
+
:tINTEGER, 1, EXPR_END|EXPR_ENDARG,
|
790
|
+
:tDOT3, "...", EXPR_BEG,
|
791
|
+
:tINTEGER, 2, EXPR_END|EXPR_ENDARG)
|
792
|
+
|
793
|
+
self.lex_state = EXPR_END|EXPR_ENDARG
|
932
794
|
assert_lex3("...", nil, :tDOT3, "...", EXPR_BEG)
|
933
795
|
end
|
934
796
|
|
@@ -950,7 +812,7 @@ class TestRubyLexer < Minitest::Test
|
|
950
812
|
end
|
951
813
|
|
952
814
|
def test_yylex_float
|
953
|
-
assert_lex3("1.0", nil, :tFLOAT, 1.0,
|
815
|
+
assert_lex3("1.0", nil, :tFLOAT, 1.0, EXPR_NUM)
|
954
816
|
end
|
955
817
|
|
956
818
|
def test_yylex_float_bad_no_underscores
|
@@ -968,7 +830,7 @@ class TestRubyLexer < Minitest::Test
|
|
968
830
|
def test_yylex_float_call
|
969
831
|
assert_lex3("1.0.to_s",
|
970
832
|
nil,
|
971
|
-
:tFLOAT, 1.0,
|
833
|
+
:tFLOAT, 1.0, EXPR_NUM,
|
972
834
|
:tDOT, ".", EXPR_DOT,
|
973
835
|
:tIDENTIFIER, "to_s", EXPR_ARG)
|
974
836
|
end
|
@@ -983,7 +845,7 @@ class TestRubyLexer < Minitest::Test
|
|
983
845
|
assert_lex3("-1.0E10",
|
984
846
|
nil,
|
985
847
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
986
|
-
:tFLOAT, 10000000000.0,
|
848
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
987
849
|
end
|
988
850
|
|
989
851
|
def test_yylex_float_dot_e
|
@@ -996,29 +858,22 @@ class TestRubyLexer < Minitest::Test
|
|
996
858
|
assert_lex3("-1.0e10",
|
997
859
|
nil,
|
998
860
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
999
|
-
:tFLOAT, 10000000000.0,
|
861
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
1000
862
|
end
|
1001
863
|
|
1002
864
|
def test_yylex_float_e
|
1003
865
|
assert_lex3("1e10",
|
1004
866
|
nil,
|
1005
|
-
:tFLOAT, 10000000000.0,
|
867
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
1006
868
|
end
|
1007
869
|
|
1008
870
|
def test_yylex_float_e_bad_double_e
|
1009
871
|
assert_lex3("1e2e3",
|
1010
872
|
nil,
|
1011
|
-
:tFLOAT, 100,
|
873
|
+
:tFLOAT, 100, EXPR_NUM,
|
1012
874
|
:tIDENTIFIER, "e3", EXPR_END)
|
1013
875
|
end
|
1014
876
|
|
1015
|
-
def test_yylex_float_if_modifier
|
1016
|
-
assert_lex3("1e2if",
|
1017
|
-
nil,
|
1018
|
-
:tFLOAT, 100, EXPR_NUM,
|
1019
|
-
:kIF_MOD, "if", EXPR_PAR)
|
1020
|
-
end
|
1021
|
-
|
1022
877
|
def test_yylex_float_e_bad_trailing_underscore
|
1023
878
|
refute_lex "123_e10"
|
1024
879
|
end
|
@@ -1031,21 +886,21 @@ class TestRubyLexer < Minitest::Test
|
|
1031
886
|
assert_lex3("-1e10",
|
1032
887
|
nil,
|
1033
888
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1034
|
-
:tFLOAT, 10000000000.0,
|
889
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
1035
890
|
end
|
1036
891
|
|
1037
892
|
def test_yylex_float_e_neg_minus
|
1038
893
|
assert_lex3("-1e-10",
|
1039
894
|
nil,
|
1040
895
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1041
|
-
:tFLOAT, 1.0e-10,
|
896
|
+
:tFLOAT, 1.0e-10, EXPR_NUM)
|
1042
897
|
end
|
1043
898
|
|
1044
899
|
def test_yylex_float_e_neg_plus
|
1045
900
|
assert_lex3("-1e+10",
|
1046
901
|
nil,
|
1047
902
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1048
|
-
:tFLOAT, 10000000000.0,
|
903
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
1049
904
|
end
|
1050
905
|
|
1051
906
|
def test_yylex_float_e_plus
|
@@ -1056,11 +911,18 @@ class TestRubyLexer < Minitest::Test
|
|
1056
911
|
assert_lex3("0e0", nil, :tFLOAT, 0.0, EXPR_NUM)
|
1057
912
|
end
|
1058
913
|
|
914
|
+
def test_yylex_float_if_modifier
|
915
|
+
assert_lex3("1e2if",
|
916
|
+
nil,
|
917
|
+
:tFLOAT, 100, EXPR_NUM,
|
918
|
+
:kIF_MOD, "if", EXPR_PAR)
|
919
|
+
end
|
920
|
+
|
1059
921
|
def test_yylex_float_neg
|
1060
922
|
assert_lex3("-1.0",
|
1061
923
|
nil,
|
1062
924
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1063
|
-
:tFLOAT, 1.0,
|
925
|
+
:tFLOAT, 1.0, EXPR_NUM)
|
1064
926
|
end
|
1065
927
|
|
1066
928
|
def test_yylex_ge
|
@@ -1068,7 +930,7 @@ class TestRubyLexer < Minitest::Test
|
|
1068
930
|
nil,
|
1069
931
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1070
932
|
:tGEQ, ">=", EXPR_BEG,
|
1071
|
-
:tINTEGER, 2,
|
933
|
+
:tINTEGER, 2, EXPR_NUM)
|
1072
934
|
end
|
1073
935
|
|
1074
936
|
def test_yylex_global
|
@@ -1082,6 +944,9 @@ class TestRubyLexer < Minitest::Test
|
|
1082
944
|
end
|
1083
945
|
|
1084
946
|
def test_yylex_global_dash_nothing
|
947
|
+
refute_lex3("$- ", nil) # fails 2.1+
|
948
|
+
|
949
|
+
setup_lexer_class RubyParser::V20
|
1085
950
|
assert_lex3("$- ", nil, :tGVAR, "$-", EXPR_END)
|
1086
951
|
end
|
1087
952
|
|
@@ -1101,6 +966,14 @@ class TestRubyLexer < Minitest::Test
|
|
1101
966
|
assert_lex3("$1234", nil, :tGVAR, "$1234", EXPR_END)
|
1102
967
|
end
|
1103
968
|
|
969
|
+
def test_yylex_global_I_have_no_words
|
970
|
+
assert_lex3("$x\xE2\x80\x8B = 42", # zero width space?!?!?
|
971
|
+
nil,
|
972
|
+
:tGVAR, "$x\xE2\x80\x8B", EXPR_END,
|
973
|
+
:tEQL, "=", EXPR_BEG,
|
974
|
+
:tINTEGER, 42, EXPR_NUM)
|
975
|
+
end
|
976
|
+
|
1104
977
|
def test_yylex_global_other
|
1105
978
|
assert_lex3("[$~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $\"]",
|
1106
979
|
nil,
|
@@ -1121,37 +994,123 @@ class TestRubyLexer < Minitest::Test
|
|
1121
994
|
:tGVAR, "$<", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1122
995
|
:tGVAR, "$>", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1123
996
|
:tGVAR, "$\"", EXPR_END,
|
1124
|
-
:tRBRACK, "]",
|
997
|
+
:tRBRACK, "]", EXPR_END)
|
998
|
+
end
|
999
|
+
|
1000
|
+
def test_yylex_global_underscore
|
1001
|
+
assert_lex3("$_", nil, :tGVAR, "$_", EXPR_END)
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
def test_yylex_global_wierd
|
1005
|
+
assert_lex3("$__blah", nil, :tGVAR, "$__blah", EXPR_END)
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
def test_yylex_global_zero
|
1009
|
+
assert_lex3("$0", nil, :tGVAR, "$0", EXPR_END)
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
def test_yylex_gt
|
1013
|
+
assert_lex3("a > 2",
|
1014
|
+
nil,
|
1015
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1016
|
+
:tGT, ">", EXPR_BEG,
|
1017
|
+
:tINTEGER, 2, EXPR_NUM)
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
def test_yylex_hash_colon
|
1021
|
+
assert_lex("{a:1}",
|
1022
|
+
s(:hash, s(:lit, :a), s(:lit, 1)),
|
1023
|
+
|
1024
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1025
|
+
:tLABEL, "a", EXPR_LAB, 0, 1,
|
1026
|
+
:tINTEGER, 1, EXPR_NUM, 0, 1,
|
1027
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
def test_yylex_hash_colon_double_quoted_symbol
|
1031
|
+
assert_lex('{"abc": :b}',
|
1032
|
+
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
1033
|
+
|
1034
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1035
|
+
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
1036
|
+
:tSYMBOL, "b", EXPR_LIT, 0, 1,
|
1037
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
def test_yylex_hash_colon_double_quoted_symbol_22
|
1041
|
+
setup_lexer_class RubyParser::V22
|
1042
|
+
|
1043
|
+
assert_lex('{"abc": :b}',
|
1044
|
+
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
1045
|
+
|
1046
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1047
|
+
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
1048
|
+
:tSYMBOL, "b", EXPR_LIT, 0, 1,
|
1049
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1125
1050
|
end
|
1126
1051
|
|
1127
|
-
def
|
1128
|
-
assert_lex3("
|
1052
|
+
def test_yylex_hash_colon_double_quoted_with_escapes
|
1053
|
+
assert_lex3("{\"s\\tr\\i\\ng\\\\foo\\'bar\":1}",
|
1054
|
+
nil,
|
1055
|
+
|
1056
|
+
:tLBRACE, "{", EXPR_PAR,
|
1057
|
+
:tLABEL, "s\tr\i\ng\\foo'bar", EXPR_LAB,
|
1058
|
+
:tINTEGER, 1, EXPR_NUM,
|
1059
|
+
:tRCURLY, "}", EXPR_END)
|
1129
1060
|
end
|
1130
1061
|
|
1131
|
-
def
|
1132
|
-
|
1062
|
+
def test_yylex_hash_colon_quoted_22
|
1063
|
+
setup_lexer_class RubyParser::V22
|
1064
|
+
|
1065
|
+
assert_lex("{'a':1}",
|
1066
|
+
s(:hash, s(:lit, :a), s(:lit, 1)),
|
1067
|
+
|
1068
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1069
|
+
:tLABEL, "a", EXPR_LAB, 0, 1,
|
1070
|
+
:tINTEGER, 1, EXPR_NUM, 0, 1,
|
1071
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1133
1072
|
end
|
1134
1073
|
|
1135
|
-
def
|
1136
|
-
|
1074
|
+
def test_yylex_hash_colon_quoted_symbol
|
1075
|
+
assert_lex("{'abc': :b}",
|
1076
|
+
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
1077
|
+
|
1078
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1079
|
+
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
1080
|
+
:tSYMBOL, "b", EXPR_LIT, 0, 1,
|
1081
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1137
1082
|
end
|
1138
1083
|
|
1139
|
-
def
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1084
|
+
def test_yylex_hash_colon_quoted_symbol_22
|
1085
|
+
setup_lexer_class RubyParser::V22
|
1086
|
+
|
1087
|
+
assert_lex("{'abc': :b}",
|
1088
|
+
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
1089
|
+
|
1090
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1091
|
+
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
1092
|
+
:tSYMBOL, "b", EXPR_LIT, 0, 1,
|
1093
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1094
|
+
end
|
1095
|
+
|
1096
|
+
def test_yylex_hash_colon_quoted_with_escapes
|
1097
|
+
assert_lex3("{'s\\tr\\i\\ng\\\\foo\\'bar':1}",
|
1098
|
+
nil,
|
1099
|
+
|
1100
|
+
:tLBRACE, "{", EXPR_PAR,
|
1101
|
+
:tLABEL, "s\\tr\\i\\ng\\foo'bar", EXPR_LAB,
|
1102
|
+
:tINTEGER, 1, EXPR_NUM,
|
1103
|
+
:tRCURLY, "}", EXPR_END)
|
1145
1104
|
end
|
1146
1105
|
|
1147
1106
|
def test_yylex_heredoc_backtick
|
1148
|
-
assert_lex3("a = <<`EOF`\n blah blah\nEOF\n
|
1107
|
+
assert_lex3("a = <<`EOF`\n blah blah\nEOF\n",
|
1149
1108
|
nil,
|
1150
1109
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1151
1110
|
:tEQL, "=", EXPR_BEG,
|
1152
1111
|
:tXSTRING_BEG, "`", EXPR_BEG,
|
1153
1112
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1154
|
-
:tSTRING_END, "EOF",
|
1113
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1155
1114
|
:tNL, nil, EXPR_BEG)
|
1156
1115
|
end
|
1157
1116
|
|
@@ -1162,67 +1121,46 @@ class TestRubyLexer < Minitest::Test
|
|
1162
1121
|
:tEQL, "=", EXPR_BEG,
|
1163
1122
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1164
1123
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1165
|
-
:tSTRING_END, "EOF",
|
1124
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1166
1125
|
:tNL, nil, EXPR_BEG)
|
1167
1126
|
end
|
1168
1127
|
|
1169
1128
|
def test_yylex_heredoc_double_dash
|
1170
|
-
assert_lex3("a =
|
1129
|
+
assert_lex3("a = \" blah blah\n\".strip\n42",
|
1171
1130
|
nil,
|
1172
1131
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1173
1132
|
:tEQL, "=", EXPR_BEG,
|
1174
|
-
:
|
1175
|
-
:
|
1176
|
-
:
|
1177
|
-
:tNL, nil, EXPR_BEG
|
1178
|
-
end
|
1133
|
+
:tSTRING, " blah blah\n", EXPR_END,
|
1134
|
+
:tDOT, ".", EXPR_DOT,
|
1135
|
+
:tIDENTIFIER, "strip", EXPR_ARG,
|
1136
|
+
:tNL, nil, EXPR_BEG,
|
1179
1137
|
|
1180
|
-
|
1181
|
-
|
1138
|
+
:tINTEGER, 42, EXPR_END
|
1139
|
+
)
|
1182
1140
|
|
1183
|
-
assert_lex3("a =
|
1141
|
+
assert_lex3("a = <<-\"EOF\".strip\n blah blah\n EOF\n42",
|
1184
1142
|
nil,
|
1185
|
-
:tIDENTIFIER, "a",
|
1186
|
-
:tEQL, "=",
|
1187
|
-
:tSTRING_BEG, "\"",
|
1188
|
-
:tSTRING_CONTENT, "blah blah\n", EXPR_BEG,
|
1189
|
-
:tSTRING_END, "EOF",
|
1190
|
-
:tNL, nil, EXPR_BEG)
|
1191
|
-
end
|
1192
|
-
|
1193
|
-
# mri handles tabs in a pretty specific way:
|
1194
|
-
# https://github.com/ruby/ruby/blob/trunk/parse.y#L5925
|
1195
|
-
def test_yylex_heredoc_double_squiggly_with_tab_indentation_remaining
|
1196
|
-
setup_lexer_class Ruby23Parser
|
1143
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1144
|
+
:tEQL, "=", EXPR_BEG,
|
1145
|
+
:tSTRING_BEG, "\"", EXPR_BEG,
|
1146
|
+
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1147
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1197
1148
|
|
1198
|
-
|
1199
|
-
|
1200
|
-
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1201
|
-
:tEQL, "=", EXPR_BEG,
|
1202
|
-
:tSTRING_BEG, "\"", EXPR_BEG,
|
1203
|
-
:tSTRING_CONTENT, "blah blah\n\tblah blah\n", EXPR_BEG,
|
1204
|
-
:tSTRING_END, "EOF", EXPR_END,
|
1205
|
-
:tNL, nil, EXPR_BEG)
|
1206
|
-
end
|
1149
|
+
:tDOT, ".", EXPR_DOT,
|
1150
|
+
:tIDENTIFIER, "strip", EXPR_ARG,
|
1207
1151
|
|
1208
|
-
|
1209
|
-
setup_lexer_class Ruby23Parser
|
1152
|
+
:tNL, nil, EXPR_BEG,
|
1210
1153
|
|
1211
|
-
|
1212
|
-
|
1213
|
-
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1214
|
-
:tEQL, "=", EXPR_BEG,
|
1215
|
-
:tSTRING_BEG, "\"", EXPR_BEG,
|
1216
|
-
:tSTRING_CONTENT, "blah blah\n blah blah\n", EXPR_BEG,
|
1217
|
-
:tSTRING_END, "EOF", EXPR_END,
|
1218
|
-
:tNL, nil, EXPR_BEG)
|
1154
|
+
:tINTEGER, 42, EXPR_END
|
1155
|
+
)
|
1219
1156
|
end
|
1220
1157
|
|
1221
1158
|
def test_yylex_heredoc_double_eos
|
1222
1159
|
refute_lex("a = <<\"EOF\"\nblah",
|
1223
1160
|
:tIDENTIFIER, "a",
|
1224
1161
|
:tEQL, "=",
|
1225
|
-
:tSTRING_BEG, "\""
|
1162
|
+
:tSTRING_BEG, "\"",
|
1163
|
+
:tSTRING_CONTENT, "blah")
|
1226
1164
|
end
|
1227
1165
|
|
1228
1166
|
def test_yylex_heredoc_double_eos_nl
|
@@ -1239,25 +1177,38 @@ class TestRubyLexer < Minitest::Test
|
|
1239
1177
|
:tEQL, "=", EXPR_BEG,
|
1240
1178
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1241
1179
|
:tSTRING_CONTENT, "#x a ", EXPR_BEG,
|
1242
|
-
:tSTRING_DVAR, "
|
1180
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1243
1181
|
:tSTRING_CONTENT, "@a b ", EXPR_BEG, # HUH?
|
1244
|
-
:tSTRING_DVAR, "
|
1182
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1245
1183
|
:tSTRING_CONTENT, "$b c ", EXPR_BEG, # HUH?
|
1246
|
-
:tSTRING_DVAR, "
|
1184
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1247
1185
|
:tSTRING_CONTENT, "@@d ", EXPR_BEG, # HUH?
|
1248
1186
|
:tSTRING_DBEG, "\#{", EXPR_BEG,
|
1249
1187
|
:tSTRING_CONTENT, "3} \n", EXPR_BEG,
|
1250
|
-
:tSTRING_END, "EOF",
|
1188
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1251
1189
|
:tNL, nil, EXPR_BEG)
|
1252
1190
|
end
|
1253
1191
|
|
1192
|
+
def test_yylex_heredoc_double_squiggly
|
1193
|
+
setup_lexer_class Ruby23Parser
|
1194
|
+
|
1195
|
+
assert_lex3("a = <<~\"EOF\"\n blah blah\n EOF\n\n",
|
1196
|
+
nil,
|
1197
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1198
|
+
:tEQL, "=", EXPR_BEG,
|
1199
|
+
:tSTRING_BEG, "\"", EXPR_BEG,
|
1200
|
+
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1201
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1202
|
+
:tNL, nil, EXPR_BEG)
|
1203
|
+
end
|
1204
|
+
|
1254
1205
|
def test_yylex_heredoc_empty
|
1255
1206
|
assert_lex3("<<\"\"\n\#{x}\nblah2\n\n\n",
|
1256
1207
|
nil,
|
1257
1208
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1258
1209
|
:tSTRING_DBEG, "\#{", EXPR_BEG,
|
1259
1210
|
:tSTRING_CONTENT, "x}\nblah2\n", EXPR_BEG,
|
1260
|
-
:tSTRING_END, "",
|
1211
|
+
:tSTRING_END, "", EXPR_LIT,
|
1261
1212
|
:tNL, nil, EXPR_BEG)
|
1262
1213
|
end
|
1263
1214
|
|
@@ -1268,7 +1219,7 @@ class TestRubyLexer < Minitest::Test
|
|
1268
1219
|
:tEQL, "=", EXPR_BEG,
|
1269
1220
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1270
1221
|
:tSTRING_CONTENT, "blah\nblah\n", EXPR_BEG,
|
1271
|
-
:tSTRING_END, "EOF",
|
1222
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1272
1223
|
:tNL, nil, EXPR_BEG)
|
1273
1224
|
end
|
1274
1225
|
|
@@ -1286,7 +1237,7 @@ class TestRubyLexer < Minitest::Test
|
|
1286
1237
|
:tEQL, "=", EXPR_BEG,
|
1287
1238
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1288
1239
|
:tSTRING_CONTENT, "blah\nblah\n", EXPR_BEG,
|
1289
|
-
:tSTRING_END, "EOF",
|
1240
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1290
1241
|
:tNL, nil, EXPR_BEG)
|
1291
1242
|
end
|
1292
1243
|
|
@@ -1295,37 +1246,41 @@ class TestRubyLexer < Minitest::Test
|
|
1295
1246
|
|
1296
1247
|
assert_lex3("a = <<~EOF\n blah\n blah\n EOF\n",
|
1297
1248
|
nil,
|
1298
|
-
:tIDENTIFIER, "a",
|
1299
|
-
:tEQL, "=",
|
1300
|
-
:tSTRING_BEG, "\"",
|
1301
|
-
:tSTRING_CONTENT, "blah\
|
1302
|
-
:tSTRING_END, "EOF",
|
1303
|
-
:tNL, nil,
|
1249
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1250
|
+
:tEQL, "=", EXPR_BEG,
|
1251
|
+
:tSTRING_BEG, "\"", EXPR_BEG,
|
1252
|
+
:tSTRING_CONTENT, " blah\n blah\n", EXPR_BEG,
|
1253
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1254
|
+
:tNL, nil, EXPR_BEG)
|
1304
1255
|
end
|
1305
1256
|
|
1306
1257
|
def test_yylex_heredoc_single
|
1307
|
-
assert_lex3("a = <<'EOF'\n blah blah\nEOF\n\n",
|
1258
|
+
assert_lex3("a = <<'EOF'\n blah blah\nEOF\n\n\n\n42\n",
|
1308
1259
|
nil,
|
1309
1260
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1310
1261
|
:tEQL, "=", EXPR_BEG,
|
1311
|
-
:tSTRING_BEG, "
|
1262
|
+
:tSTRING_BEG, "'", EXPR_BEG,
|
1312
1263
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1313
|
-
:tSTRING_END, "EOF",
|
1264
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1265
|
+
:tNL, nil, EXPR_BEG,
|
1266
|
+
:tINTEGER, 42, EXPR_LIT,
|
1314
1267
|
:tNL, nil, EXPR_BEG)
|
1268
|
+
|
1269
|
+
assert_nil lex.old_ss
|
1315
1270
|
end
|
1316
1271
|
|
1317
1272
|
def test_yylex_heredoc_single_bad_eos_body
|
1318
1273
|
refute_lex("a = <<'EOF'\nblah",
|
1319
1274
|
:tIDENTIFIER, "a",
|
1320
1275
|
:tEQL, "=",
|
1321
|
-
:tSTRING_BEG, "
|
1276
|
+
:tSTRING_BEG, "'")
|
1322
1277
|
end
|
1323
1278
|
|
1324
1279
|
def test_yylex_heredoc_single_bad_eos_empty
|
1325
1280
|
refute_lex("a = <<''\n",
|
1326
1281
|
:tIDENTIFIER, "a",
|
1327
1282
|
:tEQL, "=",
|
1328
|
-
:tSTRING_BEG, "
|
1283
|
+
:tSTRING_BEG, "'")
|
1329
1284
|
end
|
1330
1285
|
|
1331
1286
|
def test_yylex_heredoc_single_bad_eos_term
|
@@ -1347,9 +1302,9 @@ class TestRubyLexer < Minitest::Test
|
|
1347
1302
|
nil,
|
1348
1303
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1349
1304
|
:tEQL, "=", EXPR_BEG,
|
1350
|
-
:tSTRING_BEG, "
|
1305
|
+
:tSTRING_BEG, "'", EXPR_BEG,
|
1351
1306
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1352
|
-
:tSTRING_END, "EOF",
|
1307
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1353
1308
|
:tNL, nil, EXPR_BEG)
|
1354
1309
|
end
|
1355
1310
|
|
@@ -1358,12 +1313,12 @@ class TestRubyLexer < Minitest::Test
|
|
1358
1313
|
|
1359
1314
|
assert_lex3("a = <<~'EOF'\n blah blah\n EOF\n\n",
|
1360
1315
|
nil,
|
1361
|
-
:tIDENTIFIER, "a",
|
1362
|
-
:tEQL, "=",
|
1363
|
-
:tSTRING_BEG, "
|
1364
|
-
:tSTRING_CONTENT, "blah blah\n", EXPR_BEG,
|
1365
|
-
:tSTRING_END, "EOF",
|
1366
|
-
:tNL, nil,
|
1316
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1317
|
+
:tEQL, "=", EXPR_BEG,
|
1318
|
+
:tSTRING_BEG, "'", EXPR_BEG,
|
1319
|
+
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1320
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1321
|
+
:tNL, nil, EXPR_BEG)
|
1367
1322
|
end
|
1368
1323
|
|
1369
1324
|
def test_yylex_identifier
|
@@ -1392,41 +1347,41 @@ class TestRubyLexer < Minitest::Test
|
|
1392
1347
|
assert_lex3("identifier?", nil, :tFID, "identifier?", EXPR_CMDARG)
|
1393
1348
|
end
|
1394
1349
|
|
1395
|
-
def test_yylex_identifier_equals_arrow
|
1396
|
-
assert_lex3(":blah==>",
|
1397
|
-
nil,
|
1398
|
-
:tSYMBOL, "blah=", EXPR_END,
|
1399
|
-
:tASSOC, "=>", EXPR_BEG)
|
1400
|
-
end
|
1401
|
-
|
1402
1350
|
def test_yylex_identifier_equals3
|
1403
1351
|
assert_lex3(":a===b",
|
1404
1352
|
nil,
|
1405
|
-
:tSYMBOL, "a",
|
1353
|
+
:tSYMBOL, "a", EXPR_LIT,
|
1406
1354
|
:tEQQ, "===", EXPR_BEG,
|
1407
1355
|
:tIDENTIFIER, "b", EXPR_ARG)
|
1408
1356
|
end
|
1409
1357
|
|
1410
|
-
def
|
1411
|
-
assert_lex3(":
|
1358
|
+
def test_yylex_identifier_equals_arrow
|
1359
|
+
assert_lex3(":blah==>",
|
1412
1360
|
nil,
|
1413
|
-
:tSYMBOL, "
|
1414
|
-
:tASSOC,
|
1415
|
-
:tIDENTIFIER, "b", EXPR_ARG)
|
1361
|
+
:tSYMBOL, "blah=", EXPR_LIT,
|
1362
|
+
:tASSOC, "=>", EXPR_BEG)
|
1416
1363
|
end
|
1417
1364
|
|
1418
1365
|
def test_yylex_identifier_equals_caret
|
1419
1366
|
assert_lex_fname "^", :tCARET
|
1420
1367
|
end
|
1421
1368
|
|
1369
|
+
def test_yylex_identifier_equals_def2
|
1370
|
+
assert_lex_fname "==", :tEQ
|
1371
|
+
end
|
1372
|
+
|
1422
1373
|
def test_yylex_identifier_equals_def__20
|
1423
1374
|
setup_lexer_class RubyParser::V20
|
1424
1375
|
|
1425
1376
|
assert_lex_fname "identifier=", :tIDENTIFIER, EXPR_ENDFN
|
1426
1377
|
end
|
1427
1378
|
|
1428
|
-
def
|
1429
|
-
|
1379
|
+
def test_yylex_identifier_equals_equals_arrow
|
1380
|
+
assert_lex3(":a==>b",
|
1381
|
+
nil,
|
1382
|
+
:tSYMBOL, "a=", EXPR_LIT,
|
1383
|
+
:tASSOC, "=>", EXPR_BEG,
|
1384
|
+
:tIDENTIFIER, "b", EXPR_ARG)
|
1430
1385
|
end
|
1431
1386
|
|
1432
1387
|
def test_yylex_identifier_equals_expr
|
@@ -1515,6 +1470,18 @@ class TestRubyLexer < Minitest::Test
|
|
1515
1470
|
refute_lex "0d42__24"
|
1516
1471
|
end
|
1517
1472
|
|
1473
|
+
def test_yylex_integer_hex
|
1474
|
+
assert_lex3 "0x2a", nil, :tINTEGER, 42, EXPR_NUM
|
1475
|
+
end
|
1476
|
+
|
1477
|
+
def test_yylex_integer_hex_bad_none
|
1478
|
+
refute_lex "0x "
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
def test_yylex_integer_hex_bad_underscores
|
1482
|
+
refute_lex "0xab__cd"
|
1483
|
+
end
|
1484
|
+
|
1518
1485
|
def test_yylex_integer_if_modifier
|
1519
1486
|
assert_lex3("123if",
|
1520
1487
|
nil,
|
@@ -1522,32 +1489,24 @@ class TestRubyLexer < Minitest::Test
|
|
1522
1489
|
:kIF_MOD, "if", EXPR_PAR)
|
1523
1490
|
end
|
1524
1491
|
|
1525
|
-
def
|
1526
|
-
|
1527
|
-
|
1528
|
-
assert_lex3("?a", nil, :tSTRING, "a", EXPR_END)
|
1529
|
-
end
|
1530
|
-
|
1531
|
-
def test_yylex_question_eh_escape_M_escape_C__20
|
1532
|
-
setup_lexer_class RubyParser::V20
|
1533
|
-
|
1534
|
-
assert_lex3("?\\M-\\C-a", nil, :tSTRING, "\M-\C-a", EXPR_END)
|
1492
|
+
def test_yylex_integer_oct
|
1493
|
+
assert_lex3("052", nil, :tINTEGER, 42, EXPR_NUM)
|
1535
1494
|
end
|
1536
1495
|
|
1537
|
-
def
|
1538
|
-
assert_lex3 "
|
1496
|
+
def test_yylex_integer_oct_O
|
1497
|
+
assert_lex3 "0O52", nil, :tINTEGER, 42, EXPR_NUM
|
1539
1498
|
end
|
1540
1499
|
|
1541
|
-
def
|
1542
|
-
refute_lex "
|
1500
|
+
def test_yylex_integer_oct_O_bad_range
|
1501
|
+
refute_lex "0O8"
|
1543
1502
|
end
|
1544
1503
|
|
1545
|
-
def
|
1546
|
-
refute_lex "
|
1504
|
+
def test_yylex_integer_oct_O_bad_underscores
|
1505
|
+
refute_lex "0O1__23"
|
1547
1506
|
end
|
1548
1507
|
|
1549
|
-
def
|
1550
|
-
assert_lex3
|
1508
|
+
def test_yylex_integer_oct_O_not_bad_none
|
1509
|
+
assert_lex3 "0O ", nil, :tINTEGER, 0, EXPR_NUM
|
1551
1510
|
end
|
1552
1511
|
|
1553
1512
|
def test_yylex_integer_oct_bad_range
|
@@ -1562,74 +1521,261 @@ class TestRubyLexer < Minitest::Test
|
|
1562
1521
|
refute_lex "01__23"
|
1563
1522
|
end
|
1564
1523
|
|
1565
|
-
def
|
1566
|
-
assert_lex3 "
|
1524
|
+
def test_yylex_integer_oct_o
|
1525
|
+
assert_lex3 "0o52", nil, :tINTEGER, 42, EXPR_NUM
|
1567
1526
|
end
|
1568
1527
|
|
1569
|
-
def
|
1570
|
-
refute_lex "
|
1528
|
+
def test_yylex_integer_oct_o_bad_range
|
1529
|
+
refute_lex "0o8"
|
1571
1530
|
end
|
1572
1531
|
|
1573
|
-
def
|
1574
|
-
refute_lex "
|
1532
|
+
def test_yylex_integer_oct_o_bad_underscores
|
1533
|
+
refute_lex "0o1__23"
|
1575
1534
|
end
|
1576
1535
|
|
1577
|
-
def
|
1578
|
-
assert_lex3 "
|
1536
|
+
def test_yylex_integer_oct_o_not_bad_none
|
1537
|
+
assert_lex3 "0o ", nil, :tINTEGER, 0, EXPR_NUM
|
1538
|
+
end
|
1539
|
+
|
1540
|
+
def test_yylex_integer_trailing
|
1541
|
+
assert_lex3("1.to_s",
|
1542
|
+
nil,
|
1543
|
+
:tINTEGER, 1, EXPR_NUM,
|
1544
|
+
:tDOT, ".", EXPR_DOT,
|
1545
|
+
:tIDENTIFIER, "to_s", EXPR_ARG)
|
1546
|
+
end
|
1547
|
+
|
1548
|
+
def test_yylex_integer_underscore
|
1549
|
+
assert_lex3("4_2", nil, :tINTEGER, 42, EXPR_NUM)
|
1550
|
+
end
|
1551
|
+
|
1552
|
+
def test_yylex_integer_underscore_bad
|
1553
|
+
refute_lex "4__2"
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
def test_yylex_integer_zero
|
1557
|
+
assert_lex3 "0", nil, :tINTEGER, 0, EXPR_NUM
|
1558
|
+
end
|
1559
|
+
|
1560
|
+
def test_yylex_is_your_spacebar_broken?
|
1561
|
+
assert_lex3(":a!=:b",
|
1562
|
+
nil,
|
1563
|
+
:tSYMBOL, "a", EXPR_LIT,
|
1564
|
+
:tNEQ, "!=", EXPR_BEG,
|
1565
|
+
:tSYMBOL, "b", EXPR_LIT)
|
1566
|
+
end
|
1567
|
+
|
1568
|
+
def test_yylex_iter_array_curly
|
1569
|
+
# this will lex, but doesn't parse... don't freak out.
|
1570
|
+
assert_lex("f :a, [:b] { |c, d| }", # yes, this is bad code
|
1571
|
+
nil,
|
1572
|
+
|
1573
|
+
:tIDENTIFIER, "f", EXPR_CMDARG, 0, 0,
|
1574
|
+
:tSYMBOL, "a", EXPR_LIT, 0, 0,
|
1575
|
+
:tCOMMA, ",", EXPR_PAR, 0, 0,
|
1576
|
+
:tLBRACK, "[", EXPR_PAR, 1, 0,
|
1577
|
+
:tSYMBOL, "b", EXPR_LIT, 1, 0,
|
1578
|
+
:tRBRACK, "]", EXPR_END, 0, 0,
|
1579
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1580
|
+
:tPIPE, "|", EXPR_PAR, 0, 1,
|
1581
|
+
:tIDENTIFIER, "c", EXPR_ARG, 0, 1,
|
1582
|
+
:tCOMMA, ",", EXPR_PAR, 0, 1,
|
1583
|
+
:tIDENTIFIER, "d", EXPR_ARG, 0, 1,
|
1584
|
+
:tPIPE, "|", EXPR_PAR, 0, 1,
|
1585
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1586
|
+
end
|
1587
|
+
|
1588
|
+
def test_yylex_iter_array_curly__24
|
1589
|
+
setup_lexer_class RubyParser::V24
|
1590
|
+
|
1591
|
+
assert_lex("f :a, [:b] { |c, d| }", # yes, this is bad code
|
1592
|
+
s(:iter,
|
1593
|
+
s(:call, nil, :f,
|
1594
|
+
s(:lit, :a).line(1),
|
1595
|
+
s(:array, s(:lit, :b).line(1)).line(1)).line(1),
|
1596
|
+
s(:args, :c, :d).line(1)).line(1),
|
1597
|
+
|
1598
|
+
:tIDENTIFIER, "f", EXPR_CMDARG, 0, 0,
|
1599
|
+
:tSYMBOL, "a", EXPR_LIT, 0, 0,
|
1600
|
+
:tCOMMA, ",", EXPR_PAR, 0, 0,
|
1601
|
+
:tLBRACK, "[", EXPR_PAR, 1, 0,
|
1602
|
+
:tSYMBOL, "b", EXPR_LIT, 1, 0,
|
1603
|
+
:tRBRACK, "]", EXPR_ENDARG, 0, 0,
|
1604
|
+
:tLBRACE_ARG, "{", EXPR_BEG, 0, 1,
|
1605
|
+
:tPIPE, "|", EXPR_PAR, 0, 1,
|
1606
|
+
:tIDENTIFIER, "c", EXPR_ARG, 0, 1,
|
1607
|
+
:tCOMMA, ",", EXPR_PAR, 0, 1,
|
1608
|
+
:tIDENTIFIER, "d", EXPR_ARG, 0, 1,
|
1609
|
+
:tPIPE, "|", EXPR_PAR, 0, 1,
|
1610
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1611
|
+
end
|
1612
|
+
|
1613
|
+
def test_yylex_ivar
|
1614
|
+
assert_lex3("@blah", nil, :tIVAR, "@blah", EXPR_END)
|
1615
|
+
end
|
1616
|
+
|
1617
|
+
def test_yylex_ivar_bad
|
1618
|
+
refute_lex "@1"
|
1619
|
+
end
|
1620
|
+
|
1621
|
+
def test_yylex_ivar_bad_0_length
|
1622
|
+
refute_lex "1+@\n", :tINTEGER, 1, :tPLUS, "+", EXPR_NUM
|
1623
|
+
end
|
1624
|
+
|
1625
|
+
def test_yylex_keyword_expr
|
1626
|
+
self.lex_state = EXPR_ENDARG
|
1627
|
+
|
1628
|
+
assert_lex3("if", nil, :kIF_MOD, "if", EXPR_PAR)
|
1629
|
+
end
|
1630
|
+
|
1631
|
+
def test_yylex_label
|
1632
|
+
assert_lex3("{a:",
|
1633
|
+
nil,
|
1634
|
+
:tLBRACE, "{", EXPR_PAR,
|
1635
|
+
:tLABEL, "a", EXPR_LAB)
|
1636
|
+
end
|
1637
|
+
|
1638
|
+
def test_yylex_label_in_params
|
1639
|
+
assert_lex3("foo(a:",
|
1640
|
+
nil,
|
1641
|
+
:tIDENTIFIER, "foo", EXPR_CMDARG,
|
1642
|
+
:tLPAREN2, "(", EXPR_PAR,
|
1643
|
+
:tLABEL, "a", EXPR_LAB)
|
1644
|
+
end
|
1645
|
+
|
1646
|
+
def test_yylex_lambda_args
|
1647
|
+
assert_lex("-> (a) { }",
|
1648
|
+
s(:iter, s(:lambda),
|
1649
|
+
s(:args, :a)),
|
1650
|
+
|
1651
|
+
:tLAMBDA, "->", EXPR_ENDFN, 0, 0,
|
1652
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1653
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1654
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1655
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1656
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1657
|
+
end
|
1658
|
+
|
1659
|
+
def test_yylex_lambda_args__24
|
1660
|
+
setup_lexer_class RubyParser::V24
|
1661
|
+
|
1662
|
+
assert_lex("-> (a) { }",
|
1663
|
+
s(:iter, s(:lambda),
|
1664
|
+
s(:args, :a)),
|
1665
|
+
|
1666
|
+
:tLAMBDA, "->", EXPR_ENDFN, 0, 0,
|
1667
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1668
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1669
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1670
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1671
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1579
1672
|
end
|
1580
1673
|
|
1581
|
-
def
|
1582
|
-
|
1583
|
-
|
1674
|
+
def test_yylex_lambda_args_opt
|
1675
|
+
assert_lex("-> (a=nil) { }",
|
1676
|
+
s(:iter, s(:lambda),
|
1677
|
+
s(:args, s(:lasgn, :a, s(:nil)))),
|
1584
1678
|
|
1585
|
-
|
1586
|
-
|
1679
|
+
:tLAMBDA, "->", EXPR_ENDFN, 0, 0,
|
1680
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1681
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1682
|
+
:tEQL, "=", EXPR_BEG, 1, 0,
|
1683
|
+
:kNIL, "nil", EXPR_END, 1, 0,
|
1684
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1685
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1686
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1587
1687
|
end
|
1588
1688
|
|
1589
|
-
def
|
1590
|
-
|
1591
|
-
end
|
1689
|
+
def test_yylex_lambda_args_opt__24
|
1690
|
+
setup_lexer_class RubyParser::V24
|
1592
1691
|
|
1593
|
-
|
1594
|
-
|
1692
|
+
assert_lex("-> (a=nil) { }",
|
1693
|
+
s(:iter, s(:lambda),
|
1694
|
+
s(:args, s(:lasgn, :a, s(:nil)))),
|
1695
|
+
|
1696
|
+
:tLAMBDA, "->", EXPR_ENDFN, 0, 0,
|
1697
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1698
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1699
|
+
:tEQL, "=", EXPR_BEG, 1, 0,
|
1700
|
+
:kNIL, "nil", EXPR_END, 1, 0,
|
1701
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1702
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1703
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1595
1704
|
end
|
1596
1705
|
|
1597
|
-
def
|
1598
|
-
assert_lex3("
|
1706
|
+
def test_yylex_lambda_as_args_with_block
|
1707
|
+
assert_lex3("a -> do end do end",
|
1599
1708
|
nil,
|
1600
|
-
:
|
1601
|
-
:
|
1602
|
-
:
|
1709
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1710
|
+
:tLAMBDA, "->", EXPR_ENDFN,
|
1711
|
+
:kDO, "do", EXPR_BEG,
|
1712
|
+
:kEND, "end", EXPR_END,
|
1713
|
+
:kDO, "do", EXPR_BEG,
|
1714
|
+
:kEND, "end", EXPR_END)
|
1603
1715
|
end
|
1604
1716
|
|
1605
|
-
def
|
1606
|
-
|
1607
|
-
|
1717
|
+
def test_yylex_lambda_hash
|
1718
|
+
assert_lex("-> (a={}) { }",
|
1719
|
+
s(:iter, s(:lambda),
|
1720
|
+
s(:args, s(:lasgn, :a, s(:hash)))),
|
1608
1721
|
|
1609
|
-
|
1610
|
-
|
1722
|
+
:tLAMBDA, "->", EXPR_ENDFN, 0, 0,
|
1723
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1724
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1725
|
+
:tEQL, "=", EXPR_BEG, 1, 0,
|
1726
|
+
:tLBRACE, "{", EXPR_PAR, 1, 1,
|
1727
|
+
:tRCURLY, "}", EXPR_END, 1, 0,
|
1728
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1729
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1730
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1611
1731
|
end
|
1612
1732
|
|
1613
|
-
def
|
1614
|
-
|
1615
|
-
end
|
1733
|
+
def test_yylex_lambda_hash__24
|
1734
|
+
setup_lexer_class RubyParser::V24
|
1616
1735
|
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1736
|
+
assert_lex("-> (a={}) { }",
|
1737
|
+
s(:iter, s(:lambda),
|
1738
|
+
s(:args, s(:lasgn, :a, s(:hash)))),
|
1620
1739
|
|
1621
|
-
|
1622
|
-
|
1740
|
+
:tLAMBDA, "->", EXPR_ENDFN, 0, 0,
|
1741
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1742
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1743
|
+
:tEQL, "=", EXPR_BEG, 1, 0,
|
1744
|
+
:tLBRACE, "{", EXPR_PAR, 1, 1,
|
1745
|
+
:tRCURLY, "}", EXPR_ENDARG, 1, 0,
|
1746
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1747
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1748
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1623
1749
|
end
|
1624
1750
|
|
1625
|
-
def
|
1626
|
-
|
1627
|
-
|
1751
|
+
def test_yylex_lasgn_call_same_name
|
1752
|
+
assert_lex("a = b.c :d => 1",
|
1753
|
+
s(:lasgn, :a,
|
1754
|
+
s(:call, s(:call, nil, :b), :c,
|
1755
|
+
s(:hash, s(:lit, :d), s(:lit, 1)))),
|
1628
1756
|
|
1629
|
-
|
1630
|
-
|
1757
|
+
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
1758
|
+
:tEQL, "=", EXPR_BEG, 0, 0,
|
1759
|
+
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
1760
|
+
:tDOT, ".", EXPR_DOT, 0, 0,
|
1761
|
+
:tIDENTIFIER, "c", EXPR_ARG, 0, 0, # different
|
1762
|
+
:tSYMBOL, "d", EXPR_LIT, 0, 0,
|
1763
|
+
:tASSOC, "=>", EXPR_BEG, 0, 0,
|
1764
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
1631
1765
|
|
1632
|
-
|
1766
|
+
assert_lex("a = b.a :d => 1",
|
1767
|
+
s(:lasgn, :a,
|
1768
|
+
s(:call, s(:call, nil, :b), :a,
|
1769
|
+
s(:hash, s(:lit, :d), s(:lit, 1)))),
|
1770
|
+
|
1771
|
+
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
1772
|
+
:tEQL, "=", EXPR_BEG, 0, 0,
|
1773
|
+
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
1774
|
+
:tDOT, ".", EXPR_DOT, 0, 0,
|
1775
|
+
:tIDENTIFIER, "a", EXPR_ARG, 0, 0, # same as lvar
|
1776
|
+
:tSYMBOL, "d", EXPR_LIT, 0, 0,
|
1777
|
+
:tASSOC, "=>", EXPR_BEG, 0, 0,
|
1778
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
1633
1779
|
end
|
1634
1780
|
|
1635
1781
|
def test_yylex_lt
|
@@ -1656,12 +1802,22 @@ class TestRubyLexer < Minitest::Test
|
|
1656
1802
|
assert_lex3("<=", nil, :tLEQ, "<=", EXPR_BEG)
|
1657
1803
|
end
|
1658
1804
|
|
1805
|
+
def test_yylex_method_parens_chevron
|
1806
|
+
assert_lex("a()<<1",
|
1807
|
+
s(:call, s(:call, nil, :a), :<<, s(:lit, 1)),
|
1808
|
+
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
1809
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1810
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1811
|
+
:tLSHFT, "<<", EXPR_BEG, 0, 0,
|
1812
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
1813
|
+
end
|
1814
|
+
|
1659
1815
|
def test_yylex_minus
|
1660
1816
|
assert_lex3("1 - 2",
|
1661
1817
|
nil,
|
1662
|
-
:tINTEGER, 1,
|
1818
|
+
:tINTEGER, 1, EXPR_NUM,
|
1663
1819
|
:tMINUS, "-", EXPR_BEG,
|
1664
|
-
:tINTEGER, 2,
|
1820
|
+
:tINTEGER, 2, EXPR_NUM)
|
1665
1821
|
end
|
1666
1822
|
|
1667
1823
|
def test_yylex_minus_equals
|
@@ -1684,7 +1840,39 @@ class TestRubyLexer < Minitest::Test
|
|
1684
1840
|
assert_lex3("-42",
|
1685
1841
|
nil,
|
1686
1842
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1687
|
-
:tINTEGER, 42,
|
1843
|
+
:tINTEGER, 42, EXPR_NUM)
|
1844
|
+
end
|
1845
|
+
|
1846
|
+
def test_yylex_not_at_defn
|
1847
|
+
assert_lex("def +@; end",
|
1848
|
+
s(:defn, :+@, s(:args), s(:nil)),
|
1849
|
+
|
1850
|
+
:kDEF, "def", EXPR_FNAME, 0, 0,
|
1851
|
+
:tUPLUS, "+@", EXPR_ARG, 0, 0,
|
1852
|
+
:tSEMI, ";", EXPR_BEG, 0, 0,
|
1853
|
+
:kEND, "end", EXPR_END, 0, 0)
|
1854
|
+
|
1855
|
+
assert_lex("def !@; end",
|
1856
|
+
s(:defn, :"!@", s(:args), s(:nil)),
|
1857
|
+
|
1858
|
+
:kDEF, "def", EXPR_FNAME, 0, 0,
|
1859
|
+
:tBANG, "!@", EXPR_ARG, 0, 0,
|
1860
|
+
:tSEMI, ";", EXPR_BEG, 0, 0,
|
1861
|
+
:kEND, "end", EXPR_END, 0, 0)
|
1862
|
+
end
|
1863
|
+
|
1864
|
+
def test_yylex_not_at_ivar
|
1865
|
+
assert_lex("!@ivar",
|
1866
|
+
s(:call, s(:ivar, :@ivar).line(1), :"!").line(1),
|
1867
|
+
|
1868
|
+
:tBANG, "!", EXPR_BEG, 0, 0,
|
1869
|
+
:tIVAR, "@ivar", EXPR_END, 0, 0)
|
1870
|
+
end
|
1871
|
+
|
1872
|
+
def test_yylex_not_unary_method
|
1873
|
+
self.lex_state = EXPR_FNAME
|
1874
|
+
|
1875
|
+
assert_lex3("!@", nil, :tBANG, "!@", EXPR_ARG)
|
1688
1876
|
end
|
1689
1877
|
|
1690
1878
|
def test_yylex_nth_ref
|
@@ -1700,7 +1888,68 @@ class TestRubyLexer < Minitest::Test
|
|
1700
1888
|
:tNTH_REF, 7, EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1701
1889
|
:tNTH_REF, 8, EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1702
1890
|
:tNTH_REF, 9, EXPR_END,
|
1703
|
-
:tRBRACK, "]",
|
1891
|
+
:tRBRACK, "]", EXPR_END)
|
1892
|
+
end
|
1893
|
+
|
1894
|
+
def test_yylex_number_times_ident_times_return_number
|
1895
|
+
assert_lex("1 * b * 3",
|
1896
|
+
s(:call,
|
1897
|
+
s(:call, s(:lit, 1), :*, s(:call, nil, :b)),
|
1898
|
+
:*, s(:lit, 3)),
|
1899
|
+
|
1900
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0,
|
1901
|
+
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
1902
|
+
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
1903
|
+
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
1904
|
+
:tINTEGER, 3, EXPR_NUM, 0, 0)
|
1905
|
+
|
1906
|
+
assert_lex("1 * b *\n 3",
|
1907
|
+
s(:call,
|
1908
|
+
s(:call, s(:lit, 1), :*, s(:call, nil, :b)),
|
1909
|
+
:*, s(:lit, 3)),
|
1910
|
+
|
1911
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0,
|
1912
|
+
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
1913
|
+
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
1914
|
+
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
1915
|
+
:tINTEGER, 3, EXPR_NUM, 0, 0)
|
1916
|
+
end
|
1917
|
+
|
1918
|
+
def test_yylex_numbers
|
1919
|
+
assert_lex3 "0b10", nil, :tINTEGER, 2, EXPR_NUM
|
1920
|
+
assert_lex3 "0B10", nil, :tINTEGER, 2, EXPR_NUM
|
1921
|
+
|
1922
|
+
assert_lex3 "0d10", nil, :tINTEGER, 10, EXPR_NUM
|
1923
|
+
assert_lex3 "0D10", nil, :tINTEGER, 10, EXPR_NUM
|
1924
|
+
|
1925
|
+
assert_lex3 "0x10", nil, :tINTEGER, 16, EXPR_NUM
|
1926
|
+
assert_lex3 "0X10", nil, :tINTEGER, 16, EXPR_NUM
|
1927
|
+
|
1928
|
+
assert_lex3 "0o10", nil, :tINTEGER, 8, EXPR_NUM
|
1929
|
+
assert_lex3 "0O10", nil, :tINTEGER, 8, EXPR_NUM
|
1930
|
+
|
1931
|
+
assert_lex3 "0o", nil, :tINTEGER, 0, EXPR_NUM
|
1932
|
+
assert_lex3 "0O", nil, :tINTEGER, 0, EXPR_NUM
|
1933
|
+
|
1934
|
+
assert_lex3 "0", nil, :tINTEGER, 0, EXPR_NUM
|
1935
|
+
|
1936
|
+
refute_lex "0x"
|
1937
|
+
refute_lex "0X"
|
1938
|
+
refute_lex "0b"
|
1939
|
+
refute_lex "0B"
|
1940
|
+
refute_lex "0d"
|
1941
|
+
refute_lex "0D"
|
1942
|
+
|
1943
|
+
refute_lex "08"
|
1944
|
+
refute_lex "09"
|
1945
|
+
refute_lex "0o8"
|
1946
|
+
refute_lex "0o9"
|
1947
|
+
refute_lex "0O8"
|
1948
|
+
refute_lex "0O9"
|
1949
|
+
|
1950
|
+
refute_lex "1_e1"
|
1951
|
+
refute_lex "1_.1"
|
1952
|
+
refute_lex "1__1"
|
1704
1953
|
end
|
1705
1954
|
|
1706
1955
|
def test_yylex_open_bracket
|
@@ -1730,9 +1979,9 @@ class TestRubyLexer < Minitest::Test
|
|
1730
1979
|
assert_lex3("m { 3 }",
|
1731
1980
|
nil,
|
1732
1981
|
:tIDENTIFIER, "m", EXPR_CMDARG,
|
1733
|
-
:tLCURLY, "{",
|
1734
|
-
:tINTEGER, 3,
|
1735
|
-
:tRCURLY, "}",
|
1982
|
+
:tLCURLY, "{", EXPR_PAR,
|
1983
|
+
:tINTEGER, 3, EXPR_NUM,
|
1984
|
+
:tRCURLY, "}", EXPR_END)
|
1736
1985
|
end
|
1737
1986
|
|
1738
1987
|
def test_yylex_open_curly_bracket_block
|
@@ -1741,8 +1990,8 @@ class TestRubyLexer < Minitest::Test
|
|
1741
1990
|
assert_lex3("{ 4 }",
|
1742
1991
|
nil,
|
1743
1992
|
:tLBRACE_ARG, "{", EXPR_BEG,
|
1744
|
-
:tINTEGER, 4,
|
1745
|
-
:tRCURLY, "}",
|
1993
|
+
:tINTEGER, 4, EXPR_NUM,
|
1994
|
+
:tRCURLY, "}", EXPR_END)
|
1746
1995
|
end
|
1747
1996
|
|
1748
1997
|
def test_yylex_open_square_bracket_arg
|
@@ -1751,32 +2000,32 @@ class TestRubyLexer < Minitest::Test
|
|
1751
2000
|
assert_lex3("m [ 3 ]",
|
1752
2001
|
nil,
|
1753
2002
|
:tIDENTIFIER, "m", EXPR_CMDARG,
|
1754
|
-
:tLBRACK, "[",
|
1755
|
-
:tINTEGER, 3,
|
1756
|
-
:tRBRACK, "]",
|
2003
|
+
:tLBRACK, "[", EXPR_PAR,
|
2004
|
+
:tINTEGER, 3, EXPR_NUM,
|
2005
|
+
:tRBRACK, "]", EXPR_END)
|
1757
2006
|
end
|
1758
2007
|
|
1759
2008
|
def test_yylex_open_square_bracket_ary
|
1760
2009
|
assert_lex3("[1, 2, 3]",
|
1761
2010
|
nil,
|
1762
2011
|
:tLBRACK, "[", EXPR_PAR,
|
1763
|
-
:tINTEGER, 1, EXPR_NUM, :tCOMMA, ",",
|
1764
|
-
:tINTEGER, 2, EXPR_NUM, :tCOMMA, ",",
|
2012
|
+
:tINTEGER, 1, EXPR_NUM, :tCOMMA, ",", EXPR_PAR,
|
2013
|
+
:tINTEGER, 2, EXPR_NUM, :tCOMMA, ",", EXPR_PAR,
|
1765
2014
|
:tINTEGER, 3, EXPR_NUM,
|
1766
|
-
:tRBRACK, "]",
|
2015
|
+
:tRBRACK, "]", EXPR_END)
|
1767
2016
|
end
|
1768
2017
|
|
1769
2018
|
def test_yylex_open_square_bracket_meth
|
1770
2019
|
assert_lex3("m[3]",
|
1771
2020
|
nil,
|
1772
2021
|
:tIDENTIFIER, "m", EXPR_CMDARG,
|
1773
|
-
:tLBRACK2, "[",
|
1774
|
-
:tINTEGER, 3,
|
1775
|
-
:tRBRACK, "]",
|
2022
|
+
:tLBRACK2, "[", EXPR_PAR,
|
2023
|
+
:tINTEGER, 3, EXPR_NUM,
|
2024
|
+
:tRBRACK, "]", EXPR_END)
|
1776
2025
|
end
|
1777
2026
|
|
1778
2027
|
def test_yylex_or
|
1779
|
-
assert_lex3("|", nil, :tPIPE, "|",
|
2028
|
+
assert_lex3("|", nil, :tPIPE, "|", EXPR_PAR)
|
1780
2029
|
end
|
1781
2030
|
|
1782
2031
|
def test_yylex_or2
|
@@ -1791,12 +2040,85 @@ class TestRubyLexer < Minitest::Test
|
|
1791
2040
|
assert_lex3("|=", nil, :tOP_ASGN, "|", EXPR_BEG)
|
1792
2041
|
end
|
1793
2042
|
|
2043
|
+
def test_yylex_paren_string_interpolated_regexp
|
2044
|
+
setup_lexer('%( #{(/abcd/)} )',
|
2045
|
+
s(:dstr, " ", s(:evstr, s(:lit, /abcd/)), s(:str, " ")))
|
2046
|
+
|
2047
|
+
assert_next_lexeme :tSTRING_BEG, "%)", EXPR_BEG, 0, 0
|
2048
|
+
assert_next_lexeme :tSTRING_CONTENT, " ", EXPR_BEG, 0, 0
|
2049
|
+
assert_next_lexeme :tSTRING_DBEG, '#{', EXPR_BEG, 0, 0
|
2050
|
+
|
2051
|
+
emulate_string_interpolation do
|
2052
|
+
assert_next_lexeme :tLPAREN, "(", EXPR_PAR, 1, 0
|
2053
|
+
assert_next_lexeme :tREGEXP_BEG, "/", EXPR_PAR, 1, 0
|
2054
|
+
assert_next_lexeme :tSTRING_CONTENT, "abcd", EXPR_PAR, 1, 0
|
2055
|
+
assert_next_lexeme :tREGEXP_END, "", EXPR_LIT, 1, 0
|
2056
|
+
assert_next_lexeme :tRPAREN, ")", EXPR_ENDFN, 0, 0
|
2057
|
+
end
|
2058
|
+
|
2059
|
+
assert_next_lexeme :tSTRING_CONTENT, " ", EXPR_BEG, 0, 0
|
2060
|
+
assert_next_lexeme :tSTRING_END, ")", EXPR_LIT, 0, 0
|
2061
|
+
|
2062
|
+
refute_lexeme
|
2063
|
+
end
|
2064
|
+
|
2065
|
+
def test_yylex_paren_string_parens_interpolated
|
2066
|
+
setup_lexer('%((#{b}#{d}))',
|
2067
|
+
s(:dstr,
|
2068
|
+
"(",
|
2069
|
+
s(:evstr, s(:call, nil, :b)),
|
2070
|
+
s(:evstr, s(:call, nil, :d)),
|
2071
|
+
s(:str, ")")))
|
2072
|
+
|
2073
|
+
assert_next_lexeme :tSTRING_BEG, "%)", EXPR_BEG, 0, 0
|
2074
|
+
assert_next_lexeme :tSTRING_CONTENT, "(", EXPR_BEG, 0, 0
|
2075
|
+
assert_next_lexeme :tSTRING_DBEG, '#{', EXPR_BEG, 0, 0
|
2076
|
+
|
2077
|
+
emulate_string_interpolation do
|
2078
|
+
assert_next_lexeme :tIDENTIFIER, "b", EXPR_CMDARG, 0, 0
|
2079
|
+
end
|
2080
|
+
|
2081
|
+
assert_next_lexeme :tSTRING_DBEG, '#{', EXPR_BEG, 0, 0
|
2082
|
+
|
2083
|
+
emulate_string_interpolation do
|
2084
|
+
assert_next_lexeme :tIDENTIFIER, "d", EXPR_CMDARG, 0, 0
|
2085
|
+
end
|
2086
|
+
|
2087
|
+
assert_next_lexeme :tSTRING_CONTENT, ")", EXPR_BEG, 0, 0
|
2088
|
+
assert_next_lexeme :tSTRING_END, ")", EXPR_LIT, 0, 0
|
2089
|
+
|
2090
|
+
refute_lexeme
|
2091
|
+
end
|
2092
|
+
|
2093
|
+
def test_yylex_paren_string_parens_interpolated_regexp
|
2094
|
+
setup_lexer('%((#{(/abcd/)}))',
|
2095
|
+
s(:dstr, "(", s(:evstr, s(:lit, /abcd/)), s(:str, ")")))
|
2096
|
+
|
2097
|
+
assert_next_lexeme :tSTRING_BEG, "%)", EXPR_BEG, 0, 0
|
2098
|
+
assert_next_lexeme :tSTRING_CONTENT, "(", EXPR_BEG, 0, 0
|
2099
|
+
|
2100
|
+
assert_next_lexeme :tSTRING_DBEG, '#{', EXPR_BEG, 0, 0
|
2101
|
+
|
2102
|
+
emulate_string_interpolation do
|
2103
|
+
assert_next_lexeme :tLPAREN, "(", EXPR_PAR, 1, 0
|
2104
|
+
assert_next_lexeme :tREGEXP_BEG, "/", EXPR_PAR, 1, 0
|
2105
|
+
assert_next_lexeme :tSTRING_CONTENT, "abcd", EXPR_PAR, 1, 0
|
2106
|
+
assert_next_lexeme :tREGEXP_END, "", EXPR_LIT, 1, 0
|
2107
|
+
assert_next_lexeme :tRPAREN, ")", EXPR_ENDFN, 0, 0
|
2108
|
+
end
|
2109
|
+
|
2110
|
+
assert_next_lexeme :tSTRING_CONTENT, ")", EXPR_BEG, 0, 0
|
2111
|
+
assert_next_lexeme :tSTRING_END, ")", EXPR_LIT, 0, 0
|
2112
|
+
|
2113
|
+
refute_lexeme
|
2114
|
+
end
|
2115
|
+
|
1794
2116
|
def test_yylex_percent
|
1795
2117
|
assert_lex3("a % 2",
|
1796
2118
|
nil,
|
1797
2119
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1798
2120
|
:tPERCENT, "%", EXPR_BEG,
|
1799
|
-
:tINTEGER, 2,
|
2121
|
+
:tINTEGER, 2, EXPR_NUM)
|
1800
2122
|
end
|
1801
2123
|
|
1802
2124
|
def test_yylex_percent_equals
|
@@ -1804,15 +2126,15 @@ class TestRubyLexer < Minitest::Test
|
|
1804
2126
|
nil,
|
1805
2127
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1806
2128
|
:tOP_ASGN, "%", EXPR_BEG,
|
1807
|
-
:tINTEGER, 2,
|
2129
|
+
:tINTEGER, 2, EXPR_NUM)
|
1808
2130
|
end
|
1809
2131
|
|
1810
2132
|
def test_yylex_plus
|
1811
2133
|
assert_lex3("1 + 1", # TODO lex_state?
|
1812
2134
|
nil,
|
1813
|
-
:tINTEGER, 1,
|
2135
|
+
:tINTEGER, 1, EXPR_NUM,
|
1814
2136
|
:tPLUS, "+", EXPR_BEG,
|
1815
|
-
:tINTEGER, 1,
|
2137
|
+
:tINTEGER, 1, EXPR_NUM)
|
1816
2138
|
end
|
1817
2139
|
|
1818
2140
|
def test_yylex_plus_equals
|
@@ -1831,55 +2153,28 @@ class TestRubyLexer < Minitest::Test
|
|
1831
2153
|
assert_lex3("+@", nil, :tUPLUS, "+@", EXPR_ARG)
|
1832
2154
|
end
|
1833
2155
|
|
1834
|
-
def
|
1835
|
-
|
1836
|
-
|
1837
|
-
assert_lex3("!@", nil, :tUBANG, "!@", EXPR_ARG)
|
2156
|
+
def test_yylex_plus_unary_number
|
2157
|
+
assert_lex3("+42", nil, :tINTEGER, 42, EXPR_NUM)
|
1838
2158
|
end
|
1839
2159
|
|
1840
|
-
def
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
assert_lex3("0d10", nil, :tINTEGER, 10, EXPR_NUM)
|
1845
|
-
assert_lex3("0D10", nil, :tINTEGER, 10, EXPR_NUM)
|
1846
|
-
|
1847
|
-
assert_lex3("0x10", nil, :tINTEGER, 16, EXPR_NUM)
|
1848
|
-
assert_lex3("0X10", nil, :tINTEGER, 16, EXPR_NUM)
|
1849
|
-
|
1850
|
-
assert_lex3("0o10", nil, :tINTEGER, 8, EXPR_NUM)
|
1851
|
-
assert_lex3("0O10", nil, :tINTEGER, 8, EXPR_NUM)
|
1852
|
-
|
1853
|
-
assert_lex3("0o", nil, :tINTEGER, 0, EXPR_NUM)
|
1854
|
-
assert_lex3("0O", nil, :tINTEGER, 0, EXPR_NUM)
|
1855
|
-
|
1856
|
-
assert_lex3("0", nil, :tINTEGER, 0, EXPR_NUM)
|
1857
|
-
|
1858
|
-
refute_lex "0x"
|
1859
|
-
refute_lex "0X"
|
1860
|
-
refute_lex "0b"
|
1861
|
-
refute_lex "0B"
|
1862
|
-
refute_lex "0d"
|
1863
|
-
refute_lex "0D"
|
2160
|
+
def test_yylex_question_bad_eos
|
2161
|
+
refute_lex "?"
|
2162
|
+
end
|
1864
2163
|
|
1865
|
-
|
1866
|
-
|
1867
|
-
refute_lex "0o8"
|
1868
|
-
refute_lex "0o9"
|
1869
|
-
refute_lex "0O8"
|
1870
|
-
refute_lex "0O9"
|
2164
|
+
def test_yylex_question_eh_a__20
|
2165
|
+
setup_lexer_class RubyParser::V20
|
1871
2166
|
|
1872
|
-
|
1873
|
-
refute_lex "1_.1"
|
1874
|
-
refute_lex "1__1"
|
2167
|
+
assert_lex3("?a", nil, :tSTRING, "a", EXPR_END)
|
1875
2168
|
end
|
1876
2169
|
|
1877
|
-
def
|
1878
|
-
|
2170
|
+
def test_yylex_question_eh_escape_M_escape_C__20
|
2171
|
+
setup_lexer_class RubyParser::V20
|
2172
|
+
|
2173
|
+
assert_lex3("?\\M-\\C-a", nil, :tSTRING, "\M-\C-a", EXPR_END)
|
1879
2174
|
end
|
1880
2175
|
|
1881
|
-
def
|
1882
|
-
|
2176
|
+
def test_yylex_question_control_escape
|
2177
|
+
assert_lex3('?\C-\]', nil, :tSTRING, ?\C-\], EXPR_END)
|
1883
2178
|
end
|
1884
2179
|
|
1885
2180
|
def test_yylex_question_ws
|
@@ -1903,11 +2198,11 @@ class TestRubyLexer < Minitest::Test
|
|
1903
2198
|
end
|
1904
2199
|
|
1905
2200
|
def test_yylex_rbracket
|
1906
|
-
assert_lex3("]", nil, :tRBRACK, "]",
|
2201
|
+
assert_lex3("]", nil, :tRBRACK, "]", EXPR_END)
|
1907
2202
|
end
|
1908
2203
|
|
1909
2204
|
def test_yylex_rcurly
|
1910
|
-
assert_lex("}", nil, :tRCURLY, "}",
|
2205
|
+
assert_lex("}", nil, :tRCURLY, "}", EXPR_END, 0, 1) do
|
1911
2206
|
lexer.brace_nest += 2
|
1912
2207
|
end
|
1913
2208
|
end
|
@@ -1917,7 +2212,7 @@ class TestRubyLexer < Minitest::Test
|
|
1917
2212
|
nil,
|
1918
2213
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1919
2214
|
:tSTRING_CONTENT, "regexp", EXPR_BEG,
|
1920
|
-
:tREGEXP_END, "",
|
2215
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1921
2216
|
end
|
1922
2217
|
|
1923
2218
|
def test_yylex_regexp_ambiguous
|
@@ -1926,7 +2221,7 @@ class TestRubyLexer < Minitest::Test
|
|
1926
2221
|
:tIDENTIFIER, "method", EXPR_CMDARG,
|
1927
2222
|
:tREGEXP_BEG, "/", EXPR_CMDARG,
|
1928
2223
|
:tSTRING_CONTENT, "regexp", EXPR_CMDARG,
|
1929
|
-
:tREGEXP_END, "",
|
2224
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1930
2225
|
end
|
1931
2226
|
|
1932
2227
|
def test_yylex_regexp_bad
|
@@ -1940,7 +2235,7 @@ class TestRubyLexer < Minitest::Test
|
|
1940
2235
|
nil,
|
1941
2236
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1942
2237
|
:tSTRING_CONTENT, "regex\\C-x", EXPR_BEG,
|
1943
|
-
:tREGEXP_END, "",
|
2238
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1944
2239
|
end
|
1945
2240
|
|
1946
2241
|
def test_yylex_regexp_escape_C_M
|
@@ -1948,15 +2243,16 @@ class TestRubyLexer < Minitest::Test
|
|
1948
2243
|
nil,
|
1949
2244
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1950
2245
|
:tSTRING_CONTENT, "regex\\C-\\M-x", EXPR_BEG,
|
1951
|
-
:tREGEXP_END, "",
|
2246
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1952
2247
|
end
|
1953
2248
|
|
1954
2249
|
def test_yylex_regexp_escape_C_M_craaaazy
|
1955
|
-
|
2250
|
+
rb = "/regex\\C-\\\n\\M-x/"
|
2251
|
+
assert_lex3(rb,
|
1956
2252
|
nil,
|
1957
2253
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1958
2254
|
:tSTRING_CONTENT, "regex\\C-\\M-x", EXPR_BEG,
|
1959
|
-
:tREGEXP_END, "",
|
2255
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1960
2256
|
end
|
1961
2257
|
|
1962
2258
|
def test_yylex_regexp_escape_C_bad_dash
|
@@ -1984,7 +2280,7 @@ class TestRubyLexer < Minitest::Test
|
|
1984
2280
|
nil,
|
1985
2281
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1986
2282
|
:tSTRING_CONTENT, "regex\\M-x", EXPR_BEG,
|
1987
|
-
:tREGEXP_END, "",
|
2283
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1988
2284
|
end
|
1989
2285
|
|
1990
2286
|
def test_yylex_regexp_escape_M_C
|
@@ -1992,7 +2288,7 @@ class TestRubyLexer < Minitest::Test
|
|
1992
2288
|
nil,
|
1993
2289
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1994
2290
|
:tSTRING_CONTENT, "regex\\M-\\C-x", EXPR_BEG,
|
1995
|
-
:tREGEXP_END, "",
|
2291
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1996
2292
|
end
|
1997
2293
|
|
1998
2294
|
def test_yylex_regexp_escape_M_bad_dash
|
@@ -2014,49 +2310,45 @@ class TestRubyLexer < Minitest::Test
|
|
2014
2310
|
def test_yylex_regexp_escape_backslash_slash
|
2015
2311
|
assert_lex3("/\\//",
|
2016
2312
|
nil,
|
2017
|
-
:tREGEXP_BEG, "/",
|
2018
|
-
:tSTRING_CONTENT, "
|
2019
|
-
:tREGEXP_END, "",
|
2313
|
+
:tREGEXP_BEG, "/", EXPR_BEG,
|
2314
|
+
:tSTRING_CONTENT, "/", EXPR_BEG,
|
2315
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2020
2316
|
end
|
2021
2317
|
|
2022
2318
|
def test_yylex_regexp_escape_backslash_terminator
|
2023
|
-
|
2024
|
-
|
2025
|
-
:
|
2026
|
-
:
|
2027
|
-
:
|
2028
|
-
|
2029
|
-
|
2030
|
-
def test_yylex_regexp_escaped_delim
|
2031
|
-
assert_lex3("%r!blah(?\\!blah)!",
|
2032
|
-
nil,
|
2033
|
-
:tREGEXP_BEG, "%r\000", EXPR_BEG,
|
2034
|
-
:tSTRING_CONTENT, "blah(?!blah)", EXPR_BEG,
|
2035
|
-
:tREGEXP_END, "", EXPR_END)
|
2319
|
+
rb = "%r%blah\\%blah%"
|
2320
|
+
assert_lex3(rb,
|
2321
|
+
s(:lit, /blah%blah/).line(1),
|
2322
|
+
:tREGEXP_BEG, "%r\0", EXPR_BEG,
|
2323
|
+
:tSTRING_CONTENT, "blah%blah", EXPR_BEG,
|
2324
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2036
2325
|
end
|
2037
2326
|
|
2038
2327
|
def test_yylex_regexp_escape_backslash_terminator_meta1
|
2039
2328
|
assert_lex3("%r{blah\\}blah}",
|
2040
|
-
|
2041
|
-
:tREGEXP_BEG, "%r{", EXPR_BEG,
|
2329
|
+
s(:lit, /blah\}blah/).line(1),
|
2330
|
+
:tREGEXP_BEG, "%r{", EXPR_BEG,
|
2042
2331
|
:tSTRING_CONTENT, "blah\\}blah", EXPR_BEG,
|
2043
|
-
:tREGEXP_END, "",
|
2332
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2044
2333
|
end
|
2045
2334
|
|
2046
2335
|
def test_yylex_regexp_escape_backslash_terminator_meta2
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2336
|
+
rb = "%r/blah\\/blah/"
|
2337
|
+
pt = s(:lit, /blah\/blah/).line 1
|
2338
|
+
|
2339
|
+
assert_lex3(rb,
|
2340
|
+
pt,
|
2341
|
+
:tREGEXP_BEG, "%r\0", EXPR_BEG,
|
2342
|
+
:tSTRING_CONTENT, "blah/blah", EXPR_BEG,
|
2343
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2052
2344
|
end
|
2053
2345
|
|
2054
2346
|
def test_yylex_regexp_escape_backslash_terminator_meta3
|
2055
2347
|
assert_lex3("%r/blah\\%blah/",
|
2056
2348
|
nil,
|
2057
|
-
:tREGEXP_BEG, "%r\
|
2349
|
+
:tREGEXP_BEG, "%r\0", EXPR_BEG,
|
2058
2350
|
:tSTRING_CONTENT, "blah\\%blah", EXPR_BEG,
|
2059
|
-
:tREGEXP_END, "",
|
2351
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2060
2352
|
end
|
2061
2353
|
|
2062
2354
|
def test_yylex_regexp_escape_bad_eos
|
@@ -2064,11 +2356,12 @@ class TestRubyLexer < Minitest::Test
|
|
2064
2356
|
end
|
2065
2357
|
|
2066
2358
|
def test_yylex_regexp_escape_bs
|
2067
|
-
|
2068
|
-
|
2359
|
+
rp = "/regex\\\\regex/"
|
2360
|
+
assert_lex3(rp,
|
2361
|
+
s(:lit, /regex\\regex/),
|
2069
2362
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2070
2363
|
:tSTRING_CONTENT, "regex\\\\regex", EXPR_BEG,
|
2071
|
-
:tREGEXP_END, "",
|
2364
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2072
2365
|
end
|
2073
2366
|
|
2074
2367
|
def test_yylex_regexp_escape_c
|
@@ -2076,7 +2369,7 @@ class TestRubyLexer < Minitest::Test
|
|
2076
2369
|
nil,
|
2077
2370
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2078
2371
|
:tSTRING_CONTENT, "regex\\cxxx", EXPR_BEG,
|
2079
|
-
:tREGEXP_END, "",
|
2372
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2080
2373
|
end
|
2081
2374
|
|
2082
2375
|
def test_yylex_regexp_escape_c_backslash
|
@@ -2084,7 +2377,7 @@ class TestRubyLexer < Minitest::Test
|
|
2084
2377
|
nil,
|
2085
2378
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2086
2379
|
:tSTRING_CONTENT, "regex\\c\\n", EXPR_BEG,
|
2087
|
-
:tREGEXP_END, "",
|
2380
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2088
2381
|
end
|
2089
2382
|
|
2090
2383
|
def test_yylex_regexp_escape_chars
|
@@ -2092,16 +2385,18 @@ class TestRubyLexer < Minitest::Test
|
|
2092
2385
|
nil,
|
2093
2386
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2094
2387
|
:tSTRING_CONTENT, "re\\tge\\nxp", EXPR_BEG,
|
2095
|
-
:tREGEXP_END, "",
|
2388
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2096
2389
|
end
|
2097
2390
|
|
2098
2391
|
def test_yylex_regexp_escape_double_backslash
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
:
|
2392
|
+
rb = '/[\\/\\\\]$/'
|
2393
|
+
pt = s(:lit, /[\/\\]$/)
|
2394
|
+
|
2395
|
+
assert_lex3(rb,
|
2396
|
+
pt,
|
2397
|
+
:tREGEXP_BEG, "/", EXPR_BEG,
|
2398
|
+
:tSTRING_CONTENT, "[/\\\\]$", EXPR_BEG,
|
2399
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2105
2400
|
end
|
2106
2401
|
|
2107
2402
|
def test_yylex_regexp_escape_hex
|
@@ -2109,7 +2404,7 @@ class TestRubyLexer < Minitest::Test
|
|
2109
2404
|
nil,
|
2110
2405
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2111
2406
|
:tSTRING_CONTENT, "regex\\x61xp", EXPR_BEG,
|
2112
|
-
:tREGEXP_END, "",
|
2407
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2113
2408
|
end
|
2114
2409
|
|
2115
2410
|
def test_yylex_regexp_escape_hex_bad
|
@@ -2121,7 +2416,7 @@ class TestRubyLexer < Minitest::Test
|
|
2121
2416
|
nil,
|
2122
2417
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2123
2418
|
:tSTRING_CONTENT, "^[\\xd\\xa]{2}", EXPR_BEG,
|
2124
|
-
:tREGEXP_END, "on",
|
2419
|
+
:tREGEXP_END, "on", EXPR_LIT)
|
2125
2420
|
end
|
2126
2421
|
|
2127
2422
|
def test_yylex_regexp_escape_oct1
|
@@ -2129,7 +2424,7 @@ class TestRubyLexer < Minitest::Test
|
|
2129
2424
|
nil,
|
2130
2425
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2131
2426
|
:tSTRING_CONTENT, "regex\\0xp", EXPR_BEG,
|
2132
|
-
:tREGEXP_END, "",
|
2427
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2133
2428
|
end
|
2134
2429
|
|
2135
2430
|
def test_yylex_regexp_escape_oct2
|
@@ -2137,7 +2432,7 @@ class TestRubyLexer < Minitest::Test
|
|
2137
2432
|
nil,
|
2138
2433
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2139
2434
|
:tSTRING_CONTENT, "regex\\07xp", EXPR_BEG,
|
2140
|
-
:tREGEXP_END, "",
|
2435
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2141
2436
|
end
|
2142
2437
|
|
2143
2438
|
def test_yylex_regexp_escape_oct3
|
@@ -2145,7 +2440,7 @@ class TestRubyLexer < Minitest::Test
|
|
2145
2440
|
nil,
|
2146
2441
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2147
2442
|
:tSTRING_CONTENT, "regex\\10142", EXPR_BEG,
|
2148
|
-
:tREGEXP_END, "",
|
2443
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2149
2444
|
end
|
2150
2445
|
|
2151
2446
|
def test_yylex_regexp_escape_return
|
@@ -2153,7 +2448,15 @@ class TestRubyLexer < Minitest::Test
|
|
2153
2448
|
nil,
|
2154
2449
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2155
2450
|
:tSTRING_CONTENT, "regexregex", EXPR_BEG,
|
2156
|
-
:tREGEXP_END, "",
|
2451
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2452
|
+
end
|
2453
|
+
|
2454
|
+
def test_yylex_regexp_escaped_delim
|
2455
|
+
assert_lex3("%r!blah(?\\!blah)!",
|
2456
|
+
nil,
|
2457
|
+
:tREGEXP_BEG, "%r\0", EXPR_BEG,
|
2458
|
+
:tSTRING_CONTENT, "blah(?!blah)", EXPR_BEG,
|
2459
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2157
2460
|
end
|
2158
2461
|
|
2159
2462
|
def test_yylex_regexp_nm
|
@@ -2161,7 +2464,20 @@ class TestRubyLexer < Minitest::Test
|
|
2161
2464
|
nil,
|
2162
2465
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2163
2466
|
:tSTRING_CONTENT, ".*", EXPR_BEG,
|
2164
|
-
:tREGEXP_END, "nm",
|
2467
|
+
:tREGEXP_END, "nm", EXPR_LIT)
|
2468
|
+
end
|
2469
|
+
|
2470
|
+
def test_yylex_required_kwarg_no_value_22
|
2471
|
+
setup_lexer_class RubyParser::V22
|
2472
|
+
|
2473
|
+
assert_lex3("def foo a:, b:\nend",
|
2474
|
+
nil,
|
2475
|
+
:kDEF, "def", EXPR_FNAME,
|
2476
|
+
:tIDENTIFIER, "foo", EXPR_ENDFN,
|
2477
|
+
:tLABEL, "a", EXPR_LAB,
|
2478
|
+
:tCOMMA, ",", EXPR_PAR,
|
2479
|
+
:tLABEL, "b", EXPR_LAB,
|
2480
|
+
:kEND, "end", EXPR_END)
|
2165
2481
|
end
|
2166
2482
|
|
2167
2483
|
def test_yylex_rparen
|
@@ -2173,7 +2489,7 @@ class TestRubyLexer < Minitest::Test
|
|
2173
2489
|
nil,
|
2174
2490
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
2175
2491
|
:tRSHFT, ">>", EXPR_BEG,
|
2176
|
-
:tINTEGER, 2,
|
2492
|
+
:tINTEGER, 2, EXPR_NUM)
|
2177
2493
|
end
|
2178
2494
|
|
2179
2495
|
def test_yylex_rshft_equals
|
@@ -2181,7 +2497,7 @@ class TestRubyLexer < Minitest::Test
|
|
2181
2497
|
nil,
|
2182
2498
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
2183
2499
|
:tOP_ASGN, ">>", EXPR_BEG,
|
2184
|
-
:tINTEGER, 2,
|
2500
|
+
:tINTEGER, 2, EXPR_NUM)
|
2185
2501
|
end
|
2186
2502
|
|
2187
2503
|
def test_yylex_star
|
@@ -2249,11 +2565,13 @@ class TestRubyLexer < Minitest::Test
|
|
2249
2565
|
end
|
2250
2566
|
|
2251
2567
|
def test_yylex_string_bad_eos
|
2252
|
-
refute_lex(
|
2568
|
+
refute_lex("%", :tSTRING_BEG, "%")
|
2253
2569
|
end
|
2254
2570
|
|
2255
2571
|
def test_yylex_string_bad_eos_quote
|
2256
|
-
refute_lex(
|
2572
|
+
refute_lex("%{nest",
|
2573
|
+
:tSTRING_BEG, "%}",
|
2574
|
+
:tSTRING_CONTENT, "nest")
|
2257
2575
|
end
|
2258
2576
|
|
2259
2577
|
def test_yylex_string_double
|
@@ -2265,11 +2583,11 @@ class TestRubyLexer < Minitest::Test
|
|
2265
2583
|
end
|
2266
2584
|
|
2267
2585
|
def test_yylex_string_double_escape_C_backslash
|
2268
|
-
assert_lex3("
|
2586
|
+
assert_lex3(%W[ " \\ C - \\ \\ " ].join, # I hate escaping \ in ' and "
|
2269
2587
|
nil,
|
2270
2588
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2271
2589
|
:tSTRING_CONTENT, "\034", EXPR_BEG,
|
2272
|
-
:tSTRING_END, "\"",
|
2590
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2273
2591
|
end
|
2274
2592
|
|
2275
2593
|
def test_yylex_string_double_escape_C_escape
|
@@ -2277,106 +2595,25 @@ class TestRubyLexer < Minitest::Test
|
|
2277
2595
|
nil,
|
2278
2596
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2279
2597
|
:tSTRING_CONTENT, "\201", EXPR_BEG,
|
2280
|
-
:tSTRING_END, "\"",
|
2598
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2281
2599
|
end
|
2282
2600
|
|
2283
2601
|
def test_yylex_string_double_escape_C_question
|
2284
2602
|
assert_lex3("\"\\C-?\"", nil, :tSTRING, "\177", EXPR_END)
|
2285
2603
|
end
|
2286
2604
|
|
2287
|
-
def test_yylex_string_utf8_simple
|
2288
|
-
chr = [0x3024].pack("U")
|
2289
|
-
|
2290
|
-
assert_lex3('"\u{3024}"',
|
2291
|
-
s(:str, chr),
|
2292
|
-
:tSTRING, chr, EXPR_END)
|
2293
|
-
end
|
2294
|
-
|
2295
|
-
def test_yylex_string_utf8_trailing_hex
|
2296
|
-
chr = [0x3024].pack("U")
|
2297
|
-
str = "#{chr}abz"
|
2298
|
-
|
2299
|
-
assert_lex3('"\u3024abz"',
|
2300
|
-
s(:str, str),
|
2301
|
-
:tSTRING, str, EXPR_END)
|
2302
|
-
end
|
2303
|
-
|
2304
|
-
def test_yylex_string_utf8_missing_hex
|
2305
|
-
refute_lex('"\u3zzz"')
|
2306
|
-
refute_lex('"\u30zzz"')
|
2307
|
-
refute_lex('"\u302zzz"')
|
2308
|
-
end
|
2309
|
-
|
2310
|
-
def test_yylex_string_utf8_complex
|
2311
|
-
chr = [0x3024].pack("U")
|
2312
|
-
|
2313
|
-
assert_lex3('"#@a\u{3024}"',
|
2314
|
-
s(:dstr, "", s(:evstr, s(:ivar, :@a)), s(:str, chr)),
|
2315
|
-
:tSTRING_BEG, '"', EXPR_BEG,
|
2316
|
-
:tSTRING_DVAR, nil, EXPR_BEG,
|
2317
|
-
:tSTRING_CONTENT, "@a"+chr, EXPR_BEG,
|
2318
|
-
:tSTRING_END, '"', EXPR_END)
|
2319
|
-
end
|
2320
|
-
|
2321
|
-
def test_yylex_string_utf8_complex_trailing_hex
|
2322
|
-
chr = [0x3024].pack("U")
|
2323
|
-
str = "#{chr}abz"
|
2324
|
-
|
2325
|
-
assert_lex3('"#@a\u3024abz"',
|
2326
|
-
s(:dstr, "", s(:evstr, s(:ivar, :@a)), s(:str, str)),
|
2327
|
-
:tSTRING_BEG, '"', EXPR_BEG,
|
2328
|
-
:tSTRING_DVAR, nil, EXPR_BEG,
|
2329
|
-
:tSTRING_CONTENT, "@a"+str, EXPR_BEG,
|
2330
|
-
:tSTRING_END, '"', EXPR_END)
|
2331
|
-
end
|
2332
|
-
|
2333
|
-
def test_yylex_string_utf8_complex_missing_hex
|
2334
|
-
chr = [0x302].pack("U")
|
2335
|
-
str = "#{chr}zzz"
|
2336
|
-
|
2337
|
-
refute_lex('"#@a\u302zzz"',
|
2338
|
-
:tSTRING_BEG, '"',
|
2339
|
-
:tSTRING_DVAR, nil,
|
2340
|
-
:tSTRING_CONTENT, "@a"+str,
|
2341
|
-
:tSTRING_END, '"')
|
2342
|
-
|
2343
|
-
chr = [0x30].pack("U")
|
2344
|
-
str = "#{chr}zzz"
|
2345
|
-
|
2346
|
-
refute_lex('"#@a\u30zzz"',
|
2347
|
-
:tSTRING_BEG, '"',
|
2348
|
-
:tSTRING_DVAR, nil,
|
2349
|
-
:tSTRING_CONTENT, "@a"+str,
|
2350
|
-
:tSTRING_END, '"')
|
2351
|
-
|
2352
|
-
chr = [0x3].pack("U")
|
2353
|
-
str = "#{chr}zzz"
|
2354
|
-
|
2355
|
-
refute_lex('"#@a\u3zzz"',
|
2356
|
-
:tSTRING_BEG, '"',
|
2357
|
-
:tSTRING_DVAR, nil,
|
2358
|
-
:tSTRING_CONTENT, "@a"+str,
|
2359
|
-
:tSTRING_END, '"')
|
2360
|
-
end
|
2361
|
-
|
2362
2605
|
def test_yylex_string_double_escape_M
|
2363
2606
|
chr = "\341"
|
2364
2607
|
|
2365
2608
|
assert_lex3("\"\\M-a\"", nil, :tSTRING, chr, EXPR_END)
|
2366
2609
|
end
|
2367
2610
|
|
2368
|
-
def test_why_does_ruby_hate_me?
|
2369
|
-
assert_lex3("\"Nl%\\000\\000A\\000\\999\"", # you should be ashamed
|
2370
|
-
nil,
|
2371
|
-
:tSTRING, ["Nl%","\x00","\x00","A","\x00","999"].join, EXPR_END)
|
2372
|
-
end
|
2373
|
-
|
2374
2611
|
def test_yylex_string_double_escape_M_backslash
|
2375
2612
|
assert_lex3("\"\\M-\\\\\"",
|
2376
2613
|
nil,
|
2377
2614
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2378
2615
|
:tSTRING_CONTENT, "\334", EXPR_BEG,
|
2379
|
-
:tSTRING_END, "\"",
|
2616
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2380
2617
|
end
|
2381
2618
|
|
2382
2619
|
def test_yylex_string_double_escape_M_escape
|
@@ -2384,7 +2621,7 @@ class TestRubyLexer < Minitest::Test
|
|
2384
2621
|
nil,
|
2385
2622
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2386
2623
|
:tSTRING_CONTENT, "\201", EXPR_BEG,
|
2387
|
-
:tSTRING_END, "\"",
|
2624
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2388
2625
|
end
|
2389
2626
|
|
2390
2627
|
def test_yylex_string_double_escape_bs1
|
@@ -2400,11 +2637,9 @@ class TestRubyLexer < Minitest::Test
|
|
2400
2637
|
end
|
2401
2638
|
|
2402
2639
|
def test_yylex_string_double_escape_c_backslash
|
2403
|
-
|
2404
|
-
|
2405
|
-
|
2406
|
-
:tSTRING_CONTENT, "\034", EXPR_BEG,
|
2407
|
-
:tSTRING_END, "\"", EXPR_END)
|
2640
|
+
refute_lex('"\\c\\"',
|
2641
|
+
:tSTRING_BEG, '"',
|
2642
|
+
:tSTRING_CONTENT, "\002")
|
2408
2643
|
end
|
2409
2644
|
|
2410
2645
|
def test_yylex_string_double_escape_c_escape
|
@@ -2412,7 +2647,7 @@ class TestRubyLexer < Minitest::Test
|
|
2412
2647
|
nil,
|
2413
2648
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2414
2649
|
:tSTRING_CONTENT, "\201", EXPR_BEG,
|
2415
|
-
:tSTRING_END, "\"",
|
2650
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2416
2651
|
end
|
2417
2652
|
|
2418
2653
|
def test_yylex_string_double_escape_c_question
|
@@ -2440,21 +2675,13 @@ class TestRubyLexer < Minitest::Test
|
|
2440
2675
|
nil,
|
2441
2676
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2442
2677
|
:tSTRING_CONTENT, "blah #x a ", EXPR_BEG,
|
2443
|
-
:tSTRING_DVAR,
|
2678
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
2444
2679
|
:tSTRING_CONTENT, "@a b ", EXPR_BEG,
|
2445
|
-
:tSTRING_DVAR,
|
2680
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
2446
2681
|
:tSTRING_CONTENT, "$b c ", EXPR_BEG,
|
2447
|
-
:tSTRING_DBEG,
|
2448
|
-
:tSTRING_CONTENT, "3} # ", EXPR_BEG,
|
2449
|
-
:tSTRING_END, "\"",
|
2450
|
-
end
|
2451
|
-
|
2452
|
-
def test_yylex_string_double_pound_dollar_bad
|
2453
|
-
assert_lex3('"#$%"', nil,
|
2454
|
-
|
2455
|
-
:tSTRING_BEG, "\"", EXPR_BEG,
|
2456
|
-
:tSTRING_CONTENT, '#$%', EXPR_BEG,
|
2457
|
-
:tSTRING_END, "\"", EXPR_END)
|
2682
|
+
:tSTRING_DBEG, "#\{", EXPR_BEG,
|
2683
|
+
:tSTRING_CONTENT, "3} # ", EXPR_BEG, # FIX: wrong!?!?
|
2684
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2458
2685
|
end
|
2459
2686
|
|
2460
2687
|
def test_yylex_string_double_nested_curlies
|
@@ -2462,7 +2689,7 @@ class TestRubyLexer < Minitest::Test
|
|
2462
2689
|
nil,
|
2463
2690
|
:tSTRING_BEG, "%}", EXPR_BEG,
|
2464
2691
|
:tSTRING_CONTENT, "nest{one{two}one}nest", EXPR_BEG,
|
2465
|
-
:tSTRING_END, "}",
|
2692
|
+
:tSTRING_END, "}", EXPR_LIT)
|
2466
2693
|
end
|
2467
2694
|
|
2468
2695
|
def test_yylex_string_double_no_interp
|
@@ -2470,76 +2697,145 @@ class TestRubyLexer < Minitest::Test
|
|
2470
2697
|
assert_lex3("\"blah # blah\"", nil, :tSTRING, "blah # blah", EXPR_END)
|
2471
2698
|
end
|
2472
2699
|
|
2700
|
+
def test_yylex_string_double_pound_dollar_bad
|
2701
|
+
assert_lex3('"#$%"', nil,
|
2702
|
+
|
2703
|
+
:tSTRING_BEG, "\"", EXPR_BEG,
|
2704
|
+
:tSTRING_CONTENT, "#\$%", EXPR_BEG,
|
2705
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2706
|
+
end
|
2707
|
+
|
2473
2708
|
def test_yylex_string_escape_x_single
|
2474
2709
|
assert_lex3("\"\\x0\"", nil, :tSTRING, "\000", EXPR_END)
|
2475
2710
|
end
|
2476
2711
|
|
2477
|
-
def
|
2478
|
-
assert_lex3("%
|
2712
|
+
def test_yylex_string_pct_I
|
2713
|
+
assert_lex3("%I[s1 s2\ns3]",
|
2479
2714
|
nil,
|
2480
|
-
:
|
2715
|
+
:tSYMBOLS_BEG, "%I[", EXPR_BEG,
|
2481
2716
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2482
|
-
:tSPACE,
|
2717
|
+
:tSPACE, " ", EXPR_BEG,
|
2483
2718
|
:tSTRING_CONTENT, "s2", EXPR_BEG,
|
2484
|
-
:tSPACE,
|
2719
|
+
:tSPACE, " ", EXPR_BEG,
|
2485
2720
|
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2486
|
-
:tSPACE,
|
2487
|
-
:tSTRING_END,
|
2721
|
+
:tSPACE, "]", EXPR_BEG,
|
2722
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2488
2723
|
end
|
2489
2724
|
|
2490
|
-
def
|
2491
|
-
assert_lex3("%I[s1 s2\ns3]",
|
2725
|
+
def test_yylex_string_pct_I_extra_space
|
2726
|
+
assert_lex3("%I[ s1 s2\ns3 ]",
|
2492
2727
|
nil,
|
2493
2728
|
:tSYMBOLS_BEG, "%I[", EXPR_BEG,
|
2494
2729
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2495
|
-
:tSPACE,
|
2730
|
+
:tSPACE, " ", EXPR_BEG,
|
2496
2731
|
:tSTRING_CONTENT, "s2", EXPR_BEG,
|
2497
|
-
:tSPACE,
|
2732
|
+
:tSPACE, " ", EXPR_BEG,
|
2498
2733
|
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2499
|
-
:tSPACE,
|
2500
|
-
:tSTRING_END,
|
2734
|
+
:tSPACE, "]", EXPR_BEG,
|
2735
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2501
2736
|
end
|
2502
2737
|
|
2503
|
-
def
|
2504
|
-
assert_lex3("%
|
2738
|
+
def test_yylex_string_pct_Q
|
2739
|
+
assert_lex3("%Q[s1 s2]",
|
2740
|
+
nil,
|
2741
|
+
:tSTRING_BEG, "%Q[", EXPR_BEG,
|
2742
|
+
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2743
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2744
|
+
end
|
2745
|
+
|
2746
|
+
def test_yylex_string_pct_Q_null_wtf?
|
2747
|
+
assert_lex3("%Q\0s1 s2\0",
|
2748
|
+
nil,
|
2749
|
+
:tSTRING_BEG, "%Q\0", EXPR_BEG,
|
2750
|
+
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2751
|
+
:tSTRING_END, "\0", EXPR_LIT)
|
2752
|
+
end
|
2753
|
+
|
2754
|
+
def test_yylex_string_pct_Q_bang
|
2755
|
+
assert_lex3("%Q!s1 s2!",
|
2756
|
+
nil,
|
2757
|
+
:tSTRING_BEG, "%Q\0", EXPR_BEG,
|
2758
|
+
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2759
|
+
:tSTRING_END, "!", EXPR_LIT)
|
2760
|
+
end
|
2761
|
+
|
2762
|
+
def test_yylex_string_pct_W
|
2763
|
+
assert_lex3("%W[s1 s2\ns3]", # TODO: add interpolation to these
|
2764
|
+
nil,
|
2765
|
+
:tWORDS_BEG, "%W[", EXPR_BEG,
|
2766
|
+
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2767
|
+
:tSPACE, " ", EXPR_BEG,
|
2768
|
+
:tSTRING_CONTENT, "s2", EXPR_BEG,
|
2769
|
+
:tSPACE, " ", EXPR_BEG,
|
2770
|
+
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2771
|
+
:tSPACE, "]", EXPR_BEG,
|
2772
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2773
|
+
end
|
2774
|
+
|
2775
|
+
def test_yylex_string_pct_W_bs_nl
|
2776
|
+
rb = "%W[s1 \\\ns2]" # TODO: add interpolation to these
|
2777
|
+
pt = s(:array,
|
2778
|
+
s(:str, "s1").line(1),
|
2779
|
+
s(:str, "\ns2").line(1)).line(1)
|
2780
|
+
|
2781
|
+
assert_lex3(rb,
|
2782
|
+
pt,
|
2783
|
+
:tWORDS_BEG, "%W[", EXPR_BEG,
|
2784
|
+
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2785
|
+
:tSPACE, " ", EXPR_BEG,
|
2786
|
+
:tSTRING_CONTENT, "\ns2", EXPR_BEG,
|
2787
|
+
:tSPACE, "]", EXPR_BEG,
|
2788
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2789
|
+
end
|
2790
|
+
|
2791
|
+
def test_yylex_string_pct_angle
|
2792
|
+
assert_lex3("%<blah>",
|
2793
|
+
nil,
|
2794
|
+
:tSTRING_BEG, "%>", EXPR_BEG,
|
2795
|
+
:tSTRING_CONTENT, "blah", EXPR_BEG,
|
2796
|
+
:tSTRING_END, ">", EXPR_LIT)
|
2797
|
+
end
|
2798
|
+
|
2799
|
+
def test_yylex_string_pct_i
|
2800
|
+
assert_lex3("%i[s1 s2\ns3]",
|
2505
2801
|
nil,
|
2506
2802
|
:tQSYMBOLS_BEG, "%i[", EXPR_BEG,
|
2507
2803
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2508
|
-
:tSPACE,
|
2804
|
+
:tSPACE, " ", EXPR_BEG,
|
2509
2805
|
:tSTRING_CONTENT, "s2", EXPR_BEG,
|
2510
|
-
:tSPACE,
|
2806
|
+
:tSPACE, " ", EXPR_BEG,
|
2511
2807
|
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2512
|
-
:tSPACE,
|
2513
|
-
:tSTRING_END,
|
2808
|
+
:tSPACE, "]", EXPR_BEG,
|
2809
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2514
2810
|
end
|
2515
2811
|
|
2516
|
-
def
|
2517
|
-
assert_lex3("%
|
2812
|
+
def test_yylex_string_pct_i_extra_space
|
2813
|
+
assert_lex3("%i[ s1 s2\ns3 ]",
|
2518
2814
|
nil,
|
2519
|
-
:
|
2815
|
+
:tQSYMBOLS_BEG, "%i[", EXPR_BEG,
|
2520
2816
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2521
|
-
:tSPACE,
|
2817
|
+
:tSPACE, " ", EXPR_BEG,
|
2522
2818
|
:tSTRING_CONTENT, "s2", EXPR_BEG,
|
2523
|
-
:tSPACE,
|
2819
|
+
:tSPACE, " ", EXPR_BEG,
|
2524
2820
|
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2525
|
-
:tSPACE,
|
2526
|
-
:tSTRING_END,
|
2821
|
+
:tSPACE, "]", EXPR_BEG,
|
2822
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2527
2823
|
end
|
2528
2824
|
|
2529
|
-
def
|
2530
|
-
assert_lex3("%
|
2825
|
+
def test_yylex_string_pct_other
|
2826
|
+
assert_lex3("%%blah%",
|
2531
2827
|
nil,
|
2532
|
-
:tSTRING_BEG, "
|
2533
|
-
:tSTRING_CONTENT, "
|
2534
|
-
:tSTRING_END, "
|
2828
|
+
:tSTRING_BEG, "%%", EXPR_BEG,
|
2829
|
+
:tSTRING_CONTENT, "blah", EXPR_BEG,
|
2830
|
+
:tSTRING_END, "%", EXPR_LIT)
|
2535
2831
|
end
|
2536
2832
|
|
2537
|
-
def
|
2538
|
-
assert_lex3("%
|
2833
|
+
def test_yylex_string_pct_q
|
2834
|
+
assert_lex3("%q[s1 s2]",
|
2539
2835
|
nil,
|
2540
|
-
:tSTRING_BEG, "%
|
2836
|
+
:tSTRING_BEG, "%q[", EXPR_BEG,
|
2541
2837
|
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2542
|
-
:tSTRING_END, "]",
|
2838
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2543
2839
|
end
|
2544
2840
|
|
2545
2841
|
def test_yylex_string_pct_s
|
@@ -2547,109 +2843,160 @@ class TestRubyLexer < Minitest::Test
|
|
2547
2843
|
nil,
|
2548
2844
|
:tSYMBEG, "%s[", EXPR_FNAME, # TODO: :tSYM_BEG ?
|
2549
2845
|
:tSTRING_CONTENT, "s1 s2", EXPR_FNAME, # man... I don't like this
|
2550
|
-
:tSTRING_END, "]",
|
2846
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2551
2847
|
end
|
2552
2848
|
|
2553
|
-
def
|
2554
|
-
|
2849
|
+
def test_yylex_string_pct_w
|
2850
|
+
refute_lex("%w[s1 s2 ",
|
2851
|
+
:tQWORDS_BEG, "%w[",
|
2852
|
+
:tSTRING_CONTENT, "s1",
|
2853
|
+
:tSPACE, " ",
|
2854
|
+
:tSTRING_CONTENT, "s2",
|
2855
|
+
:tSPACE, " ")
|
2856
|
+
end
|
2857
|
+
|
2858
|
+
def test_yylex_string_pct_w_bs_nl
|
2859
|
+
assert_lex3("%w[s1 \\\ns2]",
|
2555
2860
|
nil,
|
2556
|
-
:
|
2557
|
-
:tSTRING_CONTENT, "s1",
|
2558
|
-
:tSPACE,
|
2559
|
-
:tSTRING_CONTENT, "
|
2560
|
-
:tSPACE,
|
2561
|
-
:
|
2562
|
-
|
2563
|
-
|
2861
|
+
:tQWORDS_BEG, "%w[", EXPR_BEG,
|
2862
|
+
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2863
|
+
:tSPACE, " ", EXPR_BEG,
|
2864
|
+
:tSTRING_CONTENT, "\ns2", EXPR_BEG,
|
2865
|
+
:tSPACE, "]", EXPR_BEG,
|
2866
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2867
|
+
end
|
2868
|
+
|
2869
|
+
def test_yylex_string_pct_w_bs_sp
|
2870
|
+
assert_lex3("%w[s\\ 1 s\\ 2]",
|
2871
|
+
s(:array, s(:str, "s 1"), s(:str, "s 2")),
|
2872
|
+
:tQWORDS_BEG, "%w[", EXPR_BEG,
|
2873
|
+
:tSTRING_CONTENT, "s 1", EXPR_BEG,
|
2874
|
+
:tSPACE, " ", EXPR_BEG,
|
2875
|
+
:tSTRING_CONTENT, "s 2", EXPR_BEG,
|
2876
|
+
:tSPACE, "]", EXPR_BEG,
|
2877
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2878
|
+
end
|
2879
|
+
|
2880
|
+
def test_yylex_string_single
|
2881
|
+
assert_lex3("'string'", nil, :tSTRING, "string", EXPR_END)
|
2882
|
+
end
|
2883
|
+
|
2884
|
+
def test_yylex_string_single_escape_chars
|
2885
|
+
assert_lex3("'s\\tri\\ng'", nil, :tSTRING, "s\\tri\\ng", EXPR_END)
|
2886
|
+
end
|
2887
|
+
|
2888
|
+
def test_yylex_string_single_escape_quote_and_backslash
|
2889
|
+
assert_lex3(":'foo\\'bar\\\\baz'", nil, :tSYMBOL, "foo'bar\\baz",
|
2890
|
+
EXPR_LIT)
|
2891
|
+
end
|
2892
|
+
|
2893
|
+
def test_yylex_string_single_escaped_quote
|
2894
|
+
assert_lex3("'foo\\'bar'", nil, :tSTRING, "foo'bar", EXPR_END)
|
2564
2895
|
end
|
2565
2896
|
|
2566
|
-
def
|
2567
|
-
assert_lex3("
|
2568
|
-
|
2569
|
-
|
2570
|
-
|
2571
|
-
|
2572
|
-
|
2573
|
-
|
2574
|
-
:
|
2897
|
+
def test_yylex_string_single_nl
|
2898
|
+
assert_lex3("'blah\\\nblah'", nil, :tSTRING, "blah\\\nblah", EXPR_END)
|
2899
|
+
end
|
2900
|
+
|
2901
|
+
def test_yylex_string_utf8_complex
|
2902
|
+
chr = [0x3024].pack("U")
|
2903
|
+
|
2904
|
+
assert_lex3('"#@a\u{3024}"',
|
2905
|
+
s(:dstr, "", s(:evstr, s(:ivar, :@a)), s(:str, chr)),
|
2906
|
+
:tSTRING_BEG, '"', EXPR_BEG,
|
2907
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
2908
|
+
:tSTRING_CONTENT, "@a"+chr, EXPR_BEG,
|
2909
|
+
:tSTRING_END, '"', EXPR_LIT)
|
2910
|
+
end
|
2911
|
+
|
2912
|
+
def test_yylex_string_utf8_complex_missing_hex
|
2913
|
+
chr = [0x302].pack("U")
|
2914
|
+
str = "#{chr}zzz"
|
2915
|
+
|
2916
|
+
refute_lex('"#@a\u302zzz"',
|
2917
|
+
:tSTRING_BEG, '"',
|
2918
|
+
:tSTRING_DVAR, "#",
|
2919
|
+
:tSTRING_CONTENT, "@a"+str,
|
2920
|
+
:tSTRING_END, '"')
|
2921
|
+
|
2922
|
+
chr = [0x30].pack("U")
|
2923
|
+
str = "#{chr}zzz"
|
2924
|
+
|
2925
|
+
refute_lex('"#@a\u30zzz"',
|
2926
|
+
:tSTRING_BEG, '"',
|
2927
|
+
:tSTRING_DVAR, "#",
|
2928
|
+
:tSTRING_CONTENT, "@a"+str,
|
2929
|
+
:tSTRING_END, '"')
|
2930
|
+
|
2931
|
+
chr = [0x3].pack("U")
|
2932
|
+
str = "#{chr}zzz"
|
2933
|
+
|
2934
|
+
refute_lex('"#@a\u3zzz"',
|
2935
|
+
:tSTRING_BEG, '"',
|
2936
|
+
:tSTRING_DVAR, "#",
|
2937
|
+
:tSTRING_CONTENT, "@a"+str,
|
2938
|
+
:tSTRING_END, '"')
|
2575
2939
|
end
|
2576
2940
|
|
2577
|
-
def
|
2578
|
-
|
2579
|
-
|
2580
|
-
:tSTRING_BEG, "%>", EXPR_BEG,
|
2581
|
-
:tSTRING_CONTENT, "blah", EXPR_BEG,
|
2582
|
-
:tSTRING_END, ">", EXPR_END)
|
2583
|
-
end
|
2941
|
+
def test_yylex_string_utf8_bad_encoding_with_escapes
|
2942
|
+
str = "\"\\xBADπ\""
|
2943
|
+
exp = "\xBADπ".b
|
2584
2944
|
|
2585
|
-
|
2586
|
-
|
2587
|
-
|
2588
|
-
:tSTRING_BEG, "%%", EXPR_BEG,
|
2589
|
-
:tSTRING_CONTENT, "blah", EXPR_BEG,
|
2590
|
-
:tSTRING_END, "%", EXPR_END)
|
2945
|
+
assert_lex(str,
|
2946
|
+
s(:str, exp),
|
2947
|
+
:tSTRING, exp, EXPR_END)
|
2591
2948
|
end
|
2592
2949
|
|
2593
|
-
def
|
2594
|
-
|
2595
|
-
|
2596
|
-
:tSTRING_CONTENT, "s1",
|
2597
|
-
:tSPACE, nil,
|
2598
|
-
:tSTRING_CONTENT, "s2",
|
2599
|
-
:tSPACE, nil)
|
2600
|
-
end
|
2950
|
+
def test_yylex_string_utf8_complex_trailing_hex
|
2951
|
+
chr = [0x3024].pack("U")
|
2952
|
+
str = "#{chr}abz"
|
2601
2953
|
|
2602
|
-
|
2603
|
-
|
2604
|
-
|
2605
|
-
:
|
2606
|
-
:tSTRING_CONTENT, "
|
2607
|
-
:
|
2608
|
-
:tSTRING_CONTENT, "\ns2", EXPR_BEG,
|
2609
|
-
:tSPACE, nil, EXPR_BEG,
|
2610
|
-
:tSTRING_END, nil, EXPR_END)
|
2954
|
+
assert_lex3('"#@a\u3024abz"',
|
2955
|
+
s(:dstr, "", s(:evstr, s(:ivar, :@a)), s(:str, str)),
|
2956
|
+
:tSTRING_BEG, '"', EXPR_BEG,
|
2957
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
2958
|
+
:tSTRING_CONTENT, "@a"+str, EXPR_BEG,
|
2959
|
+
:tSTRING_END, '"', EXPR_LIT)
|
2611
2960
|
end
|
2612
2961
|
|
2613
|
-
def
|
2614
|
-
|
2615
|
-
|
2616
|
-
|
2617
|
-
:tSTRING_CONTENT, "s 1", EXPR_BEG,
|
2618
|
-
:tSPACE, nil, EXPR_BEG,
|
2619
|
-
:tSTRING_CONTENT, "s 2", EXPR_BEG,
|
2620
|
-
:tSPACE, nil, EXPR_BEG,
|
2621
|
-
:tSTRING_END, nil, EXPR_END)
|
2962
|
+
def test_yylex_string_utf8_missing_hex
|
2963
|
+
refute_lex('"\u3zzz"')
|
2964
|
+
refute_lex('"\u30zzz"')
|
2965
|
+
refute_lex('"\u302zzz"')
|
2622
2966
|
end
|
2623
2967
|
|
2624
|
-
def
|
2625
|
-
|
2626
|
-
end
|
2968
|
+
def test_yylex_string_utf8_simple
|
2969
|
+
chr = [0x3024].pack("U")
|
2627
2970
|
|
2628
|
-
|
2629
|
-
|
2971
|
+
assert_lex3('"\u{3024}"',
|
2972
|
+
s(:str, chr),
|
2973
|
+
:tSTRING, chr, EXPR_END)
|
2630
2974
|
end
|
2631
2975
|
|
2632
|
-
def
|
2633
|
-
|
2634
|
-
|
2976
|
+
def test_yylex_string_utf8_trailing_hex
|
2977
|
+
chr = [0x3024].pack("U")
|
2978
|
+
str = "#{chr}abz"
|
2635
2979
|
|
2636
|
-
|
2637
|
-
|
2980
|
+
assert_lex3('"\u3024abz"',
|
2981
|
+
s(:str, str),
|
2982
|
+
:tSTRING, str, EXPR_END)
|
2638
2983
|
end
|
2639
2984
|
|
2640
|
-
def
|
2641
|
-
|
2985
|
+
def test_yylex_sym_quoted
|
2986
|
+
assert_lex(":'a'",
|
2987
|
+
s(:lit, :a),
|
2988
|
+
|
2989
|
+
:tSYMBOL, "a", EXPR_LIT, 0, 0)
|
2642
2990
|
end
|
2643
2991
|
|
2644
|
-
def
|
2645
|
-
|
2646
|
-
:tSYMBOL, "symbol\0", EXPR_END)
|
2992
|
+
def test_yylex_symbol
|
2993
|
+
assert_lex3(":symbol", nil, :tSYMBOL, "symbol", EXPR_LIT)
|
2647
2994
|
end
|
2648
2995
|
|
2649
2996
|
def test_yylex_symbol_double
|
2650
2997
|
assert_lex3(":\"symbol\"",
|
2651
2998
|
nil,
|
2652
|
-
:tSYMBOL,
|
2999
|
+
:tSYMBOL, "symbol", EXPR_LIT)
|
2653
3000
|
end
|
2654
3001
|
|
2655
3002
|
def test_yylex_symbol_double_interp
|
@@ -2657,31 +3004,45 @@ class TestRubyLexer < Minitest::Test
|
|
2657
3004
|
nil,
|
2658
3005
|
:tSYMBEG, ":", EXPR_FNAME,
|
2659
3006
|
:tSTRING_CONTENT, "symbol", EXPR_FNAME,
|
2660
|
-
:tSTRING_DBEG,
|
3007
|
+
:tSTRING_DBEG, '#{', EXPR_FNAME,
|
2661
3008
|
:tSTRING_CONTENT, "1+1}", EXPR_FNAME, # HUH? this is BS
|
2662
|
-
:tSTRING_END, "\"",
|
3009
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
3010
|
+
end
|
3011
|
+
|
3012
|
+
def test_yylex_symbol_double_escape_octal
|
3013
|
+
setup_lexer ":\"Variet\\303\\240\""
|
3014
|
+
|
3015
|
+
adv = @lex.next_token
|
3016
|
+
act_token, act_value = adv
|
3017
|
+
act_value = act_value.first
|
3018
|
+
|
3019
|
+
assert_equal :tSYMBOL, act_token
|
3020
|
+
assert_match EXPR_LIT, @lex.lex_state
|
3021
|
+
# Force comparison of encodings
|
3022
|
+
assert_equal "Varietà", act_value
|
2663
3023
|
end
|
2664
3024
|
|
2665
3025
|
def test_yylex_symbol_single
|
2666
3026
|
assert_lex3(":'symbol'",
|
2667
3027
|
nil,
|
2668
|
-
:tSYMBOL,
|
3028
|
+
:tSYMBOL, "symbol", EXPR_LIT)
|
2669
3029
|
end
|
2670
3030
|
|
2671
|
-
def
|
2672
|
-
assert_lex3('
|
3031
|
+
def test_yylex_symbol_single_escape_chars
|
3032
|
+
assert_lex3(":'s\\tri\\ng'",
|
2673
3033
|
nil,
|
2674
|
-
:tSYMBOL,
|
3034
|
+
:tSYMBOL, "s\\tri\\ng", EXPR_LIT)
|
2675
3035
|
end
|
2676
3036
|
|
2677
|
-
def
|
2678
|
-
assert_lex3(
|
3037
|
+
def test_yylex_symbol_single_noninterp
|
3038
|
+
assert_lex3(':\'symbol#{1+1}\'',
|
2679
3039
|
nil,
|
2680
|
-
:tSYMBOL,
|
3040
|
+
:tSYMBOL, 'symbol#{1+1}', EXPR_LIT)
|
2681
3041
|
end
|
2682
3042
|
|
2683
|
-
def
|
2684
|
-
|
3043
|
+
def test_yylex_symbol_zero_byte
|
3044
|
+
assert_lex(":\"symbol\0\"", nil,
|
3045
|
+
:tSYMBOL, "symbol\0", EXPR_LIT)
|
2685
3046
|
end
|
2686
3047
|
|
2687
3048
|
def test_yylex_ternary1
|
@@ -2703,7 +3064,7 @@ class TestRubyLexer < Minitest::Test
|
|
2703
3064
|
|
2704
3065
|
assert_lex3("42 ?",
|
2705
3066
|
nil,
|
2706
|
-
:tINTEGER, 42,
|
3067
|
+
:tINTEGER, 42, EXPR_NUM,
|
2707
3068
|
:tEH, "?", EXPR_BEG)
|
2708
3069
|
end
|
2709
3070
|
|
@@ -2746,14 +3107,14 @@ class TestRubyLexer < Minitest::Test
|
|
2746
3107
|
nil,
|
2747
3108
|
:kDEF, "def", EXPR_FNAME,
|
2748
3109
|
:tIDENTIFIER, "initialize", EXPR_ENDFN,
|
2749
|
-
:tLPAREN2, "(",
|
3110
|
+
:tLPAREN2, "(", EXPR_PAR,
|
2750
3111
|
:tIDENTIFIER, "u", EXPR_ARG,
|
2751
3112
|
:tEQL, "=", EXPR_BEG,
|
2752
|
-
:tFLOAT, 0.0,
|
2753
|
-
:tCOMMA, ",",
|
3113
|
+
:tFLOAT, 0.0, EXPR_NUM,
|
3114
|
+
:tCOMMA, ",", EXPR_PAR,
|
2754
3115
|
:tIDENTIFIER, "s", EXPR_ARG,
|
2755
3116
|
:tEQL, "=", EXPR_BEG,
|
2756
|
-
:tFLOAT, 0.0,
|
3117
|
+
:tFLOAT, 0.0, EXPR_NUM)
|
2757
3118
|
end
|
2758
3119
|
|
2759
3120
|
def test_zbug_id_equals
|
@@ -2761,7 +3122,7 @@ class TestRubyLexer < Minitest::Test
|
|
2761
3122
|
nil,
|
2762
3123
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
2763
3124
|
:tEQL, "=", EXPR_BEG,
|
2764
|
-
:tFLOAT, 0.0,
|
3125
|
+
:tFLOAT, 0.0, EXPR_NUM)
|
2765
3126
|
end
|
2766
3127
|
|
2767
3128
|
def test_zbug_no_spaces_in_decl
|
@@ -2769,190 +3130,13 @@ class TestRubyLexer < Minitest::Test
|
|
2769
3130
|
nil,
|
2770
3131
|
:kDEF, "def", EXPR_FNAME,
|
2771
3132
|
:tIDENTIFIER, "initialize", EXPR_ENDFN,
|
2772
|
-
:tLPAREN2, "(",
|
3133
|
+
:tLPAREN2, "(", EXPR_PAR,
|
2773
3134
|
:tIDENTIFIER, "u", EXPR_ARG,
|
2774
3135
|
:tEQL, "=", EXPR_BEG,
|
2775
|
-
:tFLOAT, 0.0,
|
2776
|
-
:tCOMMA, ",",
|
3136
|
+
:tFLOAT, 0.0, EXPR_NUM,
|
3137
|
+
:tCOMMA, ",", EXPR_PAR,
|
2777
3138
|
:tIDENTIFIER, "s", EXPR_ARG,
|
2778
3139
|
:tEQL, "=", EXPR_BEG,
|
2779
|
-
:tFLOAT, 0.0,
|
2780
|
-
end
|
2781
|
-
|
2782
|
-
def test_pct_w_backslashes
|
2783
|
-
["\t", "\n", "\r", "\v", "\f"].each do |char|
|
2784
|
-
next if !RubyLexer::HAS_ENC and char == "\v"
|
2785
|
-
|
2786
|
-
assert_lex("%w[foo#{char}bar]",
|
2787
|
-
s(:array, s(:str, "foo"), s(:str, "bar")),
|
2788
|
-
|
2789
|
-
:tQWORDS_BEG, "%w[", EXPR_BEG, 0, 0,
|
2790
|
-
:tSTRING_CONTENT, "foo", EXPR_BEG, 0, 0,
|
2791
|
-
:tSPACE, nil, EXPR_BEG, 0, 0,
|
2792
|
-
:tSTRING_CONTENT, "bar", EXPR_BEG, 0, 0,
|
2793
|
-
:tSPACE, nil, EXPR_BEG, 0, 0,
|
2794
|
-
:tSTRING_END, nil, EXPR_END, 0, 0)
|
2795
|
-
end
|
2796
|
-
end
|
2797
|
-
|
2798
|
-
def test_yylex_sym_quoted
|
2799
|
-
assert_lex(":'a'",
|
2800
|
-
s(:lit, :a),
|
2801
|
-
|
2802
|
-
:tSYMBOL, "a", EXPR_END, 0, 0)
|
2803
|
-
end
|
2804
|
-
|
2805
|
-
def test_yylex_hash_colon
|
2806
|
-
assert_lex("{a:1}",
|
2807
|
-
s(:hash, s(:lit, :a), s(:lit, 1)),
|
2808
|
-
|
2809
|
-
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
2810
|
-
:tLABEL, "a", EXPR_LAB, 0, 1,
|
2811
|
-
:tINTEGER, 1, EXPR_NUM, 0, 1,
|
2812
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
2813
|
-
end
|
2814
|
-
|
2815
|
-
def test_yylex_hash_colon_quoted_22
|
2816
|
-
setup_lexer_class RubyParser::V22
|
2817
|
-
|
2818
|
-
assert_lex("{'a':1}",
|
2819
|
-
s(:hash, s(:lit, :a), s(:lit, 1)),
|
2820
|
-
|
2821
|
-
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
2822
|
-
:tLABEL, "a", EXPR_LAB, 0, 1,
|
2823
|
-
:tINTEGER, 1, EXPR_NUM, 0, 1,
|
2824
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
2825
|
-
end
|
2826
|
-
|
2827
|
-
def test_yylex_hash_colon_quoted_symbol_22
|
2828
|
-
setup_lexer_class RubyParser::V22
|
2829
|
-
|
2830
|
-
assert_lex("{'abc': :b}",
|
2831
|
-
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
2832
|
-
|
2833
|
-
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
2834
|
-
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
2835
|
-
:tSYMBOL, "b", EXPR_END, 0, 1,
|
2836
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
2837
|
-
end
|
2838
|
-
|
2839
|
-
def test_yylex_hash_colon_double_quoted_symbol_22
|
2840
|
-
setup_lexer_class RubyParser::V22
|
2841
|
-
|
2842
|
-
assert_lex('{"abc": :b}',
|
2843
|
-
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
2844
|
-
|
2845
|
-
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
2846
|
-
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
2847
|
-
:tSYMBOL, "b", EXPR_END, 0, 1,
|
2848
|
-
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
2849
|
-
end
|
2850
|
-
|
2851
|
-
def test_yylex_required_kwarg_no_value_22
|
2852
|
-
setup_lexer_class RubyParser::V22
|
2853
|
-
|
2854
|
-
assert_lex3("def foo a:, b:\nend",
|
2855
|
-
nil,
|
2856
|
-
:kDEF, "def", EXPR_FNAME,
|
2857
|
-
:tIDENTIFIER, "foo", EXPR_ENDFN,
|
2858
|
-
:tLABEL, "a", EXPR_LAB,
|
2859
|
-
:tCOMMA, ",", EXPR_PAR,
|
2860
|
-
:tLABEL, "b", EXPR_LAB,
|
2861
|
-
:kEND, "end", EXPR_END)
|
2862
|
-
end
|
2863
|
-
|
2864
|
-
def test_yylex_hash_colon_double_quoted_with_escapes
|
2865
|
-
setup_lexer_class RubyParser::V22
|
2866
|
-
|
2867
|
-
assert_lex3("{\"s\\tr\\i\\ng\\\\foo\\'bar\":1}",
|
2868
|
-
nil,
|
2869
|
-
|
2870
|
-
:tLBRACE, "{", EXPR_PAR,
|
2871
|
-
:tLABEL, "s\tr\i\ng\\foo'bar", EXPR_LAB,
|
2872
|
-
:tINTEGER, 1, EXPR_NUM,
|
2873
|
-
:tRCURLY, "}", EXPR_ENDARG)
|
2874
|
-
end
|
2875
|
-
|
2876
|
-
def test_yylex_hash_colon_quoted_with_escapes
|
2877
|
-
setup_lexer_class RubyParser::V22
|
2878
|
-
|
2879
|
-
assert_lex3("{'s\\tr\\i\\ng\\\\foo\\'bar':1}",
|
2880
|
-
nil,
|
2881
|
-
|
2882
|
-
:tLBRACE, "{", EXPR_PAR,
|
2883
|
-
:tLABEL, "s\\tr\\i\\ng\\foo'bar", EXPR_LAB,
|
2884
|
-
:tINTEGER, 1, EXPR_NUM,
|
2885
|
-
:tRCURLY, "}", EXPR_ENDARG)
|
2886
|
-
end
|
2887
|
-
|
2888
|
-
def test_ruby21_rational_literal
|
2889
|
-
setup_lexer_class RubyParser::V21
|
2890
|
-
|
2891
|
-
assert_lex3("10r", nil, :tRATIONAL, Rational(10), EXPR_NUM)
|
2892
|
-
assert_lex3("0x10r", nil, :tRATIONAL, Rational(16), EXPR_NUM)
|
2893
|
-
assert_lex3("0o10r", nil, :tRATIONAL, Rational(8), EXPR_NUM)
|
2894
|
-
assert_lex3("0or", nil, :tRATIONAL, Rational(0), EXPR_NUM)
|
2895
|
-
assert_lex3("0b10r", nil, :tRATIONAL, Rational(2), EXPR_NUM)
|
2896
|
-
assert_lex3("1.5r", nil, :tRATIONAL, Rational(15, 10), EXPR_NUM)
|
2897
|
-
assert_lex3("15e3r", nil, :tRATIONAL, Rational(15000), EXPR_NUM)
|
2898
|
-
assert_lex3("15e-3r", nil, :tRATIONAL, Rational(15, 1000), EXPR_NUM)
|
2899
|
-
assert_lex3("1.5e3r", nil, :tRATIONAL, Rational(1500), EXPR_NUM)
|
2900
|
-
assert_lex3("1.5e-3r", nil, :tRATIONAL, Rational(15, 10000), EXPR_NUM)
|
2901
|
-
|
2902
|
-
assert_lex3("-10r", nil,
|
2903
|
-
:tUMINUS_NUM, "-", EXPR_BEG,
|
2904
|
-
:tRATIONAL, Rational(10), EXPR_NUM)
|
2905
|
-
end
|
2906
|
-
|
2907
|
-
def test_ruby21_imaginary_literal
|
2908
|
-
setup_lexer_class RubyParser::V21
|
2909
|
-
|
2910
|
-
assert_lex3("1i", nil, :tIMAGINARY, Complex(0, 1), EXPR_NUM)
|
2911
|
-
assert_lex3("0x10i", nil, :tIMAGINARY, Complex(0, 16), EXPR_NUM)
|
2912
|
-
assert_lex3("0o10i", nil, :tIMAGINARY, Complex(0, 8), EXPR_NUM)
|
2913
|
-
assert_lex3("0oi", nil, :tIMAGINARY, Complex(0, 0), EXPR_NUM)
|
2914
|
-
assert_lex3("0b10i", nil, :tIMAGINARY, Complex(0, 2), EXPR_NUM)
|
2915
|
-
assert_lex3("1.5i", nil, :tIMAGINARY, Complex(0, 1.5), EXPR_NUM)
|
2916
|
-
assert_lex3("15e3i", nil, :tIMAGINARY, Complex(0, 15000), EXPR_NUM)
|
2917
|
-
assert_lex3("15e-3i", nil, :tIMAGINARY, Complex(0, 0.015), EXPR_NUM)
|
2918
|
-
assert_lex3("1.5e3i", nil, :tIMAGINARY, Complex(0, 1500), EXPR_NUM)
|
2919
|
-
assert_lex3("1.5e-3i", nil, :tIMAGINARY, Complex(0, 0.0015), EXPR_NUM)
|
2920
|
-
|
2921
|
-
assert_lex3("-10i", nil,
|
2922
|
-
:tUMINUS_NUM, "-", EXPR_BEG,
|
2923
|
-
:tIMAGINARY, Complex(0, 10), EXPR_NUM)
|
2924
|
-
end
|
2925
|
-
|
2926
|
-
def test_ruby21_rational_imaginary_literal
|
2927
|
-
setup_lexer_class RubyParser::V21
|
2928
|
-
|
2929
|
-
assert_lex3 "1ri", nil, :tIMAGINARY, Complex(0, Rational(1)), EXPR_NUM
|
2930
|
-
assert_lex3 "0x10ri", nil, :tIMAGINARY, Complex(0, Rational(16)), EXPR_NUM
|
2931
|
-
assert_lex3 "0o10ri", nil, :tIMAGINARY, Complex(0, Rational(8)), EXPR_NUM
|
2932
|
-
assert_lex3 "0ori", nil, :tIMAGINARY, Complex(0, Rational(0)), EXPR_NUM
|
2933
|
-
assert_lex3 "0b10ri", nil, :tIMAGINARY, Complex(0, Rational(2)), EXPR_NUM
|
2934
|
-
assert_lex3 "1.5ri", nil, :tIMAGINARY, Complex(0, Rational("1.5")), EXPR_NUM
|
2935
|
-
assert_lex3 "15e3ri", nil, :tIMAGINARY, Complex(0, Rational("15e3")), EXPR_NUM
|
2936
|
-
assert_lex3 "15e-3ri", nil, :tIMAGINARY, Complex(0, Rational("15e-3")), EXPR_NUM
|
2937
|
-
assert_lex3 "1.5e3ri", nil, :tIMAGINARY, Complex(0, Rational("1.5e3")), EXPR_NUM
|
2938
|
-
assert_lex3 "1.5e-3ri", nil, :tIMAGINARY, Complex(0, Rational("1.5e-3")), EXPR_NUM
|
2939
|
-
|
2940
|
-
assert_lex3("-10ri", nil,
|
2941
|
-
:tUMINUS_NUM, "-", EXPR_BEG,
|
2942
|
-
:tIMAGINARY, Complex(0, Rational(10)), EXPR_NUM)
|
2943
|
-
end
|
2944
|
-
|
2945
|
-
def test_ruby21_imaginary_literal_with_succeeding_keyword
|
2946
|
-
setup_lexer_class RubyParser::V21
|
2947
|
-
|
2948
|
-
# 2/4 scenarios are syntax errors on all tested versions so I
|
2949
|
-
# deleted them.
|
2950
|
-
|
2951
|
-
assert_lex3("1if", nil,
|
2952
|
-
:tINTEGER, 1, EXPR_NUM,
|
2953
|
-
:kIF_MOD, "if", EXPR_PAR)
|
2954
|
-
assert_lex3("1.0if", nil,
|
2955
|
-
:tFLOAT, 1.0, EXPR_NUM,
|
2956
|
-
:kIF_MOD, "if", EXPR_PAR)
|
3140
|
+
:tFLOAT, 0.0, EXPR_NUM)
|
2957
3141
|
end
|
2958
3142
|
end
|