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