ruby_parser 3.13.1 → 3.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.autotest +18 -29
- data/History.rdoc +97 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +3 -3
- data/Rakefile +39 -21
- data/bin/ruby_parse +3 -1
- data/bin/ruby_parse_extract_error +8 -3
- data/compare/normalize.rb +43 -3
- data/debugging.md +39 -0
- data/lib/ruby20_parser.rb +3431 -3238
- data/lib/ruby20_parser.y +474 -300
- data/lib/ruby21_parser.rb +3491 -3295
- data/lib/ruby21_parser.y +482 -307
- data/lib/ruby22_parser.rb +3432 -3240
- data/lib/ruby22_parser.y +483 -308
- data/lib/ruby23_parser.rb +3338 -3150
- data/lib/ruby23_parser.y +483 -308
- data/lib/ruby24_parser.rb +3483 -3273
- data/lib/ruby24_parser.y +487 -310
- data/lib/ruby25_parser.rb +3482 -3272
- data/lib/ruby25_parser.y +487 -310
- data/lib/ruby26_parser.rb +3490 -3278
- data/lib/ruby26_parser.y +493 -314
- data/lib/ruby27_parser.rb +7224 -0
- data/lib/ruby27_parser.y +2657 -0
- data/lib/ruby_lexer.rb +483 -459
- data/lib/ruby_lexer.rex +5 -6
- data/lib/ruby_lexer.rex.rb +6 -8
- data/lib/ruby_parser.rb +29 -27
- data/lib/ruby_parser.yy +497 -315
- data/lib/ruby_parser_extras.rb +670 -420
- data/test/test_ruby_lexer.rb +1208 -1121
- data/test/test_ruby_parser.rb +2517 -1955
- data/test/test_ruby_parser_extras.rb +39 -4
- data/tools/munge.rb +10 -5
- data/tools/ripper.rb +13 -2
- metadata +28 -21
- metadata.gz.sig +0 -0
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
|
@@ -54,14 +51,6 @@ class TestRubyLexer < Minitest::Test
|
|
54
51
|
assert_lex(input, exp_sexp, *args, &block)
|
55
52
|
end
|
56
53
|
|
57
|
-
def refute_lex input, *args # TODO: re-sort
|
58
|
-
args = args.each_slice(2).map { |a, b| [a, b, nil, nil, nil] }.flatten
|
59
|
-
|
60
|
-
assert_raises RubyParser::SyntaxError do
|
61
|
-
assert_lex(input, nil, *args)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
54
|
def assert_lex_fname name, type, end_state = EXPR_ARG # TODO: swap name/type
|
66
55
|
assert_lex3("def #{name} ",
|
67
56
|
nil,
|
@@ -73,29 +62,30 @@ class TestRubyLexer < Minitest::Test
|
|
73
62
|
def assert_next_lexeme token=nil, value=nil, state=nil, paren=nil, brace=nil
|
74
63
|
adv = @lex.next_token
|
75
64
|
|
76
|
-
assert adv, "no more tokens"
|
65
|
+
assert adv, "no more tokens, expecting: %p %p %p %p %p" % [token, value, state, paren, brace]
|
77
66
|
|
78
67
|
act_token, act_value = adv
|
79
68
|
|
80
69
|
msg = message {
|
81
|
-
act = [act_token, act_value, @lex.lex_state,
|
82
|
-
@lex.paren_nest, @lex.brace_nest]
|
70
|
+
act = [act_token, act_value, @lex.lex_state, @lex.paren_nest, @lex.brace_nest]
|
83
71
|
exp = [token, value, state, paren, brace]
|
84
72
|
"#{exp.inspect} vs #{act.inspect}"
|
85
73
|
}
|
86
74
|
|
87
75
|
act_value = act_value.first if Array === act_value
|
88
76
|
|
89
|
-
assert_equal token, act_token,
|
77
|
+
assert_equal token, act_token, msg
|
90
78
|
case value
|
91
79
|
when Float then
|
92
80
|
assert_in_epsilon value, act_value, 0.001, msg
|
93
81
|
when NilClass then
|
94
82
|
assert_nil act_value, msg
|
83
|
+
when String then
|
84
|
+
assert_equal value, act_value.b.force_encoding(value.encoding), msg
|
95
85
|
else
|
96
|
-
assert_equal value, act_value,
|
86
|
+
assert_equal value, act_value, msg
|
97
87
|
end
|
98
|
-
|
88
|
+
assert_match state, @lex.lex_state, msg if state
|
99
89
|
assert_equal paren, @lex.paren_nest, msg if paren
|
100
90
|
assert_equal brace, @lex.brace_nest, msg if brace
|
101
91
|
end
|
@@ -106,7 +96,8 @@ class TestRubyLexer < Minitest::Test
|
|
106
96
|
|
107
97
|
def assert_read_escape expected, input
|
108
98
|
@lex.ss.string = input.dup
|
109
|
-
|
99
|
+
enc = expected.encoding
|
100
|
+
assert_equal expected, @lex.read_escape.b.force_encoding(enc), input
|
110
101
|
end
|
111
102
|
|
112
103
|
def assert_read_escape_bad input # TODO: rename refute_read_escape
|
@@ -116,6 +107,20 @@ class TestRubyLexer < Minitest::Test
|
|
116
107
|
end
|
117
108
|
end
|
118
109
|
|
110
|
+
def refute_lex input, *args # TODO: re-sort
|
111
|
+
args = args.each_slice(2).map { |a, b| [a, b, nil, nil, nil] }.flatten
|
112
|
+
|
113
|
+
assert_raises RubyParser::SyntaxError do
|
114
|
+
assert_lex(input, nil, *args)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def refute_lex5 input, *args
|
119
|
+
assert_raises RubyParser::SyntaxError do
|
120
|
+
assert_lex(input, *args)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
119
124
|
def refute_lexeme
|
120
125
|
x = y = @lex.next_token
|
121
126
|
|
@@ -140,7 +145,7 @@ class TestRubyLexer < Minitest::Test
|
|
140
145
|
yield
|
141
146
|
|
142
147
|
lexer.lex_state = EXPR_ENDARG
|
143
|
-
assert_next_lexeme :tSTRING_DEND, "}",
|
148
|
+
assert_next_lexeme :tSTRING_DEND, "}", EXPR_END|EXPR_ENDARG, 0
|
144
149
|
|
145
150
|
lexer.lex_strterm = lex_strterm
|
146
151
|
lexer.lex_state = EXPR_BEG
|
@@ -159,9 +164,20 @@ class TestRubyLexer < Minitest::Test
|
|
159
164
|
assert_nil @lex.next_token
|
160
165
|
end
|
161
166
|
|
162
|
-
def
|
163
|
-
|
164
|
-
|
167
|
+
def test_pct_w_backslashes
|
168
|
+
["\t", "\n", "\r", "\v", "\f"].each do |char|
|
169
|
+
next if !RubyLexer::HAS_ENC and char == "\v"
|
170
|
+
|
171
|
+
assert_lex("%w[foo#{char}bar]",
|
172
|
+
s(:array, s(:str, "foo"), s(:str, "bar")),
|
173
|
+
|
174
|
+
:tQWORDS_BEG, "%w[", EXPR_BEG, 0, 0,
|
175
|
+
:tSTRING_CONTENT, "foo", EXPR_BEG, 0, 0,
|
176
|
+
:tSPACE, nil, EXPR_BEG, 0, 0,
|
177
|
+
:tSTRING_CONTENT, "bar", EXPR_BEG, 0, 0,
|
178
|
+
:tSPACE, nil, EXPR_BEG, 0, 0,
|
179
|
+
:tSTRING_END, nil, EXPR_LIT, 0, 0)
|
180
|
+
end
|
165
181
|
end
|
166
182
|
|
167
183
|
def test_read_escape
|
@@ -217,6 +233,90 @@ class TestRubyLexer < Minitest::Test
|
|
217
233
|
assert_read_escape "\230", 'M-\cx'
|
218
234
|
end
|
219
235
|
|
236
|
+
def test_ruby21_imaginary_literal
|
237
|
+
setup_lexer_class RubyParser::V21
|
238
|
+
|
239
|
+
assert_lex3("1i", nil, :tIMAGINARY, Complex(0, 1), EXPR_NUM)
|
240
|
+
assert_lex3("0x10i", nil, :tIMAGINARY, Complex(0, 16), EXPR_NUM)
|
241
|
+
assert_lex3("0o10i", nil, :tIMAGINARY, Complex(0, 8), EXPR_NUM)
|
242
|
+
assert_lex3("0oi", nil, :tIMAGINARY, Complex(0, 0), EXPR_NUM)
|
243
|
+
assert_lex3("0b10i", nil, :tIMAGINARY, Complex(0, 2), EXPR_NUM)
|
244
|
+
assert_lex3("1.5i", nil, :tIMAGINARY, Complex(0, 1.5), EXPR_NUM)
|
245
|
+
assert_lex3("15e3i", nil, :tIMAGINARY, Complex(0, 15000), EXPR_NUM)
|
246
|
+
assert_lex3("15e-3i", nil, :tIMAGINARY, Complex(0, 0.015), EXPR_NUM)
|
247
|
+
assert_lex3("1.5e3i", nil, :tIMAGINARY, Complex(0, 1500), EXPR_NUM)
|
248
|
+
assert_lex3("1.5e-3i", nil, :tIMAGINARY, Complex(0, 0.0015), EXPR_NUM)
|
249
|
+
|
250
|
+
c010 = Complex(0, 10)
|
251
|
+
assert_lex3("-10i", nil,
|
252
|
+
:tUMINUS_NUM, "-", EXPR_BEG,
|
253
|
+
:tIMAGINARY, c010, EXPR_NUM)
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_ruby21_imaginary_literal_with_succeeding_keyword
|
257
|
+
setup_lexer_class RubyParser::V21
|
258
|
+
|
259
|
+
# 2/4 scenarios are syntax errors on all tested versions so I
|
260
|
+
# deleted them.
|
261
|
+
|
262
|
+
assert_lex3("1if", nil,
|
263
|
+
:tINTEGER, 1, EXPR_NUM,
|
264
|
+
:kIF_MOD, "if", EXPR_PAR)
|
265
|
+
assert_lex3("1.0if", nil,
|
266
|
+
:tFLOAT, 1.0, EXPR_NUM,
|
267
|
+
:kIF_MOD, "if", EXPR_PAR)
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_ruby21_rational_imaginary_literal
|
271
|
+
setup_lexer_class RubyParser::V21
|
272
|
+
|
273
|
+
assert_lex3 "1ri", nil, :tIMAGINARY, Complex(0, Rational(1)), EXPR_NUM
|
274
|
+
assert_lex3 "0x10ri", nil, :tIMAGINARY, Complex(0, Rational(16)), EXPR_NUM
|
275
|
+
assert_lex3 "0o10ri", nil, :tIMAGINARY, Complex(0, Rational(8)), EXPR_NUM
|
276
|
+
assert_lex3 "0ori", nil, :tIMAGINARY, Complex(0, Rational(0)), EXPR_NUM
|
277
|
+
assert_lex3 "0b10ri", nil, :tIMAGINARY, Complex(0, Rational(2)), EXPR_NUM
|
278
|
+
assert_lex3 "1.5ri", nil, :tIMAGINARY, Complex(0, Rational("1.5")), EXPR_NUM
|
279
|
+
assert_lex3 "15e3ri", nil, :tIMAGINARY, Complex(0, Rational("15e3")), EXPR_NUM
|
280
|
+
assert_lex3 "15e-3ri", nil, :tIMAGINARY, Complex(0, Rational("15e-3")), EXPR_NUM
|
281
|
+
assert_lex3 "1.5e3ri", nil, :tIMAGINARY, Complex(0, Rational("1.5e3")), EXPR_NUM
|
282
|
+
assert_lex3 "1.5e-3ri", nil, :tIMAGINARY, Complex(0, Rational("1.5e-3")), EXPR_NUM
|
283
|
+
|
284
|
+
assert_lex3("-10ri", nil,
|
285
|
+
:tUMINUS_NUM, "-", EXPR_BEG,
|
286
|
+
:tIMAGINARY, Complex(0, Rational(10)), EXPR_NUM)
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_ruby21_rational_literal
|
290
|
+
setup_lexer_class RubyParser::V21
|
291
|
+
|
292
|
+
assert_lex3("10r", nil, :tRATIONAL, Rational(10), EXPR_NUM)
|
293
|
+
assert_lex3("0x10r", nil, :tRATIONAL, Rational(16), EXPR_NUM)
|
294
|
+
assert_lex3("0o10r", nil, :tRATIONAL, Rational(8), EXPR_NUM)
|
295
|
+
assert_lex3("0or", nil, :tRATIONAL, Rational(0), EXPR_NUM)
|
296
|
+
assert_lex3("0b10r", nil, :tRATIONAL, Rational(2), EXPR_NUM)
|
297
|
+
assert_lex3("1.5r", nil, :tRATIONAL, Rational(15, 10), EXPR_NUM)
|
298
|
+
assert_lex3("15e3r", nil, :tRATIONAL, Rational(15000), EXPR_NUM)
|
299
|
+
assert_lex3("15e-3r", nil, :tRATIONAL, Rational(15, 1000), EXPR_NUM)
|
300
|
+
assert_lex3("1.5e3r", nil, :tRATIONAL, Rational(1500), EXPR_NUM)
|
301
|
+
assert_lex3("1.5e-3r", nil, :tRATIONAL, Rational(15, 10000), EXPR_NUM)
|
302
|
+
|
303
|
+
r10 = Rational(10)
|
304
|
+
assert_lex3("-10r", nil,
|
305
|
+
:tUMINUS_NUM, "-", EXPR_BEG,
|
306
|
+
:tRATIONAL, r10, EXPR_NUM)
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_unicode_ident
|
310
|
+
s = "@\u1088\u1077\u1093\u1072"
|
311
|
+
assert_lex3(s.dup, nil, :tIVAR, s.dup, EXPR_END)
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_why_does_ruby_hate_me?
|
315
|
+
assert_lex3("\"Nl%\\000\\000A\\000\\999\"", # you should be ashamed
|
316
|
+
nil,
|
317
|
+
:tSTRING, %W[ Nl% \u0000 \u0000 A \u0000 999 ].join, EXPR_END)
|
318
|
+
end
|
319
|
+
|
220
320
|
def test_yylex_ambiguous_uminus
|
221
321
|
assert_lex3("m -3",
|
222
322
|
nil,
|
@@ -248,6 +348,15 @@ class TestRubyLexer < Minitest::Test
|
|
248
348
|
assert_lex3("&&=", nil, :tOP_ASGN, "&&", EXPR_BEG)
|
249
349
|
end
|
250
350
|
|
351
|
+
def test_yylex_and_arg
|
352
|
+
self.lex_state = EXPR_ARG
|
353
|
+
|
354
|
+
assert_lex3(" &y",
|
355
|
+
nil,
|
356
|
+
:tAMPER, "&", EXPR_BEG,
|
357
|
+
:tIDENTIFIER, "y", EXPR_ARG)
|
358
|
+
end
|
359
|
+
|
251
360
|
def test_yylex_and_dot
|
252
361
|
setup_lexer_class RubyParser::V23
|
253
362
|
|
@@ -272,15 +381,6 @@ class TestRubyLexer < Minitest::Test
|
|
272
381
|
:tIDENTIFIER, "y")
|
273
382
|
end
|
274
383
|
|
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
384
|
def test_yylex_and_equals
|
285
385
|
assert_lex3("&=", nil, :tOP_ASGN, "&", EXPR_BEG)
|
286
386
|
end
|
@@ -303,424 +403,112 @@ class TestRubyLexer < Minitest::Test
|
|
303
403
|
assert_lex3 "=>", nil, :tASSOC, "=>", EXPR_BEG
|
304
404
|
end
|
305
405
|
|
306
|
-
def
|
307
|
-
|
406
|
+
def test_yylex_back_ref
|
407
|
+
assert_lex3("[$&, $`, $', $+]",
|
408
|
+
nil,
|
409
|
+
:tLBRACK, "[", EXPR_PAR,
|
410
|
+
:tBACK_REF, :&, EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
411
|
+
:tBACK_REF, :"`", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
412
|
+
:tBACK_REF, :"'", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
413
|
+
:tBACK_REF, :+, EXPR_END,
|
414
|
+
:tRBRACK, "]", EXPR_END)
|
415
|
+
end
|
308
416
|
|
309
|
-
|
417
|
+
def test_yylex_backslash
|
418
|
+
assert_lex3("1 \\\n+ 2",
|
310
419
|
nil,
|
311
|
-
:
|
312
|
-
:
|
420
|
+
:tINTEGER, 1, EXPR_NUM,
|
421
|
+
:tPLUS, "+", EXPR_BEG,
|
422
|
+
:tINTEGER, 2, EXPR_NUM)
|
313
423
|
end
|
314
424
|
|
315
|
-
def
|
316
|
-
|
425
|
+
def test_yylex_backslash_bad
|
426
|
+
refute_lex("1 \\ + 2", :tINTEGER, 1)
|
427
|
+
end
|
317
428
|
|
318
|
-
|
429
|
+
def test_yylex_backtick
|
430
|
+
assert_lex3("`ls`",
|
319
431
|
nil,
|
320
|
-
:
|
321
|
-
:
|
322
|
-
:
|
432
|
+
:tXSTRING_BEG, "`", EXPR_BEG,
|
433
|
+
:tSTRING_CONTENT, "ls", EXPR_BEG,
|
434
|
+
:tSTRING_END, "`", EXPR_LIT)
|
323
435
|
end
|
324
436
|
|
325
|
-
def
|
326
|
-
|
327
|
-
s(:dstr,
|
328
|
-
"(",
|
329
|
-
s(:evstr, s(:call, nil, :b)),
|
330
|
-
s(:evstr, s(:call, nil, :d)),
|
331
|
-
s(:str, ")")))
|
437
|
+
def test_yylex_backtick_cmdarg
|
438
|
+
self.lex_state = EXPR_DOT
|
332
439
|
|
333
|
-
|
334
|
-
|
335
|
-
|
440
|
+
# \n ensures expr_cmd (TODO: why?)
|
441
|
+
assert_lex3("\n`", nil, :tBACK_REF2, "`", EXPR_CMDARG)
|
442
|
+
end
|
336
443
|
|
337
|
-
|
338
|
-
|
339
|
-
end
|
444
|
+
def test_yylex_backtick_dot
|
445
|
+
self.lex_state = EXPR_DOT
|
340
446
|
|
341
|
-
|
447
|
+
assert_lex3("a.`(3)",
|
448
|
+
nil,
|
449
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
450
|
+
:tDOT, ".", EXPR_DOT,
|
451
|
+
:tBACK_REF2, "`", EXPR_ARG,
|
452
|
+
:tLPAREN2, "(", EXPR_PAR,
|
453
|
+
:tINTEGER, 3, EXPR_NUM,
|
454
|
+
:tRPAREN, ")", EXPR_ENDFN)
|
455
|
+
end
|
342
456
|
|
343
|
-
|
344
|
-
|
345
|
-
end
|
457
|
+
def test_yylex_backtick_method
|
458
|
+
self.lex_state = EXPR_FNAME
|
346
459
|
|
347
|
-
|
348
|
-
|
460
|
+
assert_lex3("`",
|
461
|
+
nil,
|
462
|
+
:tBACK_REF2, "`", EXPR_END)
|
463
|
+
end
|
349
464
|
|
350
|
-
|
465
|
+
def test_yylex_bad_char
|
466
|
+
refute_lex(" \010 ")
|
351
467
|
end
|
352
468
|
|
353
|
-
def
|
354
|
-
|
355
|
-
|
469
|
+
def test_yylex_bang
|
470
|
+
assert_lex3("!", nil, :tBANG, "!", EXPR_BEG)
|
471
|
+
end
|
356
472
|
|
357
|
-
|
358
|
-
|
359
|
-
|
473
|
+
def test_yylex_bang_equals
|
474
|
+
assert_lex3("!=", nil, :tNEQ, "!=", EXPR_BEG)
|
475
|
+
end
|
360
476
|
|
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
|
477
|
+
def test_yylex_bang_tilde
|
478
|
+
assert_lex3("!~", nil, :tNMATCH, "!~", EXPR_BEG)
|
479
|
+
end
|
368
480
|
|
369
|
-
|
370
|
-
|
481
|
+
def test_yylex_block_bug_1
|
482
|
+
assert_lex3("a do end",
|
483
|
+
s(:iter, s(:call, nil, :a), 0),
|
371
484
|
|
372
|
-
|
485
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
486
|
+
:kDO, "do", EXPR_BEG,
|
487
|
+
:kEND, "end", EXPR_END)
|
373
488
|
end
|
374
489
|
|
375
|
-
def
|
376
|
-
|
490
|
+
def test_yylex_block_bug_2
|
491
|
+
assert_lex3("a = 1\na do\nend",
|
492
|
+
s(:block,
|
493
|
+
s(:lasgn, :a, s(:lit, 1)),
|
494
|
+
s(:iter, s(:call, nil, :a), 0)),
|
377
495
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
assert_lex("def !@; end",
|
387
|
-
s(:defn, :"!@", s(:args), s(:nil)),
|
388
|
-
|
389
|
-
:kDEF, "def", EXPR_FNAME, 0, 0,
|
390
|
-
:tUBANG, "!@", EXPR_ARG, 0, 0,
|
391
|
-
:tSEMI, ";", EXPR_BEG, 0, 0,
|
392
|
-
:kEND, "end", EXPR_END, 0, 0)
|
393
|
-
end
|
394
|
-
|
395
|
-
def test_yylex_not_at_ivar
|
396
|
-
assert_lex("!@ivar",
|
397
|
-
s(:call, s(:ivar, :@ivar), :"!"),
|
398
|
-
|
399
|
-
:tBANG, "!", EXPR_BEG, 0, 0,
|
400
|
-
:tIVAR, "@ivar", EXPR_END, 0, 0)
|
401
|
-
end
|
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)
|
700
|
-
end
|
701
|
-
|
702
|
-
def test_yylex_block_bug_2
|
703
|
-
assert_lex3("a = 1\na do\nend",
|
704
|
-
s(:block,
|
705
|
-
s(:lasgn, :a, s(:lit, 1)),
|
706
|
-
s(:iter, s(:call, nil, :a), 0)),
|
707
|
-
|
708
|
-
:tIDENTIFIER, "a", EXPR_CMDARG,
|
709
|
-
:tEQL, "=", EXPR_BEG,
|
710
|
-
:tINTEGER, 1, EXPR_NUM,
|
711
|
-
:tNL, nil, EXPR_BEG,
|
712
|
-
:tIDENTIFIER, "a", EXPR_CMDARG,
|
713
|
-
:kDO, "do", EXPR_BEG,
|
714
|
-
:kEND, "end", EXPR_END)
|
715
|
-
end
|
496
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
497
|
+
:tEQL, "=", EXPR_BEG,
|
498
|
+
:tINTEGER, 1, EXPR_NUM,
|
499
|
+
:tNL, nil, EXPR_BEG,
|
500
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
501
|
+
:kDO, "do", EXPR_BEG,
|
502
|
+
:kEND, "end", EXPR_END)
|
503
|
+
end
|
716
504
|
|
717
505
|
def test_yylex_block_bug_3
|
718
506
|
assert_lex3("a { }",
|
719
507
|
s(:iter, s(:call, nil, :a), 0),
|
720
508
|
|
721
509
|
:tIDENTIFIER, "a", EXPR_CMDARG, # verified
|
722
|
-
:tLCURLY, "{",
|
723
|
-
:tRCURLY, "}",
|
510
|
+
:tLCURLY, "{", EXPR_PAR,
|
511
|
+
:tRCURLY, "}", EXPR_END)
|
724
512
|
end
|
725
513
|
|
726
514
|
def test_yylex_carat
|
@@ -766,9 +554,9 @@ class TestRubyLexer < Minitest::Test
|
|
766
554
|
def test_yylex_comment
|
767
555
|
assert_lex3("1 # one\n# two\n2",
|
768
556
|
nil,
|
769
|
-
:tINTEGER, 1,
|
557
|
+
:tINTEGER, 1, EXPR_NUM,
|
770
558
|
:tNL, nil, EXPR_BEG,
|
771
|
-
:tINTEGER, 2,
|
559
|
+
:tINTEGER, 2, EXPR_NUM)
|
772
560
|
|
773
561
|
assert_equal "# one\n# two\n", @lex.comments
|
774
562
|
end
|
@@ -776,7 +564,7 @@ class TestRubyLexer < Minitest::Test
|
|
776
564
|
def test_yylex_comment_begin
|
777
565
|
assert_lex3("=begin\nblah\nblah\n=end\n42",
|
778
566
|
nil,
|
779
|
-
:tINTEGER, 42,
|
567
|
+
:tINTEGER, 42, EXPR_NUM)
|
780
568
|
|
781
569
|
assert_equal "=begin\nblah\nblah\n=end\n", @lex.comments
|
782
570
|
end
|
@@ -792,7 +580,7 @@ class TestRubyLexer < Minitest::Test
|
|
792
580
|
nil,
|
793
581
|
:tIDENTIFIER, "beginfoo", EXPR_CMDARG,
|
794
582
|
:tEQL, "=", EXPR_BEG,
|
795
|
-
:tINTEGER, 5,
|
583
|
+
:tINTEGER, 5, EXPR_NUM,
|
796
584
|
:tNL, nil, EXPR_BEG,
|
797
585
|
:tIDENTIFIER, "p", EXPR_CMDARG,
|
798
586
|
:tIDENTIFIER, "x", EXPR_ARG,
|
@@ -816,6 +604,50 @@ class TestRubyLexer < Minitest::Test
|
|
816
604
|
assert_lex3("# comment", nil)
|
817
605
|
end
|
818
606
|
|
607
|
+
def test_yylex_const_call_same_name
|
608
|
+
assert_lex("X = a { }; b { f :c }",
|
609
|
+
s(:block,
|
610
|
+
s(:cdecl, :X, s(:iter, s(:call, nil, :a), 0)),
|
611
|
+
s(:iter,
|
612
|
+
s(:call, nil, :b),
|
613
|
+
0,
|
614
|
+
s(:call, nil, :f, s(:lit, :c)))),
|
615
|
+
|
616
|
+
:tCONSTANT, "X", EXPR_CMDARG, 0, 0,
|
617
|
+
:tEQL, "=", EXPR_BEG, 0, 0,
|
618
|
+
:tIDENTIFIER, "a", EXPR_ARG, 0, 0,
|
619
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
620
|
+
:tRCURLY, "}", EXPR_END, 0, 0,
|
621
|
+
:tSEMI, ";", EXPR_BEG, 0, 0,
|
622
|
+
|
623
|
+
:tIDENTIFIER, "b", EXPR_CMDARG, 0, 0,
|
624
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
625
|
+
:tIDENTIFIER, "f", EXPR_CMDARG, 0, 1, # different
|
626
|
+
:tSYMBOL, "c", EXPR_LIT, 0, 1,
|
627
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
628
|
+
|
629
|
+
assert_lex("X = a { }; b { X :c }",
|
630
|
+
s(:block,
|
631
|
+
s(:cdecl, :X, s(:iter, s(:call, nil, :a), 0)),
|
632
|
+
s(:iter,
|
633
|
+
s(:call, nil, :b),
|
634
|
+
0,
|
635
|
+
s(:call, nil, :X, s(:lit, :c)))),
|
636
|
+
|
637
|
+
:tCONSTANT, "X", EXPR_CMDARG, 0, 0,
|
638
|
+
:tEQL, "=", EXPR_BEG, 0, 0,
|
639
|
+
:tIDENTIFIER, "a", EXPR_ARG, 0, 0,
|
640
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
641
|
+
:tRCURLY, "}", EXPR_END, 0, 0,
|
642
|
+
:tSEMI, ";", EXPR_BEG, 0, 0,
|
643
|
+
|
644
|
+
:tIDENTIFIER, "b", EXPR_CMDARG, 0, 0,
|
645
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
646
|
+
:tCONSTANT, "X", EXPR_CMDARG, 0, 1, # same
|
647
|
+
:tSYMBOL, "c", EXPR_LIT, 0, 1,
|
648
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
649
|
+
end
|
650
|
+
|
819
651
|
def test_yylex_constant
|
820
652
|
assert_lex3("ArgumentError", nil, :tCONSTANT, "ArgumentError", EXPR_CMDARG)
|
821
653
|
end
|
@@ -847,7 +679,7 @@ class TestRubyLexer < Minitest::Test
|
|
847
679
|
nil,
|
848
680
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
849
681
|
:tDIVIDE, "/", EXPR_BEG,
|
850
|
-
:tINTEGER, 2,
|
682
|
+
:tINTEGER, 2, EXPR_NUM)
|
851
683
|
end
|
852
684
|
|
853
685
|
def test_yylex_div_equals
|
@@ -855,7 +687,7 @@ class TestRubyLexer < Minitest::Test
|
|
855
687
|
nil,
|
856
688
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
857
689
|
:tOP_ASGN, "/", EXPR_BEG,
|
858
|
-
:tINTEGER, 2,
|
690
|
+
:tINTEGER, 2, EXPR_NUM)
|
859
691
|
end
|
860
692
|
|
861
693
|
def test_yylex_do
|
@@ -863,7 +695,7 @@ class TestRubyLexer < Minitest::Test
|
|
863
695
|
nil,
|
864
696
|
:tIDENTIFIER, "x", EXPR_CMDARG,
|
865
697
|
:kDO, "do", EXPR_BEG,
|
866
|
-
:tINTEGER, 42,
|
698
|
+
:tINTEGER, 42, EXPR_NUM,
|
867
699
|
:kEND, "end", EXPR_END)
|
868
700
|
end
|
869
701
|
|
@@ -876,7 +708,7 @@ class TestRubyLexer < Minitest::Test
|
|
876
708
|
:tDOT, ".", EXPR_DOT,
|
877
709
|
:tIDENTIFIER, "y", EXPR_ARG,
|
878
710
|
:kDO_BLOCK, "do", EXPR_BEG,
|
879
|
-
:tINTEGER, 42,
|
711
|
+
:tINTEGER, 42, EXPR_NUM,
|
880
712
|
:kEND, "end", EXPR_END) do
|
881
713
|
@lex.cmdarg.push true
|
882
714
|
end
|
@@ -887,25 +719,17 @@ class TestRubyLexer < Minitest::Test
|
|
887
719
|
|
888
720
|
assert_lex3("do 42 end",
|
889
721
|
nil,
|
890
|
-
:
|
891
|
-
:tINTEGER, 42,
|
722
|
+
:kDO, "do", EXPR_BEG,
|
723
|
+
:tINTEGER, 42, EXPR_NUM,
|
892
724
|
:kEND, "end", EXPR_END)
|
893
725
|
end
|
894
726
|
|
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
727
|
def test_yylex_do_cond
|
904
728
|
assert_lex3("x do 42 end",
|
905
729
|
nil,
|
906
730
|
:tIDENTIFIER, "x", EXPR_CMDARG,
|
907
731
|
:kDO_COND, "do", EXPR_BEG,
|
908
|
-
:tINTEGER, 42,
|
732
|
+
:tINTEGER, 42, EXPR_NUM,
|
909
733
|
:kEND, "end", EXPR_END) do
|
910
734
|
@lex.cond.push true
|
911
735
|
end
|
@@ -950,7 +774,7 @@ class TestRubyLexer < Minitest::Test
|
|
950
774
|
end
|
951
775
|
|
952
776
|
def test_yylex_float
|
953
|
-
assert_lex3("1.0", nil, :tFLOAT, 1.0,
|
777
|
+
assert_lex3("1.0", nil, :tFLOAT, 1.0, EXPR_NUM)
|
954
778
|
end
|
955
779
|
|
956
780
|
def test_yylex_float_bad_no_underscores
|
@@ -968,7 +792,7 @@ class TestRubyLexer < Minitest::Test
|
|
968
792
|
def test_yylex_float_call
|
969
793
|
assert_lex3("1.0.to_s",
|
970
794
|
nil,
|
971
|
-
:tFLOAT, 1.0,
|
795
|
+
:tFLOAT, 1.0, EXPR_NUM,
|
972
796
|
:tDOT, ".", EXPR_DOT,
|
973
797
|
:tIDENTIFIER, "to_s", EXPR_ARG)
|
974
798
|
end
|
@@ -983,7 +807,7 @@ class TestRubyLexer < Minitest::Test
|
|
983
807
|
assert_lex3("-1.0E10",
|
984
808
|
nil,
|
985
809
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
986
|
-
:tFLOAT, 10000000000.0,
|
810
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
987
811
|
end
|
988
812
|
|
989
813
|
def test_yylex_float_dot_e
|
@@ -996,29 +820,22 @@ class TestRubyLexer < Minitest::Test
|
|
996
820
|
assert_lex3("-1.0e10",
|
997
821
|
nil,
|
998
822
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
999
|
-
:tFLOAT, 10000000000.0,
|
823
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
1000
824
|
end
|
1001
825
|
|
1002
826
|
def test_yylex_float_e
|
1003
827
|
assert_lex3("1e10",
|
1004
828
|
nil,
|
1005
|
-
:tFLOAT, 10000000000.0,
|
829
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
1006
830
|
end
|
1007
831
|
|
1008
832
|
def test_yylex_float_e_bad_double_e
|
1009
833
|
assert_lex3("1e2e3",
|
1010
834
|
nil,
|
1011
|
-
:tFLOAT, 100,
|
835
|
+
:tFLOAT, 100, EXPR_NUM,
|
1012
836
|
:tIDENTIFIER, "e3", EXPR_END)
|
1013
837
|
end
|
1014
838
|
|
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
839
|
def test_yylex_float_e_bad_trailing_underscore
|
1023
840
|
refute_lex "123_e10"
|
1024
841
|
end
|
@@ -1031,21 +848,21 @@ class TestRubyLexer < Minitest::Test
|
|
1031
848
|
assert_lex3("-1e10",
|
1032
849
|
nil,
|
1033
850
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1034
|
-
:tFLOAT, 10000000000.0,
|
851
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
1035
852
|
end
|
1036
853
|
|
1037
854
|
def test_yylex_float_e_neg_minus
|
1038
855
|
assert_lex3("-1e-10",
|
1039
856
|
nil,
|
1040
857
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1041
|
-
:tFLOAT, 1.0e-10,
|
858
|
+
:tFLOAT, 1.0e-10, EXPR_NUM)
|
1042
859
|
end
|
1043
860
|
|
1044
861
|
def test_yylex_float_e_neg_plus
|
1045
862
|
assert_lex3("-1e+10",
|
1046
863
|
nil,
|
1047
864
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1048
|
-
:tFLOAT, 10000000000.0,
|
865
|
+
:tFLOAT, 10000000000.0, EXPR_NUM)
|
1049
866
|
end
|
1050
867
|
|
1051
868
|
def test_yylex_float_e_plus
|
@@ -1056,11 +873,18 @@ class TestRubyLexer < Minitest::Test
|
|
1056
873
|
assert_lex3("0e0", nil, :tFLOAT, 0.0, EXPR_NUM)
|
1057
874
|
end
|
1058
875
|
|
876
|
+
def test_yylex_float_if_modifier
|
877
|
+
assert_lex3("1e2if",
|
878
|
+
nil,
|
879
|
+
:tFLOAT, 100, EXPR_NUM,
|
880
|
+
:kIF_MOD, "if", EXPR_PAR)
|
881
|
+
end
|
882
|
+
|
1059
883
|
def test_yylex_float_neg
|
1060
884
|
assert_lex3("-1.0",
|
1061
885
|
nil,
|
1062
886
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1063
|
-
:tFLOAT, 1.0,
|
887
|
+
:tFLOAT, 1.0, EXPR_NUM)
|
1064
888
|
end
|
1065
889
|
|
1066
890
|
def test_yylex_ge
|
@@ -1068,7 +892,7 @@ class TestRubyLexer < Minitest::Test
|
|
1068
892
|
nil,
|
1069
893
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1070
894
|
:tGEQ, ">=", EXPR_BEG,
|
1071
|
-
:tINTEGER, 2,
|
895
|
+
:tINTEGER, 2, EXPR_NUM)
|
1072
896
|
end
|
1073
897
|
|
1074
898
|
def test_yylex_global
|
@@ -1092,56 +916,150 @@ class TestRubyLexer < Minitest::Test
|
|
1092
916
|
def test_yylex_global_number
|
1093
917
|
self.lex_state = EXPR_FNAME
|
1094
918
|
|
1095
|
-
assert_lex3("$1", nil, :tGVAR, "$1", EXPR_END)
|
919
|
+
assert_lex3("$1", nil, :tGVAR, "$1", EXPR_END)
|
920
|
+
end
|
921
|
+
|
922
|
+
def test_yylex_global_number_big
|
923
|
+
self.lex_state = EXPR_FNAME
|
924
|
+
|
925
|
+
assert_lex3("$1234", nil, :tGVAR, "$1234", EXPR_END)
|
926
|
+
end
|
927
|
+
|
928
|
+
def test_yylex_global_I_have_no_words
|
929
|
+
assert_lex3("$x\xE2\x80\x8B = 42", # zero width space?!?!?
|
930
|
+
nil,
|
931
|
+
:tGVAR, "$x\xE2\x80\x8B", EXPR_END,
|
932
|
+
:tEQL, "=", EXPR_BEG,
|
933
|
+
:tINTEGER, 42, EXPR_NUM)
|
934
|
+
end
|
935
|
+
|
936
|
+
def test_yylex_global_other
|
937
|
+
assert_lex3("[$~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $\"]",
|
938
|
+
nil,
|
939
|
+
:tLBRACK, "[", EXPR_PAR,
|
940
|
+
:tGVAR, "$~", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
941
|
+
:tGVAR, "$*", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
942
|
+
:tGVAR, "$$", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
943
|
+
:tGVAR, "$?", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
944
|
+
:tGVAR, "$!", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
945
|
+
:tGVAR, "$@", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
946
|
+
:tGVAR, "$/", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
947
|
+
:tGVAR, "$\\", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
948
|
+
:tGVAR, "$;", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
949
|
+
:tGVAR, "$,", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
950
|
+
:tGVAR, "$.", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
951
|
+
:tGVAR, "$=", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
952
|
+
:tGVAR, "$:", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
953
|
+
:tGVAR, "$<", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
954
|
+
:tGVAR, "$>", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
955
|
+
:tGVAR, "$\"", EXPR_END,
|
956
|
+
:tRBRACK, "]", EXPR_END)
|
957
|
+
end
|
958
|
+
|
959
|
+
def test_yylex_global_underscore
|
960
|
+
assert_lex3("$_", nil, :tGVAR, "$_", EXPR_END)
|
961
|
+
end
|
962
|
+
|
963
|
+
def test_yylex_global_wierd
|
964
|
+
assert_lex3("$__blah", nil, :tGVAR, "$__blah", EXPR_END)
|
965
|
+
end
|
966
|
+
|
967
|
+
def test_yylex_global_zero
|
968
|
+
assert_lex3("$0", nil, :tGVAR, "$0", EXPR_END)
|
969
|
+
end
|
970
|
+
|
971
|
+
def test_yylex_gt
|
972
|
+
assert_lex3("a > 2",
|
973
|
+
nil,
|
974
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
975
|
+
:tGT, ">", EXPR_BEG,
|
976
|
+
:tINTEGER, 2, EXPR_NUM)
|
977
|
+
end
|
978
|
+
|
979
|
+
def test_yylex_hash_colon
|
980
|
+
assert_lex("{a:1}",
|
981
|
+
s(:hash, s(:lit, :a), s(:lit, 1)),
|
982
|
+
|
983
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
984
|
+
:tLABEL, "a", EXPR_LAB, 0, 1,
|
985
|
+
:tINTEGER, 1, EXPR_NUM, 0, 1,
|
986
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
987
|
+
end
|
988
|
+
|
989
|
+
def test_yylex_hash_colon_double_quoted_symbol
|
990
|
+
assert_lex('{"abc": :b}',
|
991
|
+
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
992
|
+
|
993
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
994
|
+
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
995
|
+
:tSYMBOL, "b", EXPR_LIT, 0, 1,
|
996
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
997
|
+
end
|
998
|
+
|
999
|
+
def test_yylex_hash_colon_double_quoted_symbol_22
|
1000
|
+
setup_lexer_class RubyParser::V22
|
1001
|
+
|
1002
|
+
assert_lex('{"abc": :b}',
|
1003
|
+
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
1004
|
+
|
1005
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1006
|
+
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
1007
|
+
:tSYMBOL, "b", EXPR_LIT, 0, 1,
|
1008
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
def test_yylex_hash_colon_double_quoted_with_escapes
|
1012
|
+
assert_lex3("{\"s\\tr\\i\\ng\\\\foo\\'bar\":1}",
|
1013
|
+
nil,
|
1014
|
+
|
1015
|
+
:tLBRACE, "{", EXPR_PAR,
|
1016
|
+
:tLABEL, "s\tr\i\ng\\foo'bar", EXPR_LAB,
|
1017
|
+
:tINTEGER, 1, EXPR_NUM,
|
1018
|
+
:tRCURLY, "}", EXPR_END)
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
def test_yylex_hash_colon_quoted_22
|
1022
|
+
setup_lexer_class RubyParser::V22
|
1023
|
+
|
1024
|
+
assert_lex("{'a':1}",
|
1025
|
+
s(:hash, s(:lit, :a), s(:lit, 1)),
|
1026
|
+
|
1027
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1028
|
+
:tLABEL, "a", EXPR_LAB, 0, 1,
|
1029
|
+
:tINTEGER, 1, EXPR_NUM, 0, 1,
|
1030
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1096
1031
|
end
|
1097
1032
|
|
1098
|
-
def
|
1099
|
-
|
1033
|
+
def test_yylex_hash_colon_quoted_symbol
|
1034
|
+
assert_lex("{'abc': :b}",
|
1035
|
+
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
1100
1036
|
|
1101
|
-
|
1037
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1038
|
+
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
1039
|
+
:tSYMBOL, "b", EXPR_LIT, 0, 1,
|
1040
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1102
1041
|
end
|
1103
1042
|
|
1104
|
-
def
|
1105
|
-
|
1106
|
-
nil,
|
1107
|
-
:tLBRACK, "[", EXPR_PAR,
|
1108
|
-
:tGVAR, "$~", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1109
|
-
:tGVAR, "$*", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1110
|
-
:tGVAR, "$$", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1111
|
-
:tGVAR, "$?", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1112
|
-
:tGVAR, "$!", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1113
|
-
:tGVAR, "$@", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1114
|
-
:tGVAR, "$/", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1115
|
-
:tGVAR, "$\\", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1116
|
-
:tGVAR, "$;", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1117
|
-
:tGVAR, "$,", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1118
|
-
:tGVAR, "$.", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1119
|
-
:tGVAR, "$=", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1120
|
-
:tGVAR, "$:", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1121
|
-
:tGVAR, "$<", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1122
|
-
:tGVAR, "$>", EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1123
|
-
:tGVAR, "$\"", EXPR_END,
|
1124
|
-
:tRBRACK, "]", EXPR_ENDARG)
|
1125
|
-
end
|
1043
|
+
def test_yylex_hash_colon_quoted_symbol_22
|
1044
|
+
setup_lexer_class RubyParser::V22
|
1126
1045
|
|
1127
|
-
|
1128
|
-
|
1129
|
-
end
|
1046
|
+
assert_lex("{'abc': :b}",
|
1047
|
+
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
1130
1048
|
|
1131
|
-
|
1132
|
-
|
1049
|
+
:tLBRACE, "{", EXPR_PAR, 0, 1,
|
1050
|
+
:tLABEL, "abc", EXPR_LAB, 0, 1,
|
1051
|
+
:tSYMBOL, "b", EXPR_LIT, 0, 1,
|
1052
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1133
1053
|
end
|
1134
1054
|
|
1135
|
-
def
|
1136
|
-
assert_lex3("
|
1137
|
-
|
1055
|
+
def test_yylex_hash_colon_quoted_with_escapes
|
1056
|
+
assert_lex3("{'s\\tr\\i\\ng\\\\foo\\'bar':1}",
|
1057
|
+
nil,
|
1138
1058
|
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
:tGT, ">", EXPR_BEG,
|
1144
|
-
:tINTEGER, 2, EXPR_NUM)
|
1059
|
+
:tLBRACE, "{", EXPR_PAR,
|
1060
|
+
:tLABEL, "s\\tr\\i\\ng\\foo'bar", EXPR_LAB,
|
1061
|
+
:tINTEGER, 1, EXPR_NUM,
|
1062
|
+
:tRCURLY, "}", EXPR_END)
|
1145
1063
|
end
|
1146
1064
|
|
1147
1065
|
def test_yylex_heredoc_backtick
|
@@ -1151,7 +1069,7 @@ class TestRubyLexer < Minitest::Test
|
|
1151
1069
|
:tEQL, "=", EXPR_BEG,
|
1152
1070
|
:tXSTRING_BEG, "`", EXPR_BEG,
|
1153
1071
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1154
|
-
:tSTRING_END, "EOF",
|
1072
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1155
1073
|
:tNL, nil, EXPR_BEG)
|
1156
1074
|
end
|
1157
1075
|
|
@@ -1162,7 +1080,7 @@ class TestRubyLexer < Minitest::Test
|
|
1162
1080
|
:tEQL, "=", EXPR_BEG,
|
1163
1081
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1164
1082
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1165
|
-
:tSTRING_END, "EOF",
|
1083
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1166
1084
|
:tNL, nil, EXPR_BEG)
|
1167
1085
|
end
|
1168
1086
|
|
@@ -1173,51 +1091,10 @@ class TestRubyLexer < Minitest::Test
|
|
1173
1091
|
:tEQL, "=", EXPR_BEG,
|
1174
1092
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1175
1093
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1176
|
-
:tSTRING_END, "EOF",
|
1094
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1177
1095
|
:tNL, nil, EXPR_BEG)
|
1178
1096
|
end
|
1179
1097
|
|
1180
|
-
def test_yylex_heredoc_double_squiggly
|
1181
|
-
setup_lexer_class Ruby23Parser
|
1182
|
-
|
1183
|
-
assert_lex3("a = <<~\"EOF\"\n blah blah\n EOF\n\n",
|
1184
|
-
nil,
|
1185
|
-
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1186
|
-
:tEQL, "=", EXPR_BEG,
|
1187
|
-
:tSTRING_BEG, "\"", EXPR_BEG,
|
1188
|
-
:tSTRING_CONTENT, "blah blah\n", EXPR_BEG,
|
1189
|
-
:tSTRING_END, "EOF", EXPR_END,
|
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
|
1197
|
-
|
1198
|
-
assert_lex3("a = <<~\"EOF\"\n blah blah\n \tblah blah\n EOF\n\n",
|
1199
|
-
nil,
|
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
|
1207
|
-
|
1208
|
-
def test_yylex_heredoc_double_squiggly_with_tab_indentation_removed
|
1209
|
-
setup_lexer_class Ruby23Parser
|
1210
|
-
|
1211
|
-
assert_lex3("a = <<~\"EOF\"\n blah blah\n\t blah blah\n EOF\n\n",
|
1212
|
-
nil,
|
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)
|
1219
|
-
end
|
1220
|
-
|
1221
1098
|
def test_yylex_heredoc_double_eos
|
1222
1099
|
refute_lex("a = <<\"EOF\"\nblah",
|
1223
1100
|
:tIDENTIFIER, "a",
|
@@ -1239,25 +1116,38 @@ class TestRubyLexer < Minitest::Test
|
|
1239
1116
|
:tEQL, "=", EXPR_BEG,
|
1240
1117
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1241
1118
|
:tSTRING_CONTENT, "#x a ", EXPR_BEG,
|
1242
|
-
:tSTRING_DVAR, "
|
1119
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1243
1120
|
:tSTRING_CONTENT, "@a b ", EXPR_BEG, # HUH?
|
1244
|
-
:tSTRING_DVAR, "
|
1121
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1245
1122
|
:tSTRING_CONTENT, "$b c ", EXPR_BEG, # HUH?
|
1246
|
-
:tSTRING_DVAR, "
|
1123
|
+
:tSTRING_DVAR, "#", EXPR_BEG,
|
1247
1124
|
:tSTRING_CONTENT, "@@d ", EXPR_BEG, # HUH?
|
1248
1125
|
:tSTRING_DBEG, "\#{", EXPR_BEG,
|
1249
1126
|
:tSTRING_CONTENT, "3} \n", EXPR_BEG,
|
1250
|
-
:tSTRING_END, "EOF",
|
1127
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1251
1128
|
:tNL, nil, EXPR_BEG)
|
1252
1129
|
end
|
1253
1130
|
|
1131
|
+
def test_yylex_heredoc_double_squiggly
|
1132
|
+
setup_lexer_class Ruby23Parser
|
1133
|
+
|
1134
|
+
assert_lex3("a = <<~\"EOF\"\n blah blah\n EOF\n\n",
|
1135
|
+
nil,
|
1136
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1137
|
+
:tEQL, "=", EXPR_BEG,
|
1138
|
+
:tSTRING_BEG, "\"", EXPR_BEG,
|
1139
|
+
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1140
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1141
|
+
:tNL, nil, EXPR_BEG)
|
1142
|
+
end
|
1143
|
+
|
1254
1144
|
def test_yylex_heredoc_empty
|
1255
1145
|
assert_lex3("<<\"\"\n\#{x}\nblah2\n\n\n",
|
1256
1146
|
nil,
|
1257
1147
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1258
1148
|
:tSTRING_DBEG, "\#{", EXPR_BEG,
|
1259
1149
|
:tSTRING_CONTENT, "x}\nblah2\n", EXPR_BEG,
|
1260
|
-
:tSTRING_END, "",
|
1150
|
+
:tSTRING_END, "", EXPR_LIT,
|
1261
1151
|
:tNL, nil, EXPR_BEG)
|
1262
1152
|
end
|
1263
1153
|
|
@@ -1268,7 +1158,7 @@ class TestRubyLexer < Minitest::Test
|
|
1268
1158
|
:tEQL, "=", EXPR_BEG,
|
1269
1159
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1270
1160
|
:tSTRING_CONTENT, "blah\nblah\n", EXPR_BEG,
|
1271
|
-
:tSTRING_END, "EOF",
|
1161
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1272
1162
|
:tNL, nil, EXPR_BEG)
|
1273
1163
|
end
|
1274
1164
|
|
@@ -1286,7 +1176,7 @@ class TestRubyLexer < Minitest::Test
|
|
1286
1176
|
:tEQL, "=", EXPR_BEG,
|
1287
1177
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1288
1178
|
:tSTRING_CONTENT, "blah\nblah\n", EXPR_BEG,
|
1289
|
-
:tSTRING_END, "EOF",
|
1179
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1290
1180
|
:tNL, nil, EXPR_BEG)
|
1291
1181
|
end
|
1292
1182
|
|
@@ -1298,8 +1188,8 @@ class TestRubyLexer < Minitest::Test
|
|
1298
1188
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1299
1189
|
:tEQL, "=", EXPR_BEG,
|
1300
1190
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1301
|
-
:tSTRING_CONTENT, "blah\
|
1302
|
-
:tSTRING_END, "EOF",
|
1191
|
+
:tSTRING_CONTENT, " blah\n blah\n", EXPR_BEG,
|
1192
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1303
1193
|
:tNL, nil, EXPR_BEG)
|
1304
1194
|
end
|
1305
1195
|
|
@@ -1310,7 +1200,7 @@ class TestRubyLexer < Minitest::Test
|
|
1310
1200
|
:tEQL, "=", EXPR_BEG,
|
1311
1201
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1312
1202
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1313
|
-
:tSTRING_END, "EOF",
|
1203
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1314
1204
|
:tNL, nil, EXPR_BEG)
|
1315
1205
|
end
|
1316
1206
|
|
@@ -1349,7 +1239,7 @@ class TestRubyLexer < Minitest::Test
|
|
1349
1239
|
:tEQL, "=", EXPR_BEG,
|
1350
1240
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1351
1241
|
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1352
|
-
:tSTRING_END, "EOF",
|
1242
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1353
1243
|
:tNL, nil, EXPR_BEG)
|
1354
1244
|
end
|
1355
1245
|
|
@@ -1361,8 +1251,8 @@ class TestRubyLexer < Minitest::Test
|
|
1361
1251
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1362
1252
|
:tEQL, "=", EXPR_BEG,
|
1363
1253
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
1364
|
-
:tSTRING_CONTENT, "blah blah\n", EXPR_BEG,
|
1365
|
-
:tSTRING_END, "EOF",
|
1254
|
+
:tSTRING_CONTENT, " blah blah\n", EXPR_BEG,
|
1255
|
+
:tSTRING_END, "EOF", EXPR_LIT,
|
1366
1256
|
:tNL, nil, EXPR_BEG)
|
1367
1257
|
end
|
1368
1258
|
|
@@ -1392,41 +1282,41 @@ class TestRubyLexer < Minitest::Test
|
|
1392
1282
|
assert_lex3("identifier?", nil, :tFID, "identifier?", EXPR_CMDARG)
|
1393
1283
|
end
|
1394
1284
|
|
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
1285
|
def test_yylex_identifier_equals3
|
1403
1286
|
assert_lex3(":a===b",
|
1404
1287
|
nil,
|
1405
|
-
:tSYMBOL, "a",
|
1288
|
+
:tSYMBOL, "a", EXPR_LIT,
|
1406
1289
|
:tEQQ, "===", EXPR_BEG,
|
1407
1290
|
:tIDENTIFIER, "b", EXPR_ARG)
|
1408
1291
|
end
|
1409
1292
|
|
1410
|
-
def
|
1411
|
-
assert_lex3(":
|
1293
|
+
def test_yylex_identifier_equals_arrow
|
1294
|
+
assert_lex3(":blah==>",
|
1412
1295
|
nil,
|
1413
|
-
:tSYMBOL, "
|
1414
|
-
:tASSOC,
|
1415
|
-
:tIDENTIFIER, "b", EXPR_ARG)
|
1296
|
+
:tSYMBOL, "blah=", EXPR_LIT,
|
1297
|
+
:tASSOC, "=>", EXPR_BEG)
|
1416
1298
|
end
|
1417
1299
|
|
1418
1300
|
def test_yylex_identifier_equals_caret
|
1419
1301
|
assert_lex_fname "^", :tCARET
|
1420
1302
|
end
|
1421
1303
|
|
1304
|
+
def test_yylex_identifier_equals_def2
|
1305
|
+
assert_lex_fname "==", :tEQ
|
1306
|
+
end
|
1307
|
+
|
1422
1308
|
def test_yylex_identifier_equals_def__20
|
1423
1309
|
setup_lexer_class RubyParser::V20
|
1424
1310
|
|
1425
1311
|
assert_lex_fname "identifier=", :tIDENTIFIER, EXPR_ENDFN
|
1426
1312
|
end
|
1427
1313
|
|
1428
|
-
def
|
1429
|
-
|
1314
|
+
def test_yylex_identifier_equals_equals_arrow
|
1315
|
+
assert_lex3(":a==>b",
|
1316
|
+
nil,
|
1317
|
+
:tSYMBOL, "a=", EXPR_LIT,
|
1318
|
+
:tASSOC, "=>", EXPR_BEG,
|
1319
|
+
:tIDENTIFIER, "b", EXPR_ARG)
|
1430
1320
|
end
|
1431
1321
|
|
1432
1322
|
def test_yylex_identifier_equals_expr
|
@@ -1515,25 +1405,6 @@ class TestRubyLexer < Minitest::Test
|
|
1515
1405
|
refute_lex "0d42__24"
|
1516
1406
|
end
|
1517
1407
|
|
1518
|
-
def test_yylex_integer_if_modifier
|
1519
|
-
assert_lex3("123if",
|
1520
|
-
nil,
|
1521
|
-
:tINTEGER, 123, EXPR_NUM,
|
1522
|
-
:kIF_MOD, "if", EXPR_PAR)
|
1523
|
-
end
|
1524
|
-
|
1525
|
-
def test_yylex_question_eh_a__20
|
1526
|
-
setup_lexer_class RubyParser::V20
|
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)
|
1535
|
-
end
|
1536
|
-
|
1537
1408
|
def test_yylex_integer_hex
|
1538
1409
|
assert_lex3 "0x2a", nil, :tINTEGER, 42, EXPR_NUM
|
1539
1410
|
end
|
@@ -1546,20 +1417,15 @@ class TestRubyLexer < Minitest::Test
|
|
1546
1417
|
refute_lex "0xab__cd"
|
1547
1418
|
end
|
1548
1419
|
|
1549
|
-
def
|
1550
|
-
assert_lex3("
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
refute_lex "08"
|
1555
|
-
end
|
1556
|
-
|
1557
|
-
def test_yylex_integer_oct_bad_range2
|
1558
|
-
refute_lex "08"
|
1420
|
+
def test_yylex_integer_if_modifier
|
1421
|
+
assert_lex3("123if",
|
1422
|
+
nil,
|
1423
|
+
:tINTEGER, 123, EXPR_NUM,
|
1424
|
+
:kIF_MOD, "if", EXPR_PAR)
|
1559
1425
|
end
|
1560
1426
|
|
1561
|
-
def
|
1562
|
-
|
1427
|
+
def test_yylex_integer_oct
|
1428
|
+
assert_lex3("052", nil, :tINTEGER, 42, EXPR_NUM)
|
1563
1429
|
end
|
1564
1430
|
|
1565
1431
|
def test_yylex_integer_oct_O
|
@@ -1578,6 +1444,18 @@ class TestRubyLexer < Minitest::Test
|
|
1578
1444
|
assert_lex3 "0O ", nil, :tINTEGER, 0, EXPR_NUM
|
1579
1445
|
end
|
1580
1446
|
|
1447
|
+
def test_yylex_integer_oct_bad_range
|
1448
|
+
refute_lex "08"
|
1449
|
+
end
|
1450
|
+
|
1451
|
+
def test_yylex_integer_oct_bad_range2
|
1452
|
+
refute_lex "08"
|
1453
|
+
end
|
1454
|
+
|
1455
|
+
def test_yylex_integer_oct_bad_underscores
|
1456
|
+
refute_lex "01__23"
|
1457
|
+
end
|
1458
|
+
|
1581
1459
|
def test_yylex_integer_oct_o
|
1582
1460
|
assert_lex3 "0o52", nil, :tINTEGER, 42, EXPR_NUM
|
1583
1461
|
end
|
@@ -1602,34 +1480,235 @@ class TestRubyLexer < Minitest::Test
|
|
1602
1480
|
:tIDENTIFIER, "to_s", EXPR_ARG)
|
1603
1481
|
end
|
1604
1482
|
|
1605
|
-
def test_yylex_integer_underscore
|
1606
|
-
assert_lex3("4_2", nil, :tINTEGER, 42, EXPR_NUM)
|
1483
|
+
def test_yylex_integer_underscore
|
1484
|
+
assert_lex3("4_2", nil, :tINTEGER, 42, EXPR_NUM)
|
1485
|
+
end
|
1486
|
+
|
1487
|
+
def test_yylex_integer_underscore_bad
|
1488
|
+
refute_lex "4__2"
|
1489
|
+
end
|
1490
|
+
|
1491
|
+
def test_yylex_integer_zero
|
1492
|
+
assert_lex3 "0", nil, :tINTEGER, 0, EXPR_NUM
|
1493
|
+
end
|
1494
|
+
|
1495
|
+
def test_yylex_is_your_spacebar_broken?
|
1496
|
+
assert_lex3(":a!=:b",
|
1497
|
+
nil,
|
1498
|
+
:tSYMBOL, "a", EXPR_LIT,
|
1499
|
+
:tNEQ, "!=", EXPR_BEG,
|
1500
|
+
:tSYMBOL, "b", EXPR_LIT)
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
def test_yylex_iter_array_curly
|
1504
|
+
# this will lex, but doesn't parse... don't freak out.
|
1505
|
+
assert_lex("f :a, [:b] { |c, d| }", # yes, this is bad code
|
1506
|
+
nil,
|
1507
|
+
|
1508
|
+
:tIDENTIFIER, "f", EXPR_CMDARG, 0, 0,
|
1509
|
+
:tSYMBOL, "a", EXPR_LIT, 0, 0,
|
1510
|
+
:tCOMMA, ",", EXPR_PAR, 0, 0,
|
1511
|
+
:tLBRACK, "[", EXPR_PAR, 1, 0,
|
1512
|
+
:tSYMBOL, "b", EXPR_LIT, 1, 0,
|
1513
|
+
:tRBRACK, "]", EXPR_END, 0, 0,
|
1514
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1515
|
+
:tPIPE, "|", EXPR_PAR, 0, 1,
|
1516
|
+
:tIDENTIFIER, "c", EXPR_ARG, 0, 1,
|
1517
|
+
:tCOMMA, ",", EXPR_PAR, 0, 1,
|
1518
|
+
:tIDENTIFIER, "d", EXPR_ARG, 0, 1,
|
1519
|
+
:tPIPE, "|", EXPR_PAR, 0, 1,
|
1520
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1521
|
+
end
|
1522
|
+
|
1523
|
+
def test_yylex_iter_array_curly__24
|
1524
|
+
setup_lexer_class RubyParser::V24
|
1525
|
+
|
1526
|
+
assert_lex("f :a, [:b] { |c, d| }", # yes, this is bad code
|
1527
|
+
s(:iter,
|
1528
|
+
s(:call, nil, :f, s(:lit, :a), s(:array, s(:lit, :b))),
|
1529
|
+
s(:args, :c, :d)),
|
1530
|
+
|
1531
|
+
:tIDENTIFIER, "f", EXPR_CMDARG, 0, 0,
|
1532
|
+
:tSYMBOL, "a", EXPR_LIT, 0, 0,
|
1533
|
+
:tCOMMA, ",", EXPR_PAR, 0, 0,
|
1534
|
+
:tLBRACK, "[", EXPR_PAR, 1, 0,
|
1535
|
+
:tSYMBOL, "b", EXPR_LIT, 1, 0,
|
1536
|
+
:tRBRACK, "]", EXPR_ENDARG, 0, 0,
|
1537
|
+
:tLBRACE_ARG, "{", EXPR_BEG, 0, 1,
|
1538
|
+
:tPIPE, "|", EXPR_PAR, 0, 1,
|
1539
|
+
:tIDENTIFIER, "c", EXPR_ARG, 0, 1,
|
1540
|
+
:tCOMMA, ",", EXPR_PAR, 0, 1,
|
1541
|
+
:tIDENTIFIER, "d", EXPR_ARG, 0, 1,
|
1542
|
+
:tPIPE, "|", EXPR_PAR, 0, 1,
|
1543
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1544
|
+
end
|
1545
|
+
|
1546
|
+
def test_yylex_ivar
|
1547
|
+
assert_lex3("@blah", nil, :tIVAR, "@blah", EXPR_END)
|
1548
|
+
end
|
1549
|
+
|
1550
|
+
def test_yylex_ivar_bad
|
1551
|
+
refute_lex "@1"
|
1552
|
+
end
|
1553
|
+
|
1554
|
+
def test_yylex_ivar_bad_0_length
|
1555
|
+
refute_lex "1+@\n", :tINTEGER, 1, :tPLUS, "+", EXPR_NUM
|
1556
|
+
end
|
1557
|
+
|
1558
|
+
def test_yylex_keyword_expr
|
1559
|
+
self.lex_state = EXPR_ENDARG
|
1560
|
+
|
1561
|
+
assert_lex3("if", nil, :kIF_MOD, "if", EXPR_PAR)
|
1562
|
+
end
|
1563
|
+
|
1564
|
+
def test_yylex_label
|
1565
|
+
assert_lex3("{a:",
|
1566
|
+
nil,
|
1567
|
+
:tLBRACE, "{", EXPR_PAR,
|
1568
|
+
:tLABEL, "a", EXPR_LAB)
|
1569
|
+
end
|
1570
|
+
|
1571
|
+
def test_yylex_label_in_params
|
1572
|
+
assert_lex3("foo(a:",
|
1573
|
+
nil,
|
1574
|
+
:tIDENTIFIER, "foo", EXPR_CMDARG,
|
1575
|
+
:tLPAREN2, "(", EXPR_PAR,
|
1576
|
+
:tLABEL, "a", EXPR_LAB)
|
1577
|
+
end
|
1578
|
+
|
1579
|
+
def test_yylex_lambda_args
|
1580
|
+
assert_lex("-> (a) { }",
|
1581
|
+
s(:iter, s(:lambda),
|
1582
|
+
s(:args, :a)),
|
1583
|
+
|
1584
|
+
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
1585
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1586
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1587
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1588
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1589
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1590
|
+
end
|
1591
|
+
|
1592
|
+
def test_yylex_lambda_args__24
|
1593
|
+
setup_lexer_class RubyParser::V24
|
1594
|
+
|
1595
|
+
assert_lex("-> (a) { }",
|
1596
|
+
s(:iter, s(:lambda),
|
1597
|
+
s(:args, :a)),
|
1598
|
+
|
1599
|
+
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
1600
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1601
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1602
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1603
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1604
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1605
|
+
end
|
1606
|
+
|
1607
|
+
def test_yylex_lambda_args_opt
|
1608
|
+
assert_lex("-> (a=nil) { }",
|
1609
|
+
s(:iter, s(:lambda),
|
1610
|
+
s(:args, s(:lasgn, :a, s(:nil)))),
|
1611
|
+
|
1612
|
+
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
1613
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1614
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1615
|
+
:tEQL, "=", EXPR_BEG, 1, 0,
|
1616
|
+
:kNIL, "nil", EXPR_END, 1, 0,
|
1617
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1618
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1619
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1620
|
+
end
|
1621
|
+
|
1622
|
+
def test_yylex_lambda_args_opt__24
|
1623
|
+
setup_lexer_class RubyParser::V24
|
1624
|
+
|
1625
|
+
assert_lex("-> (a=nil) { }",
|
1626
|
+
s(:iter, s(:lambda),
|
1627
|
+
s(:args, s(:lasgn, :a, s(:nil)))),
|
1628
|
+
|
1629
|
+
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
1630
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1631
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1632
|
+
:tEQL, "=", EXPR_BEG, 1, 0,
|
1633
|
+
:kNIL, "nil", EXPR_END, 1, 0,
|
1634
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1635
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1636
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1637
|
+
end
|
1638
|
+
|
1639
|
+
def test_yylex_lambda_as_args_with_block
|
1640
|
+
assert_lex3("a -> do end do end",
|
1641
|
+
nil,
|
1642
|
+
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1643
|
+
:tLAMBDA, nil, EXPR_ENDFN,
|
1644
|
+
:kDO, "do", EXPR_BEG,
|
1645
|
+
:kEND, "end", EXPR_END,
|
1646
|
+
:kDO, "do", EXPR_BEG,
|
1647
|
+
:kEND, "end", EXPR_END)
|
1607
1648
|
end
|
1608
1649
|
|
1609
|
-
def
|
1610
|
-
|
1611
|
-
|
1650
|
+
def test_yylex_lambda_hash
|
1651
|
+
assert_lex("-> (a={}) { }",
|
1652
|
+
s(:iter, s(:lambda),
|
1653
|
+
s(:args, s(:lasgn, :a, s(:hash)))),
|
1612
1654
|
|
1613
|
-
|
1614
|
-
|
1655
|
+
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
1656
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1657
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1658
|
+
:tEQL, "=", EXPR_BEG, 1, 0,
|
1659
|
+
:tLBRACE, "{", EXPR_PAR, 1, 1,
|
1660
|
+
:tRCURLY, "}", EXPR_END, 1, 0,
|
1661
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1662
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1663
|
+
:tRCURLY, "}", EXPR_END, 0, 0)
|
1615
1664
|
end
|
1616
1665
|
|
1617
|
-
def
|
1618
|
-
|
1619
|
-
end
|
1666
|
+
def test_yylex_lambda_hash__24
|
1667
|
+
setup_lexer_class RubyParser::V24
|
1620
1668
|
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1669
|
+
assert_lex("-> (a={}) { }",
|
1670
|
+
s(:iter, s(:lambda),
|
1671
|
+
s(:args, s(:lasgn, :a, s(:hash)))),
|
1624
1672
|
|
1625
|
-
|
1626
|
-
|
1673
|
+
:tLAMBDA, nil, EXPR_ENDFN, 0, 0,
|
1674
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1675
|
+
:tIDENTIFIER, "a", EXPR_ARG, 1, 0,
|
1676
|
+
:tEQL, "=", EXPR_BEG, 1, 0,
|
1677
|
+
:tLBRACE, "{", EXPR_PAR, 1, 1,
|
1678
|
+
:tRCURLY, "}", EXPR_ENDARG, 1, 0,
|
1679
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1680
|
+
:tLCURLY, "{", EXPR_PAR, 0, 1,
|
1681
|
+
:tRCURLY, "}", EXPR_ENDARG, 0, 0)
|
1627
1682
|
end
|
1628
1683
|
|
1629
|
-
def
|
1630
|
-
|
1684
|
+
def test_yylex_lasgn_call_same_name
|
1685
|
+
assert_lex("a = b.c :d => 1",
|
1686
|
+
s(:lasgn, :a,
|
1687
|
+
s(:call, s(:call, nil, :b), :c,
|
1688
|
+
s(:hash, s(:lit, :d), s(:lit, 1)))),
|
1631
1689
|
|
1632
|
-
|
1690
|
+
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
1691
|
+
:tEQL, "=", EXPR_BEG, 0, 0,
|
1692
|
+
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
1693
|
+
:tDOT, ".", EXPR_DOT, 0, 0,
|
1694
|
+
:tIDENTIFIER, "c", EXPR_ARG, 0, 0, # different
|
1695
|
+
:tSYMBOL, "d", EXPR_LIT, 0, 0,
|
1696
|
+
:tASSOC, "=>", EXPR_BEG, 0, 0,
|
1697
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
1698
|
+
|
1699
|
+
assert_lex("a = b.a :d => 1",
|
1700
|
+
s(:lasgn, :a,
|
1701
|
+
s(:call, s(:call, nil, :b), :a,
|
1702
|
+
s(:hash, s(:lit, :d), s(:lit, 1)))),
|
1703
|
+
|
1704
|
+
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
1705
|
+
:tEQL, "=", EXPR_BEG, 0, 0,
|
1706
|
+
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
1707
|
+
:tDOT, ".", EXPR_DOT, 0, 0,
|
1708
|
+
:tIDENTIFIER, "a", EXPR_ARG, 0, 0, # same as lvar
|
1709
|
+
:tSYMBOL, "d", EXPR_LIT, 0, 0,
|
1710
|
+
:tASSOC, "=>", EXPR_BEG, 0, 0,
|
1711
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
1633
1712
|
end
|
1634
1713
|
|
1635
1714
|
def test_yylex_lt
|
@@ -1656,12 +1735,22 @@ class TestRubyLexer < Minitest::Test
|
|
1656
1735
|
assert_lex3("<=", nil, :tLEQ, "<=", EXPR_BEG)
|
1657
1736
|
end
|
1658
1737
|
|
1738
|
+
def test_yylex_method_parens_chevron
|
1739
|
+
assert_lex("a()<<1",
|
1740
|
+
s(:call, s(:call, nil, :a), :<<, s(:lit, 1)),
|
1741
|
+
:tIDENTIFIER, "a", EXPR_CMDARG, 0, 0,
|
1742
|
+
:tLPAREN2, "(", EXPR_PAR, 1, 0,
|
1743
|
+
:tRPAREN, ")", EXPR_ENDFN, 0, 0,
|
1744
|
+
:tLSHFT, "<<", EXPR_BEG, 0, 0,
|
1745
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0)
|
1746
|
+
end
|
1747
|
+
|
1659
1748
|
def test_yylex_minus
|
1660
1749
|
assert_lex3("1 - 2",
|
1661
1750
|
nil,
|
1662
|
-
:tINTEGER, 1,
|
1751
|
+
:tINTEGER, 1, EXPR_NUM,
|
1663
1752
|
:tMINUS, "-", EXPR_BEG,
|
1664
|
-
:tINTEGER, 2,
|
1753
|
+
:tINTEGER, 2, EXPR_NUM)
|
1665
1754
|
end
|
1666
1755
|
|
1667
1756
|
def test_yylex_minus_equals
|
@@ -1684,7 +1773,39 @@ class TestRubyLexer < Minitest::Test
|
|
1684
1773
|
assert_lex3("-42",
|
1685
1774
|
nil,
|
1686
1775
|
:tUMINUS_NUM, "-", EXPR_BEG,
|
1687
|
-
:tINTEGER, 42,
|
1776
|
+
:tINTEGER, 42, EXPR_NUM)
|
1777
|
+
end
|
1778
|
+
|
1779
|
+
def test_yylex_not_at_defn
|
1780
|
+
assert_lex("def +@; end",
|
1781
|
+
s(:defn, :+@, s(:args), s(:nil)),
|
1782
|
+
|
1783
|
+
:kDEF, "def", EXPR_FNAME, 0, 0,
|
1784
|
+
:tUPLUS, "+@", EXPR_ARG, 0, 0,
|
1785
|
+
:tSEMI, ";", EXPR_BEG, 0, 0,
|
1786
|
+
:kEND, "end", EXPR_END, 0, 0)
|
1787
|
+
|
1788
|
+
assert_lex("def !@; end",
|
1789
|
+
s(:defn, :"!@", s(:args), s(:nil)),
|
1790
|
+
|
1791
|
+
:kDEF, "def", EXPR_FNAME, 0, 0,
|
1792
|
+
:tUBANG, "!@", EXPR_ARG, 0, 0,
|
1793
|
+
:tSEMI, ";", EXPR_BEG, 0, 0,
|
1794
|
+
:kEND, "end", EXPR_END, 0, 0)
|
1795
|
+
end
|
1796
|
+
|
1797
|
+
def test_yylex_not_at_ivar
|
1798
|
+
assert_lex("!@ivar",
|
1799
|
+
s(:call, s(:ivar, :@ivar), :"!"),
|
1800
|
+
|
1801
|
+
:tBANG, "!", EXPR_BEG, 0, 0,
|
1802
|
+
:tIVAR, "@ivar", EXPR_END, 0, 0)
|
1803
|
+
end
|
1804
|
+
|
1805
|
+
def test_yylex_not_unary_method
|
1806
|
+
self.lex_state = EXPR_FNAME
|
1807
|
+
|
1808
|
+
assert_lex3("!@", nil, :tUBANG, "!@", EXPR_ARG)
|
1688
1809
|
end
|
1689
1810
|
|
1690
1811
|
def test_yylex_nth_ref
|
@@ -1700,7 +1821,68 @@ class TestRubyLexer < Minitest::Test
|
|
1700
1821
|
:tNTH_REF, 7, EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1701
1822
|
:tNTH_REF, 8, EXPR_END, :tCOMMA, ",", EXPR_PAR,
|
1702
1823
|
:tNTH_REF, 9, EXPR_END,
|
1703
|
-
:tRBRACK, "]",
|
1824
|
+
:tRBRACK, "]", EXPR_END)
|
1825
|
+
end
|
1826
|
+
|
1827
|
+
def test_yylex_number_times_ident_times_return_number
|
1828
|
+
assert_lex("1 * b * 3",
|
1829
|
+
s(:call,
|
1830
|
+
s(:call, s(:lit, 1), :*, s(:call, nil, :b)),
|
1831
|
+
:*, s(:lit, 3)),
|
1832
|
+
|
1833
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0,
|
1834
|
+
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
1835
|
+
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
1836
|
+
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
1837
|
+
:tINTEGER, 3, EXPR_NUM, 0, 0)
|
1838
|
+
|
1839
|
+
assert_lex("1 * b *\n 3",
|
1840
|
+
s(:call,
|
1841
|
+
s(:call, s(:lit, 1), :*, s(:call, nil, :b)),
|
1842
|
+
:*, s(:lit, 3)),
|
1843
|
+
|
1844
|
+
:tINTEGER, 1, EXPR_NUM, 0, 0,
|
1845
|
+
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
1846
|
+
:tIDENTIFIER, "b", EXPR_ARG, 0, 0,
|
1847
|
+
:tSTAR2, "*", EXPR_BEG, 0, 0,
|
1848
|
+
:tINTEGER, 3, EXPR_NUM, 0, 0)
|
1849
|
+
end
|
1850
|
+
|
1851
|
+
def test_yylex_numbers
|
1852
|
+
assert_lex3 "0b10", nil, :tINTEGER, 2, EXPR_NUM
|
1853
|
+
assert_lex3 "0B10", nil, :tINTEGER, 2, EXPR_NUM
|
1854
|
+
|
1855
|
+
assert_lex3 "0d10", nil, :tINTEGER, 10, EXPR_NUM
|
1856
|
+
assert_lex3 "0D10", nil, :tINTEGER, 10, EXPR_NUM
|
1857
|
+
|
1858
|
+
assert_lex3 "0x10", nil, :tINTEGER, 16, EXPR_NUM
|
1859
|
+
assert_lex3 "0X10", nil, :tINTEGER, 16, EXPR_NUM
|
1860
|
+
|
1861
|
+
assert_lex3 "0o10", nil, :tINTEGER, 8, EXPR_NUM
|
1862
|
+
assert_lex3 "0O10", nil, :tINTEGER, 8, EXPR_NUM
|
1863
|
+
|
1864
|
+
assert_lex3 "0o", nil, :tINTEGER, 0, EXPR_NUM
|
1865
|
+
assert_lex3 "0O", nil, :tINTEGER, 0, EXPR_NUM
|
1866
|
+
|
1867
|
+
assert_lex3 "0", nil, :tINTEGER, 0, EXPR_NUM
|
1868
|
+
|
1869
|
+
refute_lex "0x"
|
1870
|
+
refute_lex "0X"
|
1871
|
+
refute_lex "0b"
|
1872
|
+
refute_lex "0B"
|
1873
|
+
refute_lex "0d"
|
1874
|
+
refute_lex "0D"
|
1875
|
+
|
1876
|
+
refute_lex "08"
|
1877
|
+
refute_lex "09"
|
1878
|
+
refute_lex "0o8"
|
1879
|
+
refute_lex "0o9"
|
1880
|
+
refute_lex "0O8"
|
1881
|
+
refute_lex "0O9"
|
1882
|
+
|
1883
|
+
refute_lex "1_e1"
|
1884
|
+
refute_lex "1_.1"
|
1885
|
+
refute_lex "1__1"
|
1704
1886
|
end
|
1705
1887
|
|
1706
1888
|
def test_yylex_open_bracket
|
@@ -1730,9 +1912,9 @@ class TestRubyLexer < Minitest::Test
|
|
1730
1912
|
assert_lex3("m { 3 }",
|
1731
1913
|
nil,
|
1732
1914
|
:tIDENTIFIER, "m", EXPR_CMDARG,
|
1733
|
-
:tLCURLY, "{",
|
1734
|
-
:tINTEGER, 3,
|
1735
|
-
:tRCURLY, "}",
|
1915
|
+
:tLCURLY, "{", EXPR_PAR,
|
1916
|
+
:tINTEGER, 3, EXPR_NUM,
|
1917
|
+
:tRCURLY, "}", EXPR_END)
|
1736
1918
|
end
|
1737
1919
|
|
1738
1920
|
def test_yylex_open_curly_bracket_block
|
@@ -1741,8 +1923,8 @@ class TestRubyLexer < Minitest::Test
|
|
1741
1923
|
assert_lex3("{ 4 }",
|
1742
1924
|
nil,
|
1743
1925
|
:tLBRACE_ARG, "{", EXPR_BEG,
|
1744
|
-
:tINTEGER, 4,
|
1745
|
-
:tRCURLY, "}",
|
1926
|
+
:tINTEGER, 4, EXPR_NUM,
|
1927
|
+
:tRCURLY, "}", EXPR_END)
|
1746
1928
|
end
|
1747
1929
|
|
1748
1930
|
def test_yylex_open_square_bracket_arg
|
@@ -1751,32 +1933,32 @@ class TestRubyLexer < Minitest::Test
|
|
1751
1933
|
assert_lex3("m [ 3 ]",
|
1752
1934
|
nil,
|
1753
1935
|
:tIDENTIFIER, "m", EXPR_CMDARG,
|
1754
|
-
:tLBRACK, "[",
|
1755
|
-
:tINTEGER, 3,
|
1756
|
-
:tRBRACK, "]",
|
1936
|
+
:tLBRACK, "[", EXPR_PAR,
|
1937
|
+
:tINTEGER, 3, EXPR_NUM,
|
1938
|
+
:tRBRACK, "]", EXPR_END)
|
1757
1939
|
end
|
1758
1940
|
|
1759
1941
|
def test_yylex_open_square_bracket_ary
|
1760
1942
|
assert_lex3("[1, 2, 3]",
|
1761
1943
|
nil,
|
1762
1944
|
:tLBRACK, "[", EXPR_PAR,
|
1763
|
-
:tINTEGER, 1, EXPR_NUM, :tCOMMA, ",",
|
1764
|
-
:tINTEGER, 2, EXPR_NUM, :tCOMMA, ",",
|
1945
|
+
:tINTEGER, 1, EXPR_NUM, :tCOMMA, ",", EXPR_PAR,
|
1946
|
+
:tINTEGER, 2, EXPR_NUM, :tCOMMA, ",", EXPR_PAR,
|
1765
1947
|
:tINTEGER, 3, EXPR_NUM,
|
1766
|
-
:tRBRACK, "]",
|
1948
|
+
:tRBRACK, "]", EXPR_END)
|
1767
1949
|
end
|
1768
1950
|
|
1769
1951
|
def test_yylex_open_square_bracket_meth
|
1770
1952
|
assert_lex3("m[3]",
|
1771
1953
|
nil,
|
1772
1954
|
:tIDENTIFIER, "m", EXPR_CMDARG,
|
1773
|
-
:tLBRACK2, "[",
|
1774
|
-
:tINTEGER, 3,
|
1775
|
-
:tRBRACK, "]",
|
1955
|
+
:tLBRACK2, "[", EXPR_PAR,
|
1956
|
+
:tINTEGER, 3, EXPR_NUM,
|
1957
|
+
:tRBRACK, "]", EXPR_END)
|
1776
1958
|
end
|
1777
1959
|
|
1778
1960
|
def test_yylex_or
|
1779
|
-
assert_lex3("|", nil, :tPIPE, "|",
|
1961
|
+
assert_lex3("|", nil, :tPIPE, "|", EXPR_PAR)
|
1780
1962
|
end
|
1781
1963
|
|
1782
1964
|
def test_yylex_or2
|
@@ -1791,12 +1973,85 @@ class TestRubyLexer < Minitest::Test
|
|
1791
1973
|
assert_lex3("|=", nil, :tOP_ASGN, "|", EXPR_BEG)
|
1792
1974
|
end
|
1793
1975
|
|
1976
|
+
def test_yylex_paren_string_interpolated_regexp
|
1977
|
+
setup_lexer('%( #{(/abcd/)} )',
|
1978
|
+
s(:dstr, " ", s(:evstr, s(:lit, /abcd/)), s(:str, " ")))
|
1979
|
+
|
1980
|
+
assert_next_lexeme :tSTRING_BEG, "%)", EXPR_BEG, 0, 0
|
1981
|
+
assert_next_lexeme :tSTRING_CONTENT, " ", EXPR_BEG, 0, 0
|
1982
|
+
assert_next_lexeme :tSTRING_DBEG, nil, EXPR_BEG, 0, 0
|
1983
|
+
|
1984
|
+
emulate_string_interpolation do
|
1985
|
+
assert_next_lexeme :tLPAREN, "(", EXPR_PAR, 1, 0
|
1986
|
+
assert_next_lexeme :tREGEXP_BEG, "/", EXPR_PAR, 1, 0
|
1987
|
+
assert_next_lexeme :tSTRING_CONTENT, "abcd", EXPR_PAR, 1, 0
|
1988
|
+
assert_next_lexeme :tREGEXP_END, "", EXPR_LIT, 1, 0
|
1989
|
+
assert_next_lexeme :tRPAREN, ")", EXPR_ENDFN, 0, 0
|
1990
|
+
end
|
1991
|
+
|
1992
|
+
assert_next_lexeme :tSTRING_CONTENT, " ", EXPR_BEG, 0, 0
|
1993
|
+
assert_next_lexeme :tSTRING_END, ")", EXPR_LIT, 0, 0
|
1994
|
+
|
1995
|
+
refute_lexeme
|
1996
|
+
end
|
1997
|
+
|
1998
|
+
def test_yylex_paren_string_parens_interpolated
|
1999
|
+
setup_lexer('%((#{b}#{d}))',
|
2000
|
+
s(:dstr,
|
2001
|
+
"(",
|
2002
|
+
s(:evstr, s(:call, nil, :b)),
|
2003
|
+
s(:evstr, s(:call, nil, :d)),
|
2004
|
+
s(:str, ")")))
|
2005
|
+
|
2006
|
+
assert_next_lexeme :tSTRING_BEG, "%)", EXPR_BEG, 0, 0
|
2007
|
+
assert_next_lexeme :tSTRING_CONTENT, "(", EXPR_BEG, 0, 0
|
2008
|
+
assert_next_lexeme :tSTRING_DBEG, nil, EXPR_BEG, 0, 0
|
2009
|
+
|
2010
|
+
emulate_string_interpolation do
|
2011
|
+
assert_next_lexeme :tIDENTIFIER, "b", EXPR_CMDARG, 0, 0
|
2012
|
+
end
|
2013
|
+
|
2014
|
+
assert_next_lexeme :tSTRING_DBEG, nil, EXPR_BEG, 0, 0
|
2015
|
+
|
2016
|
+
emulate_string_interpolation do
|
2017
|
+
assert_next_lexeme :tIDENTIFIER, "d", EXPR_CMDARG, 0, 0
|
2018
|
+
end
|
2019
|
+
|
2020
|
+
assert_next_lexeme :tSTRING_CONTENT, ")", EXPR_BEG, 0, 0
|
2021
|
+
assert_next_lexeme :tSTRING_END, ")", EXPR_LIT, 0, 0
|
2022
|
+
|
2023
|
+
refute_lexeme
|
2024
|
+
end
|
2025
|
+
|
2026
|
+
def test_yylex_paren_string_parens_interpolated_regexp
|
2027
|
+
setup_lexer('%((#{(/abcd/)}))',
|
2028
|
+
s(:dstr, "(", s(:evstr, s(:lit, /abcd/)), s(:str, ")")))
|
2029
|
+
|
2030
|
+
assert_next_lexeme :tSTRING_BEG, "%)", EXPR_BEG, 0, 0
|
2031
|
+
assert_next_lexeme :tSTRING_CONTENT, "(", EXPR_BEG, 0, 0
|
2032
|
+
|
2033
|
+
assert_next_lexeme :tSTRING_DBEG, nil, EXPR_BEG, 0, 0
|
2034
|
+
|
2035
|
+
emulate_string_interpolation do
|
2036
|
+
assert_next_lexeme :tLPAREN, "(", EXPR_PAR, 1, 0
|
2037
|
+
assert_next_lexeme :tREGEXP_BEG, "/", EXPR_PAR, 1, 0
|
2038
|
+
assert_next_lexeme :tSTRING_CONTENT, "abcd", EXPR_PAR, 1, 0
|
2039
|
+
assert_next_lexeme :tREGEXP_END, "", EXPR_LIT, 1, 0
|
2040
|
+
assert_next_lexeme :tRPAREN, ")", EXPR_ENDFN, 0, 0
|
2041
|
+
end
|
2042
|
+
|
2043
|
+
assert_next_lexeme :tSTRING_CONTENT, ")", EXPR_BEG, 0, 0
|
2044
|
+
assert_next_lexeme :tSTRING_END, ")", EXPR_LIT, 0, 0
|
2045
|
+
|
2046
|
+
refute_lexeme
|
2047
|
+
end
|
2048
|
+
|
1794
2049
|
def test_yylex_percent
|
1795
2050
|
assert_lex3("a % 2",
|
1796
2051
|
nil,
|
1797
2052
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1798
2053
|
:tPERCENT, "%", EXPR_BEG,
|
1799
|
-
:tINTEGER, 2,
|
2054
|
+
:tINTEGER, 2, EXPR_NUM)
|
1800
2055
|
end
|
1801
2056
|
|
1802
2057
|
def test_yylex_percent_equals
|
@@ -1804,15 +2059,15 @@ class TestRubyLexer < Minitest::Test
|
|
1804
2059
|
nil,
|
1805
2060
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
1806
2061
|
:tOP_ASGN, "%", EXPR_BEG,
|
1807
|
-
:tINTEGER, 2,
|
2062
|
+
:tINTEGER, 2, EXPR_NUM)
|
1808
2063
|
end
|
1809
2064
|
|
1810
2065
|
def test_yylex_plus
|
1811
2066
|
assert_lex3("1 + 1", # TODO lex_state?
|
1812
2067
|
nil,
|
1813
|
-
:tINTEGER, 1,
|
2068
|
+
:tINTEGER, 1, EXPR_NUM,
|
1814
2069
|
:tPLUS, "+", EXPR_BEG,
|
1815
|
-
:tINTEGER, 1,
|
2070
|
+
:tINTEGER, 1, EXPR_NUM)
|
1816
2071
|
end
|
1817
2072
|
|
1818
2073
|
def test_yylex_plus_equals
|
@@ -1831,55 +2086,28 @@ class TestRubyLexer < Minitest::Test
|
|
1831
2086
|
assert_lex3("+@", nil, :tUPLUS, "+@", EXPR_ARG)
|
1832
2087
|
end
|
1833
2088
|
|
1834
|
-
def
|
1835
|
-
|
1836
|
-
|
1837
|
-
assert_lex3("!@", nil, :tUBANG, "!@", EXPR_ARG)
|
2089
|
+
def test_yylex_plus_unary_number
|
2090
|
+
assert_lex3("+42", nil, :tINTEGER, 42, EXPR_NUM)
|
1838
2091
|
end
|
1839
2092
|
|
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"
|
2093
|
+
def test_yylex_question_bad_eos
|
2094
|
+
refute_lex "?"
|
2095
|
+
end
|
1864
2096
|
|
1865
|
-
|
1866
|
-
|
1867
|
-
refute_lex "0o8"
|
1868
|
-
refute_lex "0o9"
|
1869
|
-
refute_lex "0O8"
|
1870
|
-
refute_lex "0O9"
|
2097
|
+
def test_yylex_question_eh_a__20
|
2098
|
+
setup_lexer_class RubyParser::V20
|
1871
2099
|
|
1872
|
-
|
1873
|
-
refute_lex "1_.1"
|
1874
|
-
refute_lex "1__1"
|
2100
|
+
assert_lex3("?a", nil, :tSTRING, "a", EXPR_END)
|
1875
2101
|
end
|
1876
2102
|
|
1877
|
-
def
|
1878
|
-
|
2103
|
+
def test_yylex_question_eh_escape_M_escape_C__20
|
2104
|
+
setup_lexer_class RubyParser::V20
|
2105
|
+
|
2106
|
+
assert_lex3("?\\M-\\C-a", nil, :tSTRING, "\M-\C-a", EXPR_END)
|
1879
2107
|
end
|
1880
2108
|
|
1881
|
-
def
|
1882
|
-
|
2109
|
+
def test_yylex_question_control_escape
|
2110
|
+
assert_lex3('?\C-\]', nil, :tSTRING, ?\C-\], EXPR_END)
|
1883
2111
|
end
|
1884
2112
|
|
1885
2113
|
def test_yylex_question_ws
|
@@ -1903,11 +2131,11 @@ class TestRubyLexer < Minitest::Test
|
|
1903
2131
|
end
|
1904
2132
|
|
1905
2133
|
def test_yylex_rbracket
|
1906
|
-
assert_lex3("]", nil, :tRBRACK, "]",
|
2134
|
+
assert_lex3("]", nil, :tRBRACK, "]", EXPR_END)
|
1907
2135
|
end
|
1908
2136
|
|
1909
2137
|
def test_yylex_rcurly
|
1910
|
-
assert_lex("}", nil, :tRCURLY, "}",
|
2138
|
+
assert_lex("}", nil, :tRCURLY, "}", EXPR_END, 0, 1) do
|
1911
2139
|
lexer.brace_nest += 2
|
1912
2140
|
end
|
1913
2141
|
end
|
@@ -1917,7 +2145,7 @@ class TestRubyLexer < Minitest::Test
|
|
1917
2145
|
nil,
|
1918
2146
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1919
2147
|
:tSTRING_CONTENT, "regexp", EXPR_BEG,
|
1920
|
-
:tREGEXP_END, "",
|
2148
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1921
2149
|
end
|
1922
2150
|
|
1923
2151
|
def test_yylex_regexp_ambiguous
|
@@ -1926,7 +2154,7 @@ class TestRubyLexer < Minitest::Test
|
|
1926
2154
|
:tIDENTIFIER, "method", EXPR_CMDARG,
|
1927
2155
|
:tREGEXP_BEG, "/", EXPR_CMDARG,
|
1928
2156
|
:tSTRING_CONTENT, "regexp", EXPR_CMDARG,
|
1929
|
-
:tREGEXP_END, "",
|
2157
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1930
2158
|
end
|
1931
2159
|
|
1932
2160
|
def test_yylex_regexp_bad
|
@@ -1940,7 +2168,7 @@ class TestRubyLexer < Minitest::Test
|
|
1940
2168
|
nil,
|
1941
2169
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1942
2170
|
:tSTRING_CONTENT, "regex\\C-x", EXPR_BEG,
|
1943
|
-
:tREGEXP_END, "",
|
2171
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1944
2172
|
end
|
1945
2173
|
|
1946
2174
|
def test_yylex_regexp_escape_C_M
|
@@ -1948,7 +2176,7 @@ class TestRubyLexer < Minitest::Test
|
|
1948
2176
|
nil,
|
1949
2177
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1950
2178
|
:tSTRING_CONTENT, "regex\\C-\\M-x", EXPR_BEG,
|
1951
|
-
:tREGEXP_END, "",
|
2179
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1952
2180
|
end
|
1953
2181
|
|
1954
2182
|
def test_yylex_regexp_escape_C_M_craaaazy
|
@@ -1956,7 +2184,7 @@ class TestRubyLexer < Minitest::Test
|
|
1956
2184
|
nil,
|
1957
2185
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1958
2186
|
:tSTRING_CONTENT, "regex\\C-\\M-x", EXPR_BEG,
|
1959
|
-
:tREGEXP_END, "",
|
2187
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1960
2188
|
end
|
1961
2189
|
|
1962
2190
|
def test_yylex_regexp_escape_C_bad_dash
|
@@ -1984,7 +2212,7 @@ class TestRubyLexer < Minitest::Test
|
|
1984
2212
|
nil,
|
1985
2213
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1986
2214
|
:tSTRING_CONTENT, "regex\\M-x", EXPR_BEG,
|
1987
|
-
:tREGEXP_END, "",
|
2215
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1988
2216
|
end
|
1989
2217
|
|
1990
2218
|
def test_yylex_regexp_escape_M_C
|
@@ -1992,7 +2220,7 @@ class TestRubyLexer < Minitest::Test
|
|
1992
2220
|
nil,
|
1993
2221
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
1994
2222
|
:tSTRING_CONTENT, "regex\\M-\\C-x", EXPR_BEG,
|
1995
|
-
:tREGEXP_END, "",
|
2223
|
+
:tREGEXP_END, "", EXPR_LIT)
|
1996
2224
|
end
|
1997
2225
|
|
1998
2226
|
def test_yylex_regexp_escape_M_bad_dash
|
@@ -2016,7 +2244,7 @@ class TestRubyLexer < Minitest::Test
|
|
2016
2244
|
nil,
|
2017
2245
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2018
2246
|
:tSTRING_CONTENT, "\\/", EXPR_BEG,
|
2019
|
-
:tREGEXP_END, "",
|
2247
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2020
2248
|
end
|
2021
2249
|
|
2022
2250
|
def test_yylex_regexp_escape_backslash_terminator
|
@@ -2024,15 +2252,7 @@ class TestRubyLexer < Minitest::Test
|
|
2024
2252
|
nil,
|
2025
2253
|
:tREGEXP_BEG, "%r\000", EXPR_BEG,
|
2026
2254
|
:tSTRING_CONTENT, "blah\\%blah", EXPR_BEG,
|
2027
|
-
:tREGEXP_END, "",
|
2028
|
-
end
|
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)
|
2255
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2036
2256
|
end
|
2037
2257
|
|
2038
2258
|
def test_yylex_regexp_escape_backslash_terminator_meta1
|
@@ -2040,7 +2260,7 @@ class TestRubyLexer < Minitest::Test
|
|
2040
2260
|
nil,
|
2041
2261
|
:tREGEXP_BEG, "%r{", EXPR_BEG, # FIX ?!?
|
2042
2262
|
:tSTRING_CONTENT, "blah\\}blah", EXPR_BEG,
|
2043
|
-
:tREGEXP_END, "",
|
2263
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2044
2264
|
end
|
2045
2265
|
|
2046
2266
|
def test_yylex_regexp_escape_backslash_terminator_meta2
|
@@ -2048,7 +2268,7 @@ class TestRubyLexer < Minitest::Test
|
|
2048
2268
|
nil,
|
2049
2269
|
:tREGEXP_BEG, "%r\000", EXPR_BEG,
|
2050
2270
|
:tSTRING_CONTENT, "blah\\/blah", EXPR_BEG,
|
2051
|
-
:tREGEXP_END, "",
|
2271
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2052
2272
|
end
|
2053
2273
|
|
2054
2274
|
def test_yylex_regexp_escape_backslash_terminator_meta3
|
@@ -2056,7 +2276,7 @@ class TestRubyLexer < Minitest::Test
|
|
2056
2276
|
nil,
|
2057
2277
|
:tREGEXP_BEG, "%r\000", EXPR_BEG,
|
2058
2278
|
:tSTRING_CONTENT, "blah\\%blah", EXPR_BEG,
|
2059
|
-
:tREGEXP_END, "",
|
2279
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2060
2280
|
end
|
2061
2281
|
|
2062
2282
|
def test_yylex_regexp_escape_bad_eos
|
@@ -2068,7 +2288,7 @@ class TestRubyLexer < Minitest::Test
|
|
2068
2288
|
nil,
|
2069
2289
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2070
2290
|
:tSTRING_CONTENT, "regex\\\\regex", EXPR_BEG,
|
2071
|
-
:tREGEXP_END, "",
|
2291
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2072
2292
|
end
|
2073
2293
|
|
2074
2294
|
def test_yylex_regexp_escape_c
|
@@ -2076,7 +2296,7 @@ class TestRubyLexer < Minitest::Test
|
|
2076
2296
|
nil,
|
2077
2297
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2078
2298
|
:tSTRING_CONTENT, "regex\\cxxx", EXPR_BEG,
|
2079
|
-
:tREGEXP_END, "",
|
2299
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2080
2300
|
end
|
2081
2301
|
|
2082
2302
|
def test_yylex_regexp_escape_c_backslash
|
@@ -2084,7 +2304,7 @@ class TestRubyLexer < Minitest::Test
|
|
2084
2304
|
nil,
|
2085
2305
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2086
2306
|
:tSTRING_CONTENT, "regex\\c\\n", EXPR_BEG,
|
2087
|
-
:tREGEXP_END, "",
|
2307
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2088
2308
|
end
|
2089
2309
|
|
2090
2310
|
def test_yylex_regexp_escape_chars
|
@@ -2092,7 +2312,7 @@ class TestRubyLexer < Minitest::Test
|
|
2092
2312
|
nil,
|
2093
2313
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2094
2314
|
:tSTRING_CONTENT, "re\\tge\\nxp", EXPR_BEG,
|
2095
|
-
:tREGEXP_END, "",
|
2315
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2096
2316
|
end
|
2097
2317
|
|
2098
2318
|
def test_yylex_regexp_escape_double_backslash
|
@@ -2101,7 +2321,7 @@ class TestRubyLexer < Minitest::Test
|
|
2101
2321
|
nil,
|
2102
2322
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2103
2323
|
:tSTRING_CONTENT, "[\\/\\\\]$", EXPR_BEG,
|
2104
|
-
:tREGEXP_END, "",
|
2324
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2105
2325
|
end
|
2106
2326
|
|
2107
2327
|
def test_yylex_regexp_escape_hex
|
@@ -2109,7 +2329,7 @@ class TestRubyLexer < Minitest::Test
|
|
2109
2329
|
nil,
|
2110
2330
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2111
2331
|
:tSTRING_CONTENT, "regex\\x61xp", EXPR_BEG,
|
2112
|
-
:tREGEXP_END, "",
|
2332
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2113
2333
|
end
|
2114
2334
|
|
2115
2335
|
def test_yylex_regexp_escape_hex_bad
|
@@ -2121,7 +2341,7 @@ class TestRubyLexer < Minitest::Test
|
|
2121
2341
|
nil,
|
2122
2342
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2123
2343
|
:tSTRING_CONTENT, "^[\\xd\\xa]{2}", EXPR_BEG,
|
2124
|
-
:tREGEXP_END, "on",
|
2344
|
+
:tREGEXP_END, "on", EXPR_LIT)
|
2125
2345
|
end
|
2126
2346
|
|
2127
2347
|
def test_yylex_regexp_escape_oct1
|
@@ -2129,7 +2349,7 @@ class TestRubyLexer < Minitest::Test
|
|
2129
2349
|
nil,
|
2130
2350
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2131
2351
|
:tSTRING_CONTENT, "regex\\0xp", EXPR_BEG,
|
2132
|
-
:tREGEXP_END, "",
|
2352
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2133
2353
|
end
|
2134
2354
|
|
2135
2355
|
def test_yylex_regexp_escape_oct2
|
@@ -2137,7 +2357,7 @@ class TestRubyLexer < Minitest::Test
|
|
2137
2357
|
nil,
|
2138
2358
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2139
2359
|
:tSTRING_CONTENT, "regex\\07xp", EXPR_BEG,
|
2140
|
-
:tREGEXP_END, "",
|
2360
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2141
2361
|
end
|
2142
2362
|
|
2143
2363
|
def test_yylex_regexp_escape_oct3
|
@@ -2145,7 +2365,7 @@ class TestRubyLexer < Minitest::Test
|
|
2145
2365
|
nil,
|
2146
2366
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2147
2367
|
:tSTRING_CONTENT, "regex\\10142", EXPR_BEG,
|
2148
|
-
:tREGEXP_END, "",
|
2368
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2149
2369
|
end
|
2150
2370
|
|
2151
2371
|
def test_yylex_regexp_escape_return
|
@@ -2153,7 +2373,15 @@ class TestRubyLexer < Minitest::Test
|
|
2153
2373
|
nil,
|
2154
2374
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2155
2375
|
:tSTRING_CONTENT, "regexregex", EXPR_BEG,
|
2156
|
-
:tREGEXP_END, "",
|
2376
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2377
|
+
end
|
2378
|
+
|
2379
|
+
def test_yylex_regexp_escaped_delim
|
2380
|
+
assert_lex3("%r!blah(?\\!blah)!",
|
2381
|
+
nil,
|
2382
|
+
:tREGEXP_BEG, "%r\000", EXPR_BEG,
|
2383
|
+
:tSTRING_CONTENT, "blah(?!blah)", EXPR_BEG,
|
2384
|
+
:tREGEXP_END, "", EXPR_LIT)
|
2157
2385
|
end
|
2158
2386
|
|
2159
2387
|
def test_yylex_regexp_nm
|
@@ -2161,7 +2389,20 @@ class TestRubyLexer < Minitest::Test
|
|
2161
2389
|
nil,
|
2162
2390
|
:tREGEXP_BEG, "/", EXPR_BEG,
|
2163
2391
|
:tSTRING_CONTENT, ".*", EXPR_BEG,
|
2164
|
-
:tREGEXP_END, "nm",
|
2392
|
+
:tREGEXP_END, "nm", EXPR_LIT)
|
2393
|
+
end
|
2394
|
+
|
2395
|
+
def test_yylex_required_kwarg_no_value_22
|
2396
|
+
setup_lexer_class RubyParser::V22
|
2397
|
+
|
2398
|
+
assert_lex3("def foo a:, b:\nend",
|
2399
|
+
nil,
|
2400
|
+
:kDEF, "def", EXPR_FNAME,
|
2401
|
+
:tIDENTIFIER, "foo", EXPR_ENDFN,
|
2402
|
+
:tLABEL, "a", EXPR_LAB,
|
2403
|
+
:tCOMMA, ",", EXPR_PAR,
|
2404
|
+
:tLABEL, "b", EXPR_LAB,
|
2405
|
+
:kEND, "end", EXPR_END)
|
2165
2406
|
end
|
2166
2407
|
|
2167
2408
|
def test_yylex_rparen
|
@@ -2173,7 +2414,7 @@ class TestRubyLexer < Minitest::Test
|
|
2173
2414
|
nil,
|
2174
2415
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
2175
2416
|
:tRSHFT, ">>", EXPR_BEG,
|
2176
|
-
:tINTEGER, 2,
|
2417
|
+
:tINTEGER, 2, EXPR_NUM)
|
2177
2418
|
end
|
2178
2419
|
|
2179
2420
|
def test_yylex_rshft_equals
|
@@ -2181,7 +2422,7 @@ class TestRubyLexer < Minitest::Test
|
|
2181
2422
|
nil,
|
2182
2423
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
2183
2424
|
:tOP_ASGN, ">>", EXPR_BEG,
|
2184
|
-
:tINTEGER, 2,
|
2425
|
+
:tINTEGER, 2, EXPR_NUM)
|
2185
2426
|
end
|
2186
2427
|
|
2187
2428
|
def test_yylex_star
|
@@ -2249,11 +2490,11 @@ class TestRubyLexer < Minitest::Test
|
|
2249
2490
|
end
|
2250
2491
|
|
2251
2492
|
def test_yylex_string_bad_eos
|
2252
|
-
refute_lex(
|
2493
|
+
refute_lex("%", :tSTRING_BEG, "%")
|
2253
2494
|
end
|
2254
2495
|
|
2255
2496
|
def test_yylex_string_bad_eos_quote
|
2256
|
-
refute_lex(
|
2497
|
+
refute_lex("%{nest", :tSTRING_BEG, "%}")
|
2257
2498
|
end
|
2258
2499
|
|
2259
2500
|
def test_yylex_string_double
|
@@ -2269,7 +2510,7 @@ class TestRubyLexer < Minitest::Test
|
|
2269
2510
|
nil,
|
2270
2511
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2271
2512
|
:tSTRING_CONTENT, "\034", EXPR_BEG,
|
2272
|
-
:tSTRING_END, "\"",
|
2513
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2273
2514
|
end
|
2274
2515
|
|
2275
2516
|
def test_yylex_string_double_escape_C_escape
|
@@ -2277,106 +2518,25 @@ class TestRubyLexer < Minitest::Test
|
|
2277
2518
|
nil,
|
2278
2519
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2279
2520
|
:tSTRING_CONTENT, "\201", EXPR_BEG,
|
2280
|
-
:tSTRING_END, "\"",
|
2521
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2281
2522
|
end
|
2282
2523
|
|
2283
2524
|
def test_yylex_string_double_escape_C_question
|
2284
2525
|
assert_lex3("\"\\C-?\"", nil, :tSTRING, "\177", EXPR_END)
|
2285
2526
|
end
|
2286
2527
|
|
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
2528
|
def test_yylex_string_double_escape_M
|
2363
2529
|
chr = "\341"
|
2364
2530
|
|
2365
2531
|
assert_lex3("\"\\M-a\"", nil, :tSTRING, chr, EXPR_END)
|
2366
2532
|
end
|
2367
2533
|
|
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
2534
|
def test_yylex_string_double_escape_M_backslash
|
2375
2535
|
assert_lex3("\"\\M-\\\\\"",
|
2376
2536
|
nil,
|
2377
2537
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2378
2538
|
:tSTRING_CONTENT, "\334", EXPR_BEG,
|
2379
|
-
:tSTRING_END, "\"",
|
2539
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2380
2540
|
end
|
2381
2541
|
|
2382
2542
|
def test_yylex_string_double_escape_M_escape
|
@@ -2384,7 +2544,7 @@ class TestRubyLexer < Minitest::Test
|
|
2384
2544
|
nil,
|
2385
2545
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2386
2546
|
:tSTRING_CONTENT, "\201", EXPR_BEG,
|
2387
|
-
:tSTRING_END, "\"",
|
2547
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2388
2548
|
end
|
2389
2549
|
|
2390
2550
|
def test_yylex_string_double_escape_bs1
|
@@ -2400,11 +2560,7 @@ class TestRubyLexer < Minitest::Test
|
|
2400
2560
|
end
|
2401
2561
|
|
2402
2562
|
def test_yylex_string_double_escape_c_backslash
|
2403
|
-
|
2404
|
-
nil,
|
2405
|
-
:tSTRING_BEG, "\"", EXPR_BEG,
|
2406
|
-
:tSTRING_CONTENT, "\034", EXPR_BEG,
|
2407
|
-
:tSTRING_END, "\"", EXPR_END)
|
2563
|
+
refute_lex("\"\\c\\\"", :tSTRING_BEG, '"')
|
2408
2564
|
end
|
2409
2565
|
|
2410
2566
|
def test_yylex_string_double_escape_c_escape
|
@@ -2412,7 +2568,7 @@ class TestRubyLexer < Minitest::Test
|
|
2412
2568
|
nil,
|
2413
2569
|
:tSTRING_BEG, "\"", EXPR_BEG,
|
2414
2570
|
:tSTRING_CONTENT, "\201", EXPR_BEG,
|
2415
|
-
:tSTRING_END, "\"",
|
2571
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2416
2572
|
end
|
2417
2573
|
|
2418
2574
|
def test_yylex_string_double_escape_c_question
|
@@ -2446,15 +2602,7 @@ class TestRubyLexer < Minitest::Test
|
|
2446
2602
|
:tSTRING_CONTENT, "$b c ", EXPR_BEG,
|
2447
2603
|
:tSTRING_DBEG, nil, EXPR_BEG,
|
2448
2604
|
: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)
|
2605
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2458
2606
|
end
|
2459
2607
|
|
2460
2608
|
def test_yylex_string_double_nested_curlies
|
@@ -2462,7 +2610,7 @@ class TestRubyLexer < Minitest::Test
|
|
2462
2610
|
nil,
|
2463
2611
|
:tSTRING_BEG, "%}", EXPR_BEG,
|
2464
2612
|
:tSTRING_CONTENT, "nest{one{two}one}nest", EXPR_BEG,
|
2465
|
-
:tSTRING_END, "}",
|
2613
|
+
:tSTRING_END, "}", EXPR_LIT)
|
2466
2614
|
end
|
2467
2615
|
|
2468
2616
|
def test_yylex_string_double_no_interp
|
@@ -2470,25 +2618,33 @@ class TestRubyLexer < Minitest::Test
|
|
2470
2618
|
assert_lex3("\"blah # blah\"", nil, :tSTRING, "blah # blah", EXPR_END)
|
2471
2619
|
end
|
2472
2620
|
|
2621
|
+
def test_yylex_string_double_pound_dollar_bad
|
2622
|
+
assert_lex3('"#$%"', nil,
|
2623
|
+
|
2624
|
+
:tSTRING_BEG, "\"", EXPR_BEG,
|
2625
|
+
:tSTRING_CONTENT, "#\$%", EXPR_BEG,
|
2626
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2627
|
+
end
|
2628
|
+
|
2473
2629
|
def test_yylex_string_escape_x_single
|
2474
2630
|
assert_lex3("\"\\x0\"", nil, :tSTRING, "\000", EXPR_END)
|
2475
2631
|
end
|
2476
2632
|
|
2477
|
-
def
|
2478
|
-
assert_lex3("%
|
2633
|
+
def test_yylex_string_pct_I
|
2634
|
+
assert_lex3("%I[s1 s2\ns3]",
|
2479
2635
|
nil,
|
2480
|
-
:
|
2636
|
+
:tSYMBOLS_BEG, "%I[", EXPR_BEG,
|
2481
2637
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2482
2638
|
:tSPACE, nil, EXPR_BEG,
|
2483
2639
|
:tSTRING_CONTENT, "s2", EXPR_BEG,
|
2484
2640
|
:tSPACE, nil, EXPR_BEG,
|
2485
2641
|
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2486
2642
|
:tSPACE, nil, EXPR_BEG,
|
2487
|
-
:tSTRING_END, nil,
|
2643
|
+
:tSTRING_END, nil, EXPR_LIT)
|
2488
2644
|
end
|
2489
2645
|
|
2490
|
-
def
|
2491
|
-
assert_lex3("%I[s1 s2\ns3]",
|
2646
|
+
def test_yylex_string_pct_I_extra_space
|
2647
|
+
assert_lex3("%I[ s1 s2\ns3 ]",
|
2492
2648
|
nil,
|
2493
2649
|
:tSYMBOLS_BEG, "%I[", EXPR_BEG,
|
2494
2650
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
@@ -2497,11 +2653,67 @@ class TestRubyLexer < Minitest::Test
|
|
2497
2653
|
:tSPACE, nil, EXPR_BEG,
|
2498
2654
|
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2499
2655
|
:tSPACE, nil, EXPR_BEG,
|
2500
|
-
:tSTRING_END, nil,
|
2656
|
+
:tSTRING_END, nil, EXPR_LIT)
|
2501
2657
|
end
|
2502
2658
|
|
2503
|
-
def
|
2504
|
-
assert_lex3("%
|
2659
|
+
def test_yylex_string_pct_Q
|
2660
|
+
assert_lex3("%Q[s1 s2]",
|
2661
|
+
nil,
|
2662
|
+
:tSTRING_BEG, "%Q[", EXPR_BEG,
|
2663
|
+
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2664
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2665
|
+
end
|
2666
|
+
|
2667
|
+
def test_yylex_string_pct_Q_null_wtf?
|
2668
|
+
assert_lex3("%Q\0s1 s2\0",
|
2669
|
+
nil,
|
2670
|
+
:tSTRING_BEG, "%Q\0", EXPR_BEG,
|
2671
|
+
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2672
|
+
:tSTRING_END, "\0", EXPR_LIT)
|
2673
|
+
end
|
2674
|
+
|
2675
|
+
def test_yylex_string_pct_Q_bang
|
2676
|
+
assert_lex3("%Q!s1 s2!",
|
2677
|
+
nil,
|
2678
|
+
:tSTRING_BEG, "%Q\0", EXPR_BEG,
|
2679
|
+
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2680
|
+
:tSTRING_END, "!", EXPR_LIT)
|
2681
|
+
end
|
2682
|
+
|
2683
|
+
def test_yylex_string_pct_W
|
2684
|
+
assert_lex3("%W[s1 s2\ns3]", # TODO: add interpolation to these
|
2685
|
+
nil,
|
2686
|
+
:tWORDS_BEG, "%W[", EXPR_BEG,
|
2687
|
+
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2688
|
+
:tSPACE, nil, EXPR_BEG,
|
2689
|
+
:tSTRING_CONTENT, "s2", EXPR_BEG,
|
2690
|
+
:tSPACE, nil, EXPR_BEG,
|
2691
|
+
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2692
|
+
:tSPACE, nil, EXPR_BEG,
|
2693
|
+
:tSTRING_END, nil, EXPR_LIT)
|
2694
|
+
end
|
2695
|
+
|
2696
|
+
def test_yylex_string_pct_W_bs_nl
|
2697
|
+
assert_lex3("%W[s1 \\\ns2]", # TODO: add interpolation to these
|
2698
|
+
nil,
|
2699
|
+
:tWORDS_BEG, "%W[", EXPR_BEG,
|
2700
|
+
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2701
|
+
:tSPACE, nil, EXPR_BEG,
|
2702
|
+
:tSTRING_CONTENT, "\ns2", EXPR_BEG,
|
2703
|
+
:tSPACE, nil, EXPR_BEG,
|
2704
|
+
:tSTRING_END, nil, EXPR_LIT)
|
2705
|
+
end
|
2706
|
+
|
2707
|
+
def test_yylex_string_pct_angle
|
2708
|
+
assert_lex3("%<blah>",
|
2709
|
+
nil,
|
2710
|
+
:tSTRING_BEG, "%>", EXPR_BEG,
|
2711
|
+
:tSTRING_CONTENT, "blah", EXPR_BEG,
|
2712
|
+
:tSTRING_END, ">", EXPR_LIT)
|
2713
|
+
end
|
2714
|
+
|
2715
|
+
def test_yylex_string_pct_i
|
2716
|
+
assert_lex3("%i[s1 s2\ns3]",
|
2505
2717
|
nil,
|
2506
2718
|
:tQSYMBOLS_BEG, "%i[", EXPR_BEG,
|
2507
2719
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
@@ -2510,36 +2722,36 @@ class TestRubyLexer < Minitest::Test
|
|
2510
2722
|
:tSPACE, nil, EXPR_BEG,
|
2511
2723
|
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2512
2724
|
:tSPACE, nil, EXPR_BEG,
|
2513
|
-
:tSTRING_END, nil,
|
2725
|
+
:tSTRING_END, nil, EXPR_LIT)
|
2514
2726
|
end
|
2515
2727
|
|
2516
|
-
def
|
2517
|
-
assert_lex3("%
|
2728
|
+
def test_yylex_string_pct_i_extra_space
|
2729
|
+
assert_lex3("%i[ s1 s2\ns3 ]",
|
2518
2730
|
nil,
|
2519
|
-
:
|
2731
|
+
:tQSYMBOLS_BEG, "%i[", EXPR_BEG,
|
2520
2732
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2521
2733
|
:tSPACE, nil, EXPR_BEG,
|
2522
2734
|
:tSTRING_CONTENT, "s2", EXPR_BEG,
|
2523
2735
|
:tSPACE, nil, EXPR_BEG,
|
2524
2736
|
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2525
2737
|
:tSPACE, nil, EXPR_BEG,
|
2526
|
-
:tSTRING_END, nil,
|
2738
|
+
:tSTRING_END, nil, EXPR_LIT)
|
2527
2739
|
end
|
2528
2740
|
|
2529
|
-
def
|
2530
|
-
assert_lex3("%
|
2741
|
+
def test_yylex_string_pct_other
|
2742
|
+
assert_lex3("%%blah%",
|
2531
2743
|
nil,
|
2532
|
-
:tSTRING_BEG, "
|
2533
|
-
:tSTRING_CONTENT, "
|
2534
|
-
:tSTRING_END, "
|
2744
|
+
:tSTRING_BEG, "%%", EXPR_BEG,
|
2745
|
+
:tSTRING_CONTENT, "blah", EXPR_BEG,
|
2746
|
+
:tSTRING_END, "%", EXPR_LIT)
|
2535
2747
|
end
|
2536
2748
|
|
2537
|
-
def
|
2538
|
-
assert_lex3("%
|
2749
|
+
def test_yylex_string_pct_q
|
2750
|
+
assert_lex3("%q[s1 s2]",
|
2539
2751
|
nil,
|
2540
|
-
:tSTRING_BEG, "%
|
2752
|
+
:tSTRING_BEG, "%q[", EXPR_BEG,
|
2541
2753
|
:tSTRING_CONTENT, "s1 s2", EXPR_BEG,
|
2542
|
-
:tSTRING_END, "]",
|
2754
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2543
2755
|
end
|
2544
2756
|
|
2545
2757
|
def test_yylex_string_pct_s
|
@@ -2547,109 +2759,160 @@ class TestRubyLexer < Minitest::Test
|
|
2547
2759
|
nil,
|
2548
2760
|
:tSYMBEG, "%s[", EXPR_FNAME, # TODO: :tSYM_BEG ?
|
2549
2761
|
:tSTRING_CONTENT, "s1 s2", EXPR_FNAME, # man... I don't like this
|
2550
|
-
:tSTRING_END, "]",
|
2762
|
+
:tSTRING_END, "]", EXPR_LIT)
|
2551
2763
|
end
|
2552
2764
|
|
2553
|
-
def
|
2554
|
-
|
2555
|
-
|
2556
|
-
|
2557
|
-
|
2558
|
-
|
2559
|
-
|
2560
|
-
:tSPACE, nil, EXPR_BEG,
|
2561
|
-
:tSTRING_CONTENT, "s3", EXPR_BEG,
|
2562
|
-
:tSPACE, nil, EXPR_BEG,
|
2563
|
-
:tSTRING_END, nil, EXPR_END)
|
2765
|
+
def test_yylex_string_pct_w
|
2766
|
+
refute_lex("%w[s1 s2 ",
|
2767
|
+
:tQWORDS_BEG, "%w[",
|
2768
|
+
:tSTRING_CONTENT, "s1",
|
2769
|
+
:tSPACE, nil,
|
2770
|
+
:tSTRING_CONTENT, "s2",
|
2771
|
+
:tSPACE, nil)
|
2564
2772
|
end
|
2565
2773
|
|
2566
|
-
def
|
2567
|
-
assert_lex3("%
|
2774
|
+
def test_yylex_string_pct_w_bs_nl
|
2775
|
+
assert_lex3("%w[s1 \\\ns2]",
|
2568
2776
|
nil,
|
2569
|
-
:
|
2777
|
+
:tQWORDS_BEG, "%w[", EXPR_BEG,
|
2570
2778
|
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2571
2779
|
:tSPACE, nil, EXPR_BEG,
|
2572
2780
|
:tSTRING_CONTENT, "\ns2", EXPR_BEG,
|
2573
2781
|
:tSPACE, nil, EXPR_BEG,
|
2574
|
-
:tSTRING_END, nil,
|
2782
|
+
:tSTRING_END, nil, EXPR_LIT)
|
2783
|
+
end
|
2784
|
+
|
2785
|
+
def test_yylex_string_pct_w_bs_sp
|
2786
|
+
assert_lex3("%w[s\\ 1 s\\ 2]",
|
2787
|
+
nil,
|
2788
|
+
:tQWORDS_BEG, "%w[", EXPR_BEG,
|
2789
|
+
:tSTRING_CONTENT, "s 1", EXPR_BEG,
|
2790
|
+
:tSPACE, nil, EXPR_BEG,
|
2791
|
+
:tSTRING_CONTENT, "s 2", EXPR_BEG,
|
2792
|
+
:tSPACE, nil, EXPR_BEG,
|
2793
|
+
:tSTRING_END, nil, EXPR_LIT)
|
2794
|
+
end
|
2795
|
+
|
2796
|
+
def test_yylex_string_single
|
2797
|
+
assert_lex3("'string'", nil, :tSTRING, "string", EXPR_END)
|
2798
|
+
end
|
2799
|
+
|
2800
|
+
def test_yylex_string_single_escape_chars
|
2801
|
+
assert_lex3("'s\\tri\\ng'", nil, :tSTRING, "s\\tri\\ng", EXPR_END)
|
2802
|
+
end
|
2803
|
+
|
2804
|
+
def test_yylex_string_single_escape_quote_and_backslash
|
2805
|
+
assert_lex3(":'foo\\'bar\\\\baz'", nil, :tSYMBOL, "foo'bar\\baz",
|
2806
|
+
EXPR_LIT)
|
2807
|
+
end
|
2808
|
+
|
2809
|
+
def test_yylex_string_single_escaped_quote
|
2810
|
+
assert_lex3("'foo\\'bar'", nil, :tSTRING, "foo'bar", EXPR_END)
|
2811
|
+
end
|
2812
|
+
|
2813
|
+
def test_yylex_string_single_nl
|
2814
|
+
assert_lex3("'blah\\\nblah'", nil, :tSTRING, "blah\\\nblah", EXPR_END)
|
2815
|
+
end
|
2816
|
+
|
2817
|
+
def test_yylex_string_utf8_complex
|
2818
|
+
chr = [0x3024].pack("U")
|
2819
|
+
|
2820
|
+
assert_lex3('"#@a\u{3024}"',
|
2821
|
+
s(:dstr, "", s(:evstr, s(:ivar, :@a)), s(:str, chr)),
|
2822
|
+
:tSTRING_BEG, '"', EXPR_BEG,
|
2823
|
+
:tSTRING_DVAR, nil, EXPR_BEG,
|
2824
|
+
:tSTRING_CONTENT, "@a"+chr, EXPR_BEG,
|
2825
|
+
:tSTRING_END, '"', EXPR_LIT)
|
2575
2826
|
end
|
2576
2827
|
|
2577
|
-
def
|
2578
|
-
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
:
|
2828
|
+
def test_yylex_string_utf8_complex_missing_hex
|
2829
|
+
chr = [0x302].pack("U")
|
2830
|
+
str = "#{chr}zzz"
|
2831
|
+
|
2832
|
+
refute_lex('"#@a\u302zzz"',
|
2833
|
+
:tSTRING_BEG, '"',
|
2834
|
+
:tSTRING_DVAR, nil,
|
2835
|
+
:tSTRING_CONTENT, "@a"+str,
|
2836
|
+
:tSTRING_END, '"')
|
2837
|
+
|
2838
|
+
chr = [0x30].pack("U")
|
2839
|
+
str = "#{chr}zzz"
|
2840
|
+
|
2841
|
+
refute_lex('"#@a\u30zzz"',
|
2842
|
+
:tSTRING_BEG, '"',
|
2843
|
+
:tSTRING_DVAR, nil,
|
2844
|
+
:tSTRING_CONTENT, "@a"+str,
|
2845
|
+
:tSTRING_END, '"')
|
2846
|
+
|
2847
|
+
chr = [0x3].pack("U")
|
2848
|
+
str = "#{chr}zzz"
|
2849
|
+
|
2850
|
+
refute_lex('"#@a\u3zzz"',
|
2851
|
+
:tSTRING_BEG, '"',
|
2852
|
+
:tSTRING_DVAR, nil,
|
2853
|
+
:tSTRING_CONTENT, "@a"+str,
|
2854
|
+
:tSTRING_END, '"')
|
2583
2855
|
end
|
2584
2856
|
|
2585
|
-
def
|
2586
|
-
|
2587
|
-
|
2588
|
-
:tSTRING_BEG, "%%", EXPR_BEG,
|
2589
|
-
:tSTRING_CONTENT, "blah", EXPR_BEG,
|
2590
|
-
:tSTRING_END, "%", EXPR_END)
|
2591
|
-
end
|
2857
|
+
def test_yylex_string_utf8_bad_encoding_with_escapes
|
2858
|
+
str = "\"\\xBADπ\""
|
2859
|
+
exp = "\xBADπ".b
|
2592
2860
|
|
2593
|
-
|
2594
|
-
|
2595
|
-
:
|
2596
|
-
:tSTRING_CONTENT, "s1",
|
2597
|
-
:tSPACE, nil,
|
2598
|
-
:tSTRING_CONTENT, "s2",
|
2599
|
-
:tSPACE, nil)
|
2861
|
+
assert_lex(str,
|
2862
|
+
s(:str, exp),
|
2863
|
+
:tSTRING, exp, EXPR_END)
|
2600
2864
|
end
|
2601
2865
|
|
2602
|
-
def
|
2603
|
-
|
2604
|
-
|
2605
|
-
:tQWORDS_BEG, "%w[", EXPR_BEG,
|
2606
|
-
:tSTRING_CONTENT, "s1", EXPR_BEG,
|
2607
|
-
:tSPACE, nil, EXPR_BEG,
|
2608
|
-
:tSTRING_CONTENT, "\ns2", EXPR_BEG,
|
2609
|
-
:tSPACE, nil, EXPR_BEG,
|
2610
|
-
:tSTRING_END, nil, EXPR_END)
|
2611
|
-
end
|
2866
|
+
def test_yylex_string_utf8_complex_trailing_hex
|
2867
|
+
chr = [0x3024].pack("U")
|
2868
|
+
str = "#{chr}abz"
|
2612
2869
|
|
2613
|
-
|
2614
|
-
|
2615
|
-
|
2616
|
-
:
|
2617
|
-
:tSTRING_CONTENT, "
|
2618
|
-
:
|
2619
|
-
:tSTRING_CONTENT, "s 2", EXPR_BEG,
|
2620
|
-
:tSPACE, nil, EXPR_BEG,
|
2621
|
-
:tSTRING_END, nil, EXPR_END)
|
2870
|
+
assert_lex3('"#@a\u3024abz"',
|
2871
|
+
s(:dstr, "", s(:evstr, s(:ivar, :@a)), s(:str, str)),
|
2872
|
+
:tSTRING_BEG, '"', EXPR_BEG,
|
2873
|
+
:tSTRING_DVAR, nil, EXPR_BEG,
|
2874
|
+
:tSTRING_CONTENT, "@a"+str, EXPR_BEG,
|
2875
|
+
:tSTRING_END, '"', EXPR_LIT)
|
2622
2876
|
end
|
2623
2877
|
|
2624
|
-
def
|
2625
|
-
|
2878
|
+
def test_yylex_string_utf8_missing_hex
|
2879
|
+
refute_lex('"\u3zzz"')
|
2880
|
+
refute_lex('"\u30zzz"')
|
2881
|
+
refute_lex('"\u302zzz"')
|
2626
2882
|
end
|
2627
2883
|
|
2628
|
-
def
|
2629
|
-
|
2630
|
-
end
|
2884
|
+
def test_yylex_string_utf8_simple
|
2885
|
+
chr = [0x3024].pack("U")
|
2631
2886
|
|
2632
|
-
|
2633
|
-
|
2887
|
+
assert_lex3('"\u{3024}"',
|
2888
|
+
s(:str, chr),
|
2889
|
+
:tSTRING, chr, EXPR_END)
|
2634
2890
|
end
|
2635
2891
|
|
2636
|
-
def
|
2637
|
-
|
2892
|
+
def test_yylex_string_utf8_trailing_hex
|
2893
|
+
chr = [0x3024].pack("U")
|
2894
|
+
str = "#{chr}abz"
|
2895
|
+
|
2896
|
+
assert_lex3('"\u3024abz"',
|
2897
|
+
s(:str, str),
|
2898
|
+
:tSTRING, str, EXPR_END)
|
2638
2899
|
end
|
2639
2900
|
|
2640
|
-
def
|
2641
|
-
|
2901
|
+
def test_yylex_sym_quoted
|
2902
|
+
assert_lex(":'a'",
|
2903
|
+
s(:lit, :a),
|
2904
|
+
|
2905
|
+
:tSYMBOL, "a", EXPR_LIT, 0, 0)
|
2642
2906
|
end
|
2643
2907
|
|
2644
|
-
def
|
2645
|
-
|
2646
|
-
:tSYMBOL, "symbol\0", EXPR_END)
|
2908
|
+
def test_yylex_symbol
|
2909
|
+
assert_lex3(":symbol", nil, :tSYMBOL, "symbol", EXPR_LIT)
|
2647
2910
|
end
|
2648
2911
|
|
2649
2912
|
def test_yylex_symbol_double
|
2650
2913
|
assert_lex3(":\"symbol\"",
|
2651
2914
|
nil,
|
2652
|
-
:tSYMBOL,
|
2915
|
+
:tSYMBOL, "symbol", EXPR_LIT)
|
2653
2916
|
end
|
2654
2917
|
|
2655
2918
|
def test_yylex_symbol_double_interp
|
@@ -2659,29 +2922,30 @@ class TestRubyLexer < Minitest::Test
|
|
2659
2922
|
:tSTRING_CONTENT, "symbol", EXPR_FNAME,
|
2660
2923
|
:tSTRING_DBEG, nil, EXPR_FNAME,
|
2661
2924
|
:tSTRING_CONTENT, "1+1}", EXPR_FNAME, # HUH? this is BS
|
2662
|
-
:tSTRING_END, "\"",
|
2925
|
+
:tSTRING_END, "\"", EXPR_LIT)
|
2663
2926
|
end
|
2664
2927
|
|
2665
2928
|
def test_yylex_symbol_single
|
2666
2929
|
assert_lex3(":'symbol'",
|
2667
2930
|
nil,
|
2668
|
-
:tSYMBOL,
|
2931
|
+
:tSYMBOL, "symbol", EXPR_LIT)
|
2669
2932
|
end
|
2670
2933
|
|
2671
|
-
def
|
2672
|
-
assert_lex3('
|
2934
|
+
def test_yylex_symbol_single_escape_chars
|
2935
|
+
assert_lex3(":'s\\tri\\ng'",
|
2673
2936
|
nil,
|
2674
|
-
:tSYMBOL,
|
2937
|
+
:tSYMBOL, "s\\tri\\ng", EXPR_LIT)
|
2675
2938
|
end
|
2676
2939
|
|
2677
|
-
def
|
2678
|
-
assert_lex3(
|
2940
|
+
def test_yylex_symbol_single_noninterp
|
2941
|
+
assert_lex3(':\'symbol#{1+1}\'',
|
2679
2942
|
nil,
|
2680
|
-
:tSYMBOL,
|
2943
|
+
:tSYMBOL, 'symbol#{1+1}', EXPR_LIT)
|
2681
2944
|
end
|
2682
2945
|
|
2683
|
-
def
|
2684
|
-
|
2946
|
+
def test_yylex_symbol_zero_byte
|
2947
|
+
assert_lex(":\"symbol\0\"", nil,
|
2948
|
+
:tSYMBOL, "symbol\0", EXPR_LIT)
|
2685
2949
|
end
|
2686
2950
|
|
2687
2951
|
def test_yylex_ternary1
|
@@ -2703,7 +2967,7 @@ class TestRubyLexer < Minitest::Test
|
|
2703
2967
|
|
2704
2968
|
assert_lex3("42 ?",
|
2705
2969
|
nil,
|
2706
|
-
:tINTEGER, 42,
|
2970
|
+
:tINTEGER, 42, EXPR_NUM,
|
2707
2971
|
:tEH, "?", EXPR_BEG)
|
2708
2972
|
end
|
2709
2973
|
|
@@ -2746,14 +3010,14 @@ class TestRubyLexer < Minitest::Test
|
|
2746
3010
|
nil,
|
2747
3011
|
:kDEF, "def", EXPR_FNAME,
|
2748
3012
|
:tIDENTIFIER, "initialize", EXPR_ENDFN,
|
2749
|
-
:tLPAREN2, "(",
|
3013
|
+
:tLPAREN2, "(", EXPR_PAR,
|
2750
3014
|
:tIDENTIFIER, "u", EXPR_ARG,
|
2751
3015
|
:tEQL, "=", EXPR_BEG,
|
2752
|
-
:tFLOAT, 0.0,
|
2753
|
-
:tCOMMA, ",",
|
3016
|
+
:tFLOAT, 0.0, EXPR_NUM,
|
3017
|
+
:tCOMMA, ",", EXPR_PAR,
|
2754
3018
|
:tIDENTIFIER, "s", EXPR_ARG,
|
2755
3019
|
:tEQL, "=", EXPR_BEG,
|
2756
|
-
:tFLOAT, 0.0,
|
3020
|
+
:tFLOAT, 0.0, EXPR_NUM)
|
2757
3021
|
end
|
2758
3022
|
|
2759
3023
|
def test_zbug_id_equals
|
@@ -2761,7 +3025,7 @@ class TestRubyLexer < Minitest::Test
|
|
2761
3025
|
nil,
|
2762
3026
|
:tIDENTIFIER, "a", EXPR_CMDARG,
|
2763
3027
|
:tEQL, "=", EXPR_BEG,
|
2764
|
-
:tFLOAT, 0.0,
|
3028
|
+
:tFLOAT, 0.0, EXPR_NUM)
|
2765
3029
|
end
|
2766
3030
|
|
2767
3031
|
def test_zbug_no_spaces_in_decl
|
@@ -2769,190 +3033,13 @@ class TestRubyLexer < Minitest::Test
|
|
2769
3033
|
nil,
|
2770
3034
|
:kDEF, "def", EXPR_FNAME,
|
2771
3035
|
:tIDENTIFIER, "initialize", EXPR_ENDFN,
|
2772
|
-
:tLPAREN2, "(",
|
3036
|
+
:tLPAREN2, "(", EXPR_PAR,
|
2773
3037
|
:tIDENTIFIER, "u", EXPR_ARG,
|
2774
3038
|
:tEQL, "=", EXPR_BEG,
|
2775
|
-
:tFLOAT, 0.0,
|
2776
|
-
:tCOMMA, ",",
|
3039
|
+
:tFLOAT, 0.0, EXPR_NUM,
|
3040
|
+
:tCOMMA, ",", EXPR_PAR,
|
2777
3041
|
:tIDENTIFIER, "s", EXPR_ARG,
|
2778
3042
|
: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)
|
3043
|
+
:tFLOAT, 0.0, EXPR_NUM)
|
2957
3044
|
end
|
2958
3045
|
end
|