ruby_parser 3.12.0 → 3.13.0
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 +47 -0
- data/Manifest.txt +5 -4
- data/Rakefile +41 -28
- data/compare/normalize.rb +29 -2
- data/debugging.md +18 -0
- data/lib/rp_extensions.rb +0 -7
- data/lib/ruby20_parser.rb +3689 -3502
- data/lib/ruby20_parser.y +284 -201
- data/lib/ruby21_parser.rb +3755 -3570
- data/lib/ruby21_parser.y +281 -197
- data/lib/ruby22_parser.rb +3780 -3600
- data/lib/ruby22_parser.y +281 -202
- data/lib/ruby23_parser.rb +3755 -3591
- data/lib/ruby23_parser.y +282 -203
- data/lib/ruby24_parser.rb +3755 -3591
- data/lib/ruby24_parser.y +282 -203
- data/lib/ruby25_parser.rb +3754 -3591
- data/lib/ruby25_parser.y +282 -203
- data/lib/ruby26_parser.rb +6999 -0
- data/lib/{ruby19_parser.y → ruby26_parser.y} +658 -305
- data/lib/ruby_lexer.rb +116 -118
- data/lib/ruby_lexer.rex +10 -8
- data/lib/ruby_lexer.rex.rb +8 -8
- data/lib/ruby_parser.rb +5 -7
- data/lib/ruby_parser.yy +308 -218
- data/lib/ruby_parser_extras.rb +88 -106
- data/test/test_ruby_lexer.rb +68 -121
- data/test/test_ruby_parser.rb +173 -277
- data/tools/munge.rb +216 -0
- data/tools/ripper.rb +23 -0
- metadata +18 -17
- metadata.gz.sig +1 -1
- data/lib/ruby18_parser.rb +0 -5793
- data/lib/ruby18_parser.y +0 -1908
- data/lib/ruby19_parser.rb +0 -6185
data/lib/ruby_parser_extras.rb
CHANGED
@@ -7,9 +7,10 @@ require "rp_extensions"
|
|
7
7
|
require "rp_stringscanner"
|
8
8
|
|
9
9
|
module RubyParserStuff
|
10
|
-
VERSION = "3.
|
10
|
+
VERSION = "3.13.0"
|
11
11
|
|
12
12
|
attr_accessor :lexer, :in_def, :in_single, :file
|
13
|
+
attr_accessor :in_kwarg
|
13
14
|
attr_reader :env, :comments
|
14
15
|
|
15
16
|
$good20 = []
|
@@ -90,23 +91,6 @@ module RubyParserStuff
|
|
90
91
|
result
|
91
92
|
end
|
92
93
|
|
93
|
-
def block_var18 ary, splat, block
|
94
|
-
ary ||= s(:array)
|
95
|
-
|
96
|
-
if splat then
|
97
|
-
splat = splat[1] unless Symbol === splat
|
98
|
-
ary << "*#{splat}".to_sym
|
99
|
-
end
|
100
|
-
|
101
|
-
ary << "&#{block[1]}".to_sym if block
|
102
|
-
|
103
|
-
if ary.length > 2 or ary.splat then # HACK
|
104
|
-
s(:masgn, *ary.sexp_body)
|
105
|
-
else
|
106
|
-
ary.last
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
94
|
def array_to_hash array
|
111
95
|
case array.sexp_type
|
112
96
|
when :kwsplat then
|
@@ -152,8 +136,10 @@ module RubyParserStuff
|
|
152
136
|
when :block_arg then
|
153
137
|
result << :"&#{arg.last}"
|
154
138
|
when :shadow then
|
139
|
+
name = arg.last
|
140
|
+
self.env[name] = :lvar
|
155
141
|
if Sexp === result.last and result.last.sexp_type == :shadow then
|
156
|
-
result.last <<
|
142
|
+
result.last << name
|
157
143
|
else
|
158
144
|
result << arg
|
159
145
|
end
|
@@ -288,9 +274,6 @@ module RubyParserStuff
|
|
288
274
|
return new_call(lhs, :"=~", argl(rhs)).line(lhs.line)
|
289
275
|
end
|
290
276
|
|
291
|
-
# TODO: remove in 4.0 or 2018-01, whichever is first
|
292
|
-
deprecate :get_match_node, :new_match
|
293
|
-
|
294
277
|
def gettable(id)
|
295
278
|
lineno = id.lineno if id.respond_to? :lineno
|
296
279
|
id = id.to_sym if String === id
|
@@ -334,10 +317,12 @@ module RubyParserStuff
|
|
334
317
|
def initialize(options = {})
|
335
318
|
super()
|
336
319
|
|
337
|
-
v = self.class.name[/
|
320
|
+
v = self.class.name[/2\d/]
|
321
|
+
raise "Bad Class name #{self.class}" unless v
|
338
322
|
|
339
323
|
self.lexer = RubyLexer.new v && v.to_i
|
340
324
|
self.lexer.parser = self
|
325
|
+
self.in_kwarg = false
|
341
326
|
|
342
327
|
@env = RubyParserStuff::Environment.new
|
343
328
|
@comments = []
|
@@ -431,9 +416,6 @@ module RubyParserStuff
|
|
431
416
|
return s(type, left, right)
|
432
417
|
end
|
433
418
|
|
434
|
-
# TODO: remove in 4.0 or 2018-01, whichever is first
|
435
|
-
deprecate :logop, :logical_op
|
436
|
-
|
437
419
|
def new_aref val
|
438
420
|
val[2] ||= s(:arglist)
|
439
421
|
val[2].sexp_type = :arglist if val[2].sexp_type == :array # REFACTOR
|
@@ -472,6 +454,10 @@ module RubyParserStuff
|
|
472
454
|
result
|
473
455
|
end
|
474
456
|
|
457
|
+
def new_brace_body args, body, lineno
|
458
|
+
new_iter(nil, args, body).line(lineno)
|
459
|
+
end
|
460
|
+
|
475
461
|
def argl x
|
476
462
|
x = s(:arglist, x) if x and x.sexp_type == :array
|
477
463
|
x
|
@@ -580,7 +566,7 @@ module RubyParserStuff
|
|
580
566
|
end
|
581
567
|
|
582
568
|
def new_defn val
|
583
|
-
(_, line), name, _, args, body, * = val
|
569
|
+
(_, line), (name, _), _, args, body, * = val
|
584
570
|
body ||= s(:nil)
|
585
571
|
|
586
572
|
result = s(:defn, name.to_sym, args)
|
@@ -601,7 +587,7 @@ module RubyParserStuff
|
|
601
587
|
end
|
602
588
|
|
603
589
|
def new_defs val
|
604
|
-
recv, name, args, body = val[1], val[4], val[6], val[7]
|
590
|
+
recv, (name, _line), args, body = val[1], val[4], val[6], val[7]
|
605
591
|
body ||= s(:nil)
|
606
592
|
|
607
593
|
result = s(:defs, recv, name.to_sym, args)
|
@@ -619,6 +605,10 @@ module RubyParserStuff
|
|
619
605
|
result
|
620
606
|
end
|
621
607
|
|
608
|
+
def new_do_body args, body, lineno
|
609
|
+
new_iter(nil, args, body).line(lineno)
|
610
|
+
end
|
611
|
+
|
622
612
|
def new_for expr, var, body
|
623
613
|
result = s(:for, expr, var).line(var.line)
|
624
614
|
result << body if body
|
@@ -743,9 +733,6 @@ module RubyParserStuff
|
|
743
733
|
}[c]
|
744
734
|
raise "unknown regexp option: #{c}" unless v
|
745
735
|
o += v
|
746
|
-
|
747
|
-
# encoding options are ignored on 1.9+
|
748
|
-
k = c if c =~ /[esu]/ if RUBY_VERSION < "1.9"
|
749
736
|
end
|
750
737
|
|
751
738
|
case node.sexp_type
|
@@ -783,6 +770,10 @@ module RubyParserStuff
|
|
783
770
|
node
|
784
771
|
end
|
785
772
|
|
773
|
+
def new_rescue body, resbody
|
774
|
+
s(:rescue, body, resbody)
|
775
|
+
end
|
776
|
+
|
786
777
|
def new_resbody cond, body
|
787
778
|
if body && body.sexp_type == :block then
|
788
779
|
body.shift # remove block and splat it in directly
|
@@ -813,7 +804,7 @@ module RubyParserStuff
|
|
813
804
|
|
814
805
|
def new_string val
|
815
806
|
str = val[0]
|
816
|
-
str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
|
807
|
+
str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
|
817
808
|
result = s(:str, str)
|
818
809
|
self.lexer.fixup_lineno str.count("\n")
|
819
810
|
result
|
@@ -821,7 +812,7 @@ module RubyParserStuff
|
|
821
812
|
|
822
813
|
def new_qword_list_entry val
|
823
814
|
str = val[1]
|
824
|
-
str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
|
815
|
+
str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
|
825
816
|
result = s(:str, str)
|
826
817
|
self.lexer.fixup_lineno
|
827
818
|
result
|
@@ -875,7 +866,6 @@ module RubyParserStuff
|
|
875
866
|
when :str then
|
876
867
|
sym = s(:lit, sym.last.to_sym)
|
877
868
|
else
|
878
|
-
debug20 24
|
879
869
|
sym = s(:dsym, "", sym || s(:str, ""))
|
880
870
|
end
|
881
871
|
self.lexer.fixup_lineno
|
@@ -986,9 +976,6 @@ module RubyParserStuff
|
|
986
976
|
lhs
|
987
977
|
end
|
988
978
|
|
989
|
-
# TODO: remove in 4.0 or 2018-01, whichever is first
|
990
|
-
deprecate :node_assign, :new_assign
|
991
|
-
|
992
979
|
##
|
993
980
|
# Returns a UTF-8 encoded string after processing BOMs and magic
|
994
981
|
# encoding comments.
|
@@ -1145,7 +1132,7 @@ module RubyParserStuff
|
|
1145
1132
|
result
|
1146
1133
|
end
|
1147
1134
|
|
1148
|
-
def value_expr oldnode # HACK
|
1135
|
+
def value_expr oldnode # HACK: much more to do
|
1149
1136
|
node = remove_begin oldnode
|
1150
1137
|
node.line = oldnode.line if oldnode
|
1151
1138
|
node[2] = value_expr node[2] if node and node.sexp_type == :if
|
@@ -1193,82 +1180,71 @@ module RubyParserStuff
|
|
1193
1180
|
##
|
1194
1181
|
# :stopdoc:
|
1195
1182
|
#
|
1196
|
-
# :expr_beg
|
1197
|
-
# :expr_end
|
1198
|
-
# :
|
1199
|
-
# :
|
1200
|
-
# :
|
1201
|
-
# :
|
1202
|
-
# :
|
1203
|
-
# :
|
1204
|
-
# :
|
1183
|
+
# :expr_beg = ignore newline, +/- is a sign.
|
1184
|
+
# :expr_end = newline significant, +/- is an operator.
|
1185
|
+
# :expr_endarg = ditto, and unbound braces.
|
1186
|
+
# :expr_endfn = ditto, and unbound braces.
|
1187
|
+
# :expr_arg = newline significant, +/- is an operator.
|
1188
|
+
# :expr_cmdarg = ditto
|
1189
|
+
# :expr_mid = ditto
|
1190
|
+
# :expr_fname = ignore newline, no reserved words.
|
1191
|
+
# :expr_dot = right after . or ::, no reserved words.
|
1192
|
+
# :expr_class = immediate after class, no here document.
|
1193
|
+
# :expr_label = flag bit, label is allowed.
|
1194
|
+
# :expr_labeled = flag bit, just after a label.
|
1195
|
+
# :expr_fitem = symbol literal as FNAME.
|
1196
|
+
# :expr_value = :expr_beg -- work to remove. Need multi-state support.
|
1205
1197
|
|
1206
1198
|
wordlist = [
|
1207
|
-
["
|
1208
|
-
["
|
1199
|
+
["alias", [:kALIAS, :kALIAS ], :expr_fname ],
|
1200
|
+
["and", [:kAND, :kAND ], :expr_beg ],
|
1201
|
+
["begin", [:kBEGIN, :kBEGIN ], :expr_beg ],
|
1202
|
+
["break", [:kBREAK, :kBREAK ], :expr_mid ],
|
1209
1203
|
["case", [:kCASE, :kCASE ], :expr_beg ],
|
1204
|
+
["class", [:kCLASS, :kCLASS ], :expr_class ],
|
1205
|
+
["def", [:kDEF, :kDEF ], :expr_fname ],
|
1206
|
+
["defined?", [:kDEFINED, :kDEFINED ], :expr_arg ],
|
1207
|
+
["do", [:kDO, :kDO ], :expr_beg ],
|
1208
|
+
["else", [:kELSE, :kELSE ], :expr_beg ],
|
1209
|
+
["elsif", [:kELSIF, :kELSIF ], :expr_beg ],
|
1210
|
+
["end", [:kEND, :kEND ], :expr_end ],
|
1210
1211
|
["ensure", [:kENSURE, :kENSURE ], :expr_beg ],
|
1212
|
+
["false", [:kFALSE, :kFALSE ], :expr_end ],
|
1213
|
+
["for", [:kFOR, :kFOR ], :expr_beg ],
|
1214
|
+
["if", [:kIF, :kIF_MOD ], :expr_beg ],
|
1215
|
+
["in", [:kIN, :kIN ], :expr_beg ],
|
1211
1216
|
["module", [:kMODULE, :kMODULE ], :expr_beg ],
|
1212
|
-
["
|
1213
|
-
["
|
1217
|
+
["next", [:kNEXT, :kNEXT ], :expr_mid ],
|
1218
|
+
["nil", [:kNIL, :kNIL ], :expr_end ],
|
1219
|
+
["not", [:kNOT, :kNOT ], :expr_arg ],
|
1220
|
+
["or", [:kOR, :kOR ], :expr_beg ],
|
1221
|
+
["redo", [:kREDO, :kREDO ], :expr_end ],
|
1214
1222
|
["rescue", [:kRESCUE, :kRESCUE_MOD ], :expr_mid ],
|
1215
|
-
["not", [:kNOT, :kNOT ], :expr_beg ],
|
1216
|
-
["then", [:kTHEN, :kTHEN ], :expr_beg ],
|
1217
|
-
["yield", [:kYIELD, :kYIELD ], :expr_arg ],
|
1218
|
-
["for", [:kFOR, :kFOR ], :expr_beg ],
|
1219
|
-
["self", [:kSELF, :kSELF ], :expr_end ],
|
1220
|
-
["false", [:kFALSE, :kFALSE ], :expr_end ],
|
1221
1223
|
["retry", [:kRETRY, :kRETRY ], :expr_end ],
|
1222
1224
|
["return", [:kRETURN, :kRETURN ], :expr_mid ],
|
1223
|
-
["
|
1224
|
-
["if", [:kIF, :kIF_MOD ], :expr_beg ],
|
1225
|
-
["defined?", [:kDEFINED, :kDEFINED ], :expr_arg ],
|
1225
|
+
["self", [:kSELF, :kSELF ], :expr_end ],
|
1226
1226
|
["super", [:kSUPER, :kSUPER ], :expr_arg ],
|
1227
|
+
["then", [:kTHEN, :kTHEN ], :expr_beg ],
|
1228
|
+
["true", [:kTRUE, :kTRUE ], :expr_end ],
|
1227
1229
|
["undef", [:kUNDEF, :kUNDEF ], :expr_fname ],
|
1228
|
-
["break", [:kBREAK, :kBREAK ], :expr_mid ],
|
1229
|
-
["in", [:kIN, :kIN ], :expr_beg ],
|
1230
|
-
["do", [:kDO, :kDO ], :expr_beg ],
|
1231
|
-
["nil", [:kNIL, :kNIL ], :expr_end ],
|
1232
|
-
["until", [:kUNTIL, :kUNTIL_MOD ], :expr_beg ],
|
1233
1230
|
["unless", [:kUNLESS, :kUNLESS_MOD ], :expr_beg ],
|
1234
|
-
["
|
1235
|
-
["next", [:kNEXT, :kNEXT ], :expr_mid ],
|
1231
|
+
["until", [:kUNTIL, :kUNTIL_MOD ], :expr_beg ],
|
1236
1232
|
["when", [:kWHEN, :kWHEN ], :expr_beg ],
|
1237
|
-
["redo", [:kREDO, :kREDO ], :expr_end ],
|
1238
|
-
["and", [:kAND, :kAND ], :expr_beg ],
|
1239
|
-
["begin", [:kBEGIN, :kBEGIN ], :expr_beg ],
|
1240
|
-
["__LINE__", [:k__LINE__, :k__LINE__ ], :expr_end ],
|
1241
|
-
["class", [:kCLASS, :kCLASS ], :expr_class ],
|
1242
|
-
["__FILE__", [:k__FILE__, :k__FILE__ ], :expr_end ],
|
1243
|
-
["END", [:klEND, :klEND ], :expr_end ],
|
1244
|
-
["BEGIN", [:klBEGIN, :klBEGIN ], :expr_end ],
|
1245
1233
|
["while", [:kWHILE, :kWHILE_MOD ], :expr_beg ],
|
1246
|
-
["
|
1234
|
+
["yield", [:kYIELD, :kYIELD ], :expr_arg ],
|
1235
|
+
["BEGIN", [:klBEGIN, :klBEGIN ], :expr_end ],
|
1236
|
+
["END", [:klEND, :klEND ], :expr_end ],
|
1237
|
+
["__FILE__", [:k__FILE__, :k__FILE__ ], :expr_end ],
|
1238
|
+
["__LINE__", [:k__LINE__, :k__LINE__ ], :expr_end ],
|
1247
1239
|
["__ENCODING__", [:k__ENCODING__, :k__ENCODING__], :expr_end],
|
1248
1240
|
].map { |args| KWtable.new(*args) }
|
1249
1241
|
|
1250
1242
|
# :startdoc:
|
1251
1243
|
|
1252
|
-
|
1253
|
-
WORDLIST19 = Hash[*wordlist.map { |o| [o.name, o] }.flatten]
|
1244
|
+
WORDLIST = Hash[*wordlist.map { |o| [o.name, o] }.flatten]
|
1254
1245
|
|
1255
|
-
|
1256
|
-
|
1257
|
-
%w[and case elsif for if in module or unless until when while].each do |k|
|
1258
|
-
WORDLIST19[k] = WORDLIST19[k].dup
|
1259
|
-
WORDLIST19[k].state = :expr_value
|
1260
|
-
end
|
1261
|
-
%w[not].each do |k|
|
1262
|
-
WORDLIST19[k] = WORDLIST19[k].dup
|
1263
|
-
WORDLIST19[k].state = :expr_arg
|
1264
|
-
end
|
1265
|
-
|
1266
|
-
def self.keyword18 str # REFACTOR
|
1267
|
-
WORDLIST18[str]
|
1268
|
-
end
|
1269
|
-
|
1270
|
-
def self.keyword19 str
|
1271
|
-
WORDLIST19[str]
|
1246
|
+
def self.keyword str
|
1247
|
+
WORDLIST[str]
|
1272
1248
|
end
|
1273
1249
|
end
|
1274
1250
|
|
@@ -1330,7 +1306,7 @@ module RubyParserStuff
|
|
1330
1306
|
|
1331
1307
|
def reset
|
1332
1308
|
@stack = [false]
|
1333
|
-
|
1309
|
+
log :reset if debug
|
1334
1310
|
end
|
1335
1311
|
|
1336
1312
|
def inspect
|
@@ -1338,41 +1314,47 @@ module RubyParserStuff
|
|
1338
1314
|
end
|
1339
1315
|
|
1340
1316
|
def is_in_state
|
1317
|
+
log :is_in_state if debug
|
1341
1318
|
@stack.last
|
1342
1319
|
end
|
1343
1320
|
|
1344
1321
|
def lexpop
|
1345
|
-
warn "#{name}_stack.lexpop" if debug
|
1346
1322
|
raise if @stack.size == 0
|
1347
1323
|
a = @stack.pop
|
1348
1324
|
b = @stack.pop
|
1349
1325
|
@stack.push(a || b)
|
1326
|
+
log :lexpop if debug
|
1327
|
+
end
|
1328
|
+
|
1329
|
+
def log action
|
1330
|
+
c = caller[1]
|
1331
|
+
c = caller[2] if c =~ /expr_result/
|
1332
|
+
warn "%s_stack.%s: %p at %s" % [name, action, @stack, c.clean_caller]
|
1333
|
+
nil
|
1350
1334
|
end
|
1351
1335
|
|
1352
1336
|
def pop
|
1353
1337
|
r = @stack.pop
|
1354
|
-
|
1355
|
-
|
1338
|
+
@stack.push false if @stack.empty?
|
1339
|
+
log :pop if debug
|
1356
1340
|
r
|
1357
1341
|
end
|
1358
1342
|
|
1359
1343
|
def push val
|
1360
1344
|
@stack.push val
|
1361
|
-
|
1362
|
-
c = caller.first
|
1363
|
-
c = caller[1] if c =~ /expr_result/
|
1364
|
-
warn "#{name}_stack(push): #{val} at line #{c.clean_caller}"
|
1365
|
-
nil
|
1345
|
+
log :push if debug
|
1366
1346
|
end
|
1367
1347
|
|
1368
|
-
def store
|
1348
|
+
def store base = false
|
1369
1349
|
result = @stack.dup
|
1370
|
-
@stack.replace [
|
1350
|
+
@stack.replace [base]
|
1351
|
+
log :store if debug
|
1371
1352
|
result
|
1372
1353
|
end
|
1373
1354
|
|
1374
1355
|
def restore oldstate
|
1375
1356
|
@stack.replace oldstate
|
1357
|
+
log :restore if debug
|
1376
1358
|
end
|
1377
1359
|
end
|
1378
1360
|
end
|
data/test/test_ruby_lexer.rb
CHANGED
@@ -51,10 +51,6 @@ class TestRubyLexer < Minitest::Test
|
|
51
51
|
assert_lex(input, exp_sexp, *args, &block)
|
52
52
|
end
|
53
53
|
|
54
|
-
def ruby18
|
55
|
-
RubyParser::V18 === lexer.parser
|
56
|
-
end
|
57
|
-
|
58
54
|
def refute_lex input, *args # TODO: re-sort
|
59
55
|
args = args.each_slice(2).map { |a, b| [a, b, nil, nil, nil] }.flatten
|
60
56
|
|
@@ -141,7 +137,7 @@ class TestRubyLexer < Minitest::Test
|
|
141
137
|
yield
|
142
138
|
|
143
139
|
lexer.lex_state = :expr_endarg
|
144
|
-
assert_next_lexeme :
|
140
|
+
assert_next_lexeme :tSTRING_DEND, "}", :expr_endarg, 0
|
145
141
|
|
146
142
|
lexer.lex_strterm = lex_strterm
|
147
143
|
lexer.lex_state = :expr_beg
|
@@ -304,44 +300,23 @@ class TestRubyLexer < Minitest::Test
|
|
304
300
|
assert_lex3("=>", nil, :tASSOC, "=>", :expr_beg)
|
305
301
|
end
|
306
302
|
|
307
|
-
def
|
308
|
-
setup_lexer_class RubyParser::
|
309
|
-
|
310
|
-
assert_lex3("{a:",
|
311
|
-
nil,
|
312
|
-
:tLBRACE, "{", :expr_beg,
|
313
|
-
:tIDENTIFIER, "a", :expr_arg,
|
314
|
-
:tSYMBEG, ":", :expr_fname)
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_yylex_label_in_params__18
|
318
|
-
setup_lexer_class RubyParser::V18
|
319
|
-
|
320
|
-
assert_lex3("foo(a:",
|
321
|
-
nil,
|
322
|
-
:tIDENTIFIER, "foo", :expr_cmdarg,
|
323
|
-
:tLPAREN2, "(", :expr_beg,
|
324
|
-
:tIDENTIFIER, "a", :expr_cmdarg,
|
325
|
-
:tSYMBEG, ":", :expr_fname)
|
326
|
-
end
|
327
|
-
|
328
|
-
def test_yylex_label__19
|
329
|
-
setup_lexer_class RubyParser::V19
|
303
|
+
def test_yylex_label__20
|
304
|
+
setup_lexer_class RubyParser::V20
|
330
305
|
|
331
306
|
assert_lex3("{a:",
|
332
307
|
nil,
|
333
308
|
:tLBRACE, "{", :expr_beg,
|
334
|
-
:tLABEL, "a", :
|
309
|
+
:tLABEL, "a", :expr_labeled)
|
335
310
|
end
|
336
311
|
|
337
|
-
def
|
338
|
-
setup_lexer_class RubyParser::
|
312
|
+
def test_yylex_label_in_params__20
|
313
|
+
setup_lexer_class RubyParser::V20
|
339
314
|
|
340
315
|
assert_lex3("foo(a:",
|
341
316
|
nil,
|
342
317
|
:tIDENTIFIER, "foo", :expr_cmdarg,
|
343
318
|
:tLPAREN2, "(", :expr_beg,
|
344
|
-
:tLABEL, "a", :
|
319
|
+
:tLABEL, "a", :expr_labeled)
|
345
320
|
end
|
346
321
|
|
347
322
|
def test_yylex_paren_string_parens_interpolated
|
@@ -357,13 +332,13 @@ class TestRubyLexer < Minitest::Test
|
|
357
332
|
assert_next_lexeme :tSTRING_DBEG, nil, :expr_beg, 0, 0
|
358
333
|
|
359
334
|
emulate_string_interpolation do
|
360
|
-
assert_next_lexeme :tIDENTIFIER, "b", :
|
335
|
+
assert_next_lexeme :tIDENTIFIER, "b", :expr_cmdarg, 0, 0
|
361
336
|
end
|
362
337
|
|
363
338
|
assert_next_lexeme :tSTRING_DBEG, nil, :expr_beg, 0, 0
|
364
339
|
|
365
340
|
emulate_string_interpolation do
|
366
|
-
assert_next_lexeme :tIDENTIFIER, "d", :
|
341
|
+
assert_next_lexeme :tIDENTIFIER, "d", :expr_cmdarg, 0, 0
|
367
342
|
end
|
368
343
|
|
369
344
|
assert_next_lexeme :tSTRING_CONTENT, ")", :expr_beg, 0, 0
|
@@ -503,7 +478,7 @@ class TestRubyLexer < Minitest::Test
|
|
503
478
|
:tLAMBDA, nil, :expr_endfn,
|
504
479
|
:kDO, "do", :expr_beg,
|
505
480
|
:kEND, "end", :expr_end,
|
506
|
-
:
|
481
|
+
:kDO, "do", :expr_beg,
|
507
482
|
:kEND, "end", :expr_end)
|
508
483
|
end
|
509
484
|
|
@@ -712,6 +687,39 @@ class TestRubyLexer < Minitest::Test
|
|
712
687
|
assert_lex3("!~", nil, :tNMATCH, "!~", :expr_beg)
|
713
688
|
end
|
714
689
|
|
690
|
+
def test_yylex_block_bug_1
|
691
|
+
assert_lex3("a do end",
|
692
|
+
s(:iter, s(:call, nil, :a), 0),
|
693
|
+
|
694
|
+
:tIDENTIFIER, "a", :expr_cmdarg,
|
695
|
+
:kDO, "do", :expr_beg,
|
696
|
+
:kEND, "end", :expr_end)
|
697
|
+
end
|
698
|
+
|
699
|
+
def test_yylex_block_bug_2
|
700
|
+
assert_lex3("a = 1\na do\nend",
|
701
|
+
s(:block,
|
702
|
+
s(:lasgn, :a, s(:lit, 1)),
|
703
|
+
s(:iter, s(:call, nil, :a), 0)),
|
704
|
+
|
705
|
+
:tIDENTIFIER, "a", :expr_cmdarg,
|
706
|
+
:tEQL, "=", :expr_beg,
|
707
|
+
:tINTEGER, 1, :expr_end,
|
708
|
+
:tNL, nil, :expr_beg,
|
709
|
+
:tIDENTIFIER, "a", :expr_cmdarg,
|
710
|
+
:kDO, "do", :expr_beg,
|
711
|
+
:kEND, "end", :expr_end)
|
712
|
+
end
|
713
|
+
|
714
|
+
def test_yylex_block_bug_3
|
715
|
+
assert_lex3("a { }",
|
716
|
+
s(:iter, s(:call, nil, :a), 0),
|
717
|
+
|
718
|
+
:tIDENTIFIER, "a", :expr_cmdarg, # verified
|
719
|
+
:tLCURLY, "{", :expr_beg, # TODO: expr_beg|expr_label
|
720
|
+
:tRCURLY, "}", :expr_endarg)
|
721
|
+
end
|
722
|
+
|
715
723
|
def test_yylex_carat
|
716
724
|
assert_lex3("^", nil, :tCARET, "^", :expr_beg)
|
717
725
|
end
|
@@ -731,8 +739,8 @@ class TestRubyLexer < Minitest::Test
|
|
731
739
|
def test_yylex_colon2_argh
|
732
740
|
assert_lex3("module X::Y\n c\nend",
|
733
741
|
nil,
|
734
|
-
:kMODULE, "module", :
|
735
|
-
:tCONSTANT, "X", :
|
742
|
+
:kMODULE, "module", :expr_beg,
|
743
|
+
:tCONSTANT, "X", :expr_cmdarg,
|
736
744
|
:tCOLON2, "::", :expr_dot,
|
737
745
|
:tCONSTANT, "Y", :expr_arg,
|
738
746
|
:tNL, nil, :expr_beg,
|
@@ -1369,14 +1377,8 @@ class TestRubyLexer < Minitest::Test
|
|
1369
1377
|
assert_lex_fname "<=>", :tCMP
|
1370
1378
|
end
|
1371
1379
|
|
1372
|
-
def
|
1373
|
-
setup_lexer_class RubyParser::
|
1374
|
-
|
1375
|
-
assert_lex_fname "identifier", :tIDENTIFIER, :expr_end
|
1376
|
-
end
|
1377
|
-
|
1378
|
-
def test_yylex_identifier_def__1920
|
1379
|
-
setup_lexer_class RubyParser::V19
|
1380
|
+
def test_yylex_identifier_def__20
|
1381
|
+
setup_lexer_class RubyParser::V20
|
1380
1382
|
|
1381
1383
|
assert_lex_fname "identifier", :tIDENTIFIER, :expr_endfn
|
1382
1384
|
end
|
@@ -1412,14 +1414,8 @@ class TestRubyLexer < Minitest::Test
|
|
1412
1414
|
assert_lex_fname "^", :tCARET
|
1413
1415
|
end
|
1414
1416
|
|
1415
|
-
def
|
1416
|
-
setup_lexer_class RubyParser::
|
1417
|
-
|
1418
|
-
assert_lex_fname "identifier=", :tIDENTIFIER, :expr_end
|
1419
|
-
end
|
1420
|
-
|
1421
|
-
def test_yylex_identifier_equals_def__1920
|
1422
|
-
setup_lexer_class RubyParser::V19
|
1417
|
+
def test_yylex_identifier_equals_def__20
|
1418
|
+
setup_lexer_class RubyParser::V20
|
1423
1419
|
|
1424
1420
|
assert_lex_fname "identifier=", :tIDENTIFIER, :expr_endfn
|
1425
1421
|
end
|
@@ -1521,26 +1517,14 @@ class TestRubyLexer < Minitest::Test
|
|
1521
1517
|
:kIF_MOD, "if", :expr_beg)
|
1522
1518
|
end
|
1523
1519
|
|
1524
|
-
def
|
1525
|
-
setup_lexer_class RubyParser::
|
1526
|
-
|
1527
|
-
assert_lex3("?a", nil, :tINTEGER, 97, :expr_end)
|
1528
|
-
end
|
1529
|
-
|
1530
|
-
def test_yylex_question_eh_a__19
|
1531
|
-
setup_lexer_class RubyParser::V19
|
1520
|
+
def test_yylex_question_eh_a__20
|
1521
|
+
setup_lexer_class RubyParser::V20
|
1532
1522
|
|
1533
1523
|
assert_lex3("?a", nil, :tSTRING, "a", :expr_end)
|
1534
1524
|
end
|
1535
1525
|
|
1536
|
-
def
|
1537
|
-
setup_lexer_class RubyParser::
|
1538
|
-
|
1539
|
-
assert_lex3("?\\M-\\C-a", nil, :tINTEGER, 129, :expr_end)
|
1540
|
-
end
|
1541
|
-
|
1542
|
-
def test_yylex_question_eh_escape_M_escape_C__19
|
1543
|
-
setup_lexer_class RubyParser::V19
|
1526
|
+
def test_yylex_question_eh_escape_M_escape_C__20
|
1527
|
+
setup_lexer_class RubyParser::V20
|
1544
1528
|
|
1545
1529
|
assert_lex3("?\\M-\\C-a", nil, :tSTRING, "\M-\C-a", :expr_end)
|
1546
1530
|
end
|
@@ -1724,15 +1708,8 @@ class TestRubyLexer < Minitest::Test
|
|
1724
1708
|
assert_lex3(" (", nil, :tLPAREN_ARG, "(", :expr_beg)
|
1725
1709
|
end
|
1726
1710
|
|
1727
|
-
def
|
1728
|
-
setup_lexer_class RubyParser::
|
1729
|
-
self.lex_state = :expr_arg
|
1730
|
-
|
1731
|
-
assert_lex3(" (", nil, :tLPAREN2, "(", :expr_beg)
|
1732
|
-
end
|
1733
|
-
|
1734
|
-
def test_yylex_open_bracket_exprarg__19
|
1735
|
-
setup_lexer_class RubyParser::V19
|
1711
|
+
def test_yylex_open_bracket_exprarg__20
|
1712
|
+
setup_lexer_class RubyParser::V20
|
1736
1713
|
self.lex_state = :expr_arg
|
1737
1714
|
|
1738
1715
|
assert_lex3(" (", nil, :tLPAREN_ARG, "(", :expr_beg)
|
@@ -1896,18 +1873,6 @@ class TestRubyLexer < Minitest::Test
|
|
1896
1873
|
assert_lex3("+42", nil, :tINTEGER, 42, :expr_end)
|
1897
1874
|
end
|
1898
1875
|
|
1899
|
-
def test_yylex_question__18
|
1900
|
-
setup_lexer_class RubyParser::V18
|
1901
|
-
|
1902
|
-
assert_lex3("?*", nil, :tINTEGER, 42, :expr_end)
|
1903
|
-
end
|
1904
|
-
|
1905
|
-
def test_yylex_question__19
|
1906
|
-
setup_lexer_class RubyParser::V19
|
1907
|
-
|
1908
|
-
assert_lex3("?*", nil, :tSTRING, "*", :expr_end)
|
1909
|
-
end
|
1910
|
-
|
1911
1876
|
def test_yylex_question_bad_eos
|
1912
1877
|
refute_lex "?"
|
1913
1878
|
end
|
@@ -1921,19 +1886,8 @@ class TestRubyLexer < Minitest::Test
|
|
1921
1886
|
assert_lex3("?\f", nil, :tEH, "?", :expr_value)
|
1922
1887
|
end
|
1923
1888
|
|
1924
|
-
def
|
1925
|
-
setup_lexer_class RubyParser::
|
1926
|
-
|
1927
|
-
assert_lex3("?\\ ", nil, :tINTEGER, 32, :expr_end)
|
1928
|
-
assert_lex3("?\\n", nil, :tINTEGER, 10, :expr_end)
|
1929
|
-
assert_lex3("?\\t", nil, :tINTEGER, 9, :expr_end)
|
1930
|
-
assert_lex3("?\\v", nil, :tINTEGER, 11, :expr_end)
|
1931
|
-
assert_lex3("?\\r", nil, :tINTEGER, 13, :expr_end)
|
1932
|
-
assert_lex3("?\\f", nil, :tINTEGER, 12, :expr_end)
|
1933
|
-
end
|
1934
|
-
|
1935
|
-
def test_yylex_question_ws_backslashed__19
|
1936
|
-
setup_lexer_class RubyParser::V19
|
1889
|
+
def test_yylex_question_ws_backslashed__20
|
1890
|
+
setup_lexer_class RubyParser::V20
|
1937
1891
|
|
1938
1892
|
assert_lex3("?\\ ", nil, :tSTRING, " ", :expr_end)
|
1939
1893
|
assert_lex3("?\\n", nil, :tSTRING, "\n", :expr_end)
|
@@ -1948,7 +1902,9 @@ class TestRubyLexer < Minitest::Test
|
|
1948
1902
|
end
|
1949
1903
|
|
1950
1904
|
def test_yylex_rcurly
|
1951
|
-
|
1905
|
+
assert_lex("}", nil, :tRCURLY, "}", :expr_endarg, 0, 1) do
|
1906
|
+
lexer.brace_nest += 2
|
1907
|
+
end
|
1952
1908
|
end
|
1953
1909
|
|
1954
1910
|
def test_yylex_regexp
|
@@ -2434,8 +2390,6 @@ class TestRubyLexer < Minitest::Test
|
|
2434
2390
|
end
|
2435
2391
|
|
2436
2392
|
def test_yylex_string_double_pound_dollar_bad
|
2437
|
-
skip if ruby18
|
2438
|
-
|
2439
2393
|
assert_lex3('"#$%"', nil,
|
2440
2394
|
|
2441
2395
|
:tSTRING_BEG, "\"", :expr_beg,
|
@@ -2619,12 +2573,6 @@ class TestRubyLexer < Minitest::Test
|
|
2619
2573
|
assert_lex3(":symbol", nil, :tSYMBOL, "symbol", :expr_end)
|
2620
2574
|
end
|
2621
2575
|
|
2622
|
-
def test_yylex_symbol_zero_byte__18
|
2623
|
-
setup_lexer_class RubyParser::V18
|
2624
|
-
|
2625
|
-
refute_lex(":\"symbol\0\"", :tSYMBEG, ":")
|
2626
|
-
end
|
2627
|
-
|
2628
2576
|
def test_yylex_symbol_zero_byte
|
2629
2577
|
assert_lex(":\"symbol\0\"", nil,
|
2630
2578
|
:tSYMBOL, "symbol\0", :expr_end)
|
@@ -2791,7 +2739,7 @@ class TestRubyLexer < Minitest::Test
|
|
2791
2739
|
s(:hash, s(:lit, :a), s(:lit, 1)),
|
2792
2740
|
|
2793
2741
|
:tLBRACE, "{", :expr_beg, 0, 1,
|
2794
|
-
:tLABEL, "a", :
|
2742
|
+
:tLABEL, "a", :expr_labeled, 0, 1,
|
2795
2743
|
:tINTEGER, 1, :expr_end, 0, 1,
|
2796
2744
|
:tRCURLY, "}", :expr_endarg, 0, 0)
|
2797
2745
|
end
|
@@ -2803,7 +2751,7 @@ class TestRubyLexer < Minitest::Test
|
|
2803
2751
|
s(:hash, s(:lit, :a), s(:lit, 1)),
|
2804
2752
|
|
2805
2753
|
:tLBRACE, "{", :expr_beg, 0, 1,
|
2806
|
-
:tLABEL, "a", :
|
2754
|
+
:tLABEL, "a", :expr_labeled, 0, 1,
|
2807
2755
|
:tINTEGER, 1, :expr_end, 0, 1,
|
2808
2756
|
:tRCURLY, "}", :expr_endarg, 0, 0)
|
2809
2757
|
end
|
@@ -2815,7 +2763,7 @@ class TestRubyLexer < Minitest::Test
|
|
2815
2763
|
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
2816
2764
|
|
2817
2765
|
:tLBRACE, "{", :expr_beg, 0, 1,
|
2818
|
-
:tLABEL, "abc", :
|
2766
|
+
:tLABEL, "abc", :expr_labeled, 0, 1,
|
2819
2767
|
:tSYMBOL, "b", :expr_end, 0, 1,
|
2820
2768
|
:tRCURLY, "}", :expr_endarg, 0, 0)
|
2821
2769
|
end
|
@@ -2827,7 +2775,7 @@ class TestRubyLexer < Minitest::Test
|
|
2827
2775
|
s(:hash, s(:lit, :abc), s(:lit, :b)),
|
2828
2776
|
|
2829
2777
|
:tLBRACE, "{", :expr_beg, 0, 1,
|
2830
|
-
:tLABEL, "abc", :
|
2778
|
+
:tLABEL, "abc", :expr_labeled, 0, 1,
|
2831
2779
|
:tSYMBOL, "b", :expr_end, 0, 1,
|
2832
2780
|
:tRCURLY, "}", :expr_endarg, 0, 0)
|
2833
2781
|
end
|
@@ -2839,10 +2787,9 @@ class TestRubyLexer < Minitest::Test
|
|
2839
2787
|
nil,
|
2840
2788
|
:kDEF, "def", :expr_fname,
|
2841
2789
|
:tIDENTIFIER, "foo", :expr_endfn,
|
2842
|
-
:tLABEL, "a", :
|
2790
|
+
:tLABEL, "a", :expr_labeled,
|
2843
2791
|
:tCOMMA, ",", :expr_beg,
|
2844
|
-
:tLABEL, "b", :
|
2845
|
-
:tNL, nil, :expr_beg,
|
2792
|
+
:tLABEL, "b", :expr_labeled,
|
2846
2793
|
:kEND, "end", :expr_end)
|
2847
2794
|
end
|
2848
2795
|
|
@@ -2853,7 +2800,7 @@ class TestRubyLexer < Minitest::Test
|
|
2853
2800
|
nil,
|
2854
2801
|
|
2855
2802
|
:tLBRACE, "{", :expr_beg,
|
2856
|
-
:tLABEL, "s\tr\i\ng\\foo'bar", :
|
2803
|
+
:tLABEL, "s\tr\i\ng\\foo'bar", :expr_labeled,
|
2857
2804
|
:tINTEGER, 1, :expr_end,
|
2858
2805
|
:tRCURLY, "}", :expr_endarg)
|
2859
2806
|
end
|
@@ -2865,7 +2812,7 @@ class TestRubyLexer < Minitest::Test
|
|
2865
2812
|
nil,
|
2866
2813
|
|
2867
2814
|
:tLBRACE, "{", :expr_beg,
|
2868
|
-
:tLABEL, "s\\tr\\i\\ng\\foo'bar", :
|
2815
|
+
:tLABEL, "s\\tr\\i\\ng\\foo'bar", :expr_labeled,
|
2869
2816
|
:tINTEGER, 1, :expr_end,
|
2870
2817
|
:tRCURLY, "}", :expr_endarg)
|
2871
2818
|
end
|