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