ruby_parser 3.17.0 → 3.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +76 -0
- data/Manifest.txt +3 -0
- data/README.rdoc +1 -0
- data/Rakefile +68 -18
- data/bin/ruby_parse_extract_error +1 -1
- data/compare/normalize.rb +6 -1
- data/gauntlet.md +106 -0
- data/lib/rp_extensions.rb +15 -36
- data/lib/rp_stringscanner.rb +20 -51
- data/lib/ruby20_parser.rb +3445 -3394
- data/lib/ruby20_parser.y +326 -248
- data/lib/ruby21_parser.rb +3543 -3511
- data/lib/ruby21_parser.y +321 -245
- data/lib/ruby22_parser.rb +3553 -3512
- data/lib/ruby22_parser.y +325 -247
- data/lib/ruby23_parser.rb +3566 -3530
- data/lib/ruby23_parser.y +325 -247
- data/lib/ruby24_parser.rb +3595 -3548
- data/lib/ruby24_parser.y +325 -247
- data/lib/ruby25_parser.rb +3595 -3547
- data/lib/ruby25_parser.y +325 -247
- data/lib/ruby26_parser.rb +3605 -3560
- data/lib/ruby26_parser.y +324 -246
- data/lib/ruby27_parser.rb +4657 -3539
- data/lib/ruby27_parser.y +878 -253
- data/lib/ruby30_parser.rb +5230 -3882
- data/lib/ruby30_parser.y +1069 -321
- data/lib/ruby3_parser.yy +3467 -0
- data/lib/ruby_lexer.rb +261 -609
- data/lib/ruby_lexer.rex +27 -20
- data/lib/ruby_lexer.rex.rb +59 -23
- data/lib/ruby_lexer_strings.rb +638 -0
- data/lib/ruby_parser.yy +910 -263
- data/lib/ruby_parser_extras.rb +289 -114
- data/test/test_ruby_lexer.rb +181 -129
- data/test/test_ruby_parser.rb +1213 -108
- data/tools/munge.rb +34 -6
- data/tools/ripper.rb +15 -10
- data.tar.gz.sig +0 -0
- metadata +11 -12
- metadata.gz.sig +0 -0
data/lib/ruby_parser_extras.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# TODO: remove encoding comment
|
3
4
|
|
4
5
|
require "sexp"
|
5
6
|
require "ruby_lexer"
|
@@ -29,7 +30,7 @@ class Sexp
|
|
29
30
|
end
|
30
31
|
|
31
32
|
module RubyParserStuff
|
32
|
-
VERSION = "3.
|
33
|
+
VERSION = "3.18.0"
|
33
34
|
|
34
35
|
attr_accessor :lexer, :in_def, :in_single, :file
|
35
36
|
attr_accessor :in_kwarg
|
@@ -155,11 +156,25 @@ module RubyParserStuff
|
|
155
156
|
end
|
156
157
|
|
157
158
|
args.each do |arg|
|
159
|
+
if arg.instance_of? Array and arg.size == 2 and arg.last.is_a? Numeric then
|
160
|
+
arg = arg.first
|
161
|
+
end
|
162
|
+
|
158
163
|
case arg
|
159
164
|
when Sexp then
|
160
165
|
case arg.sexp_type
|
161
166
|
when :args, :block, :array, :call_args then # HACK call_args mismatch
|
162
|
-
|
167
|
+
rest = arg.sexp_body
|
168
|
+
|
169
|
+
rest.map! { |x|
|
170
|
+
if x.instance_of? Array and x.size == 2 and Numeric === x.last then
|
171
|
+
x.first
|
172
|
+
else
|
173
|
+
x
|
174
|
+
end
|
175
|
+
}
|
176
|
+
|
177
|
+
result.concat rest
|
163
178
|
when :forward_args then
|
164
179
|
self.env[:*] = :lvar # TODO: arg_var(p, idFWD_REST) ?
|
165
180
|
self.env[:**] = :lvar
|
@@ -185,6 +200,8 @@ module RubyParserStuff
|
|
185
200
|
name = arg.to_s.delete("&*")
|
186
201
|
self.env[name.to_sym] = :lvar unless name.empty?
|
187
202
|
result << arg
|
203
|
+
when true, false then
|
204
|
+
self.in_kwarg = arg
|
188
205
|
when ",", "|", ";", "(", ")", nil then
|
189
206
|
# ignore
|
190
207
|
else
|
@@ -195,6 +212,23 @@ module RubyParserStuff
|
|
195
212
|
result
|
196
213
|
end
|
197
214
|
|
215
|
+
def end_args args
|
216
|
+
lexer.lex_state = RubyLexer::State::Values::EXPR_BEG
|
217
|
+
lexer.command_start = true
|
218
|
+
self.args args
|
219
|
+
end
|
220
|
+
|
221
|
+
def endless_method_name defn_or_defs
|
222
|
+
name = defn_or_defs[1]
|
223
|
+
name = defn_or_defs[2] unless Symbol === name
|
224
|
+
|
225
|
+
if name.end_with? "=" then
|
226
|
+
yyerror "setter method cannot be defined in an endless method definition"
|
227
|
+
end
|
228
|
+
|
229
|
+
# TODO? token_info_drop(p, "def", loc->beg_pos);
|
230
|
+
end
|
231
|
+
|
198
232
|
def array_to_hash array
|
199
233
|
case array.sexp_type
|
200
234
|
when :kwsplat then
|
@@ -214,17 +248,10 @@ module RubyParserStuff
|
|
214
248
|
end
|
215
249
|
|
216
250
|
def assignable(lhs, value = nil)
|
217
|
-
id = lhs
|
218
|
-
|
219
|
-
raise "WTF" if Sexp === id
|
220
|
-
id = id.to_sym if Sexp === id
|
221
|
-
|
222
|
-
raise "write a test 1" if id.to_s =~ /^(?:self|nil|true|false|__LINE__|__FILE__)$/
|
251
|
+
id, line = lhs
|
252
|
+
id = id.to_sym
|
223
253
|
|
224
|
-
|
225
|
-
id.to_s =~ /^(?:self|nil|true|false|__LINE__|__FILE__)$/
|
226
|
-
|
227
|
-
result = case id.to_s
|
254
|
+
result = case id
|
228
255
|
when /^@@/ then
|
229
256
|
asgn = in_def || in_single > 0
|
230
257
|
s((asgn ? :cvasgn : :cvdecl), id)
|
@@ -245,17 +272,9 @@ module RubyParserStuff
|
|
245
272
|
|
246
273
|
self.env[id] ||= :lvar if result.sexp_type == :lasgn
|
247
274
|
|
248
|
-
line = case lhs
|
249
|
-
when Sexp then
|
250
|
-
lhs.line
|
251
|
-
else
|
252
|
-
value && value.line || lexer.lineno
|
253
|
-
end
|
254
|
-
|
255
275
|
result << value if value
|
256
|
-
result.line
|
257
|
-
|
258
|
-
return result
|
276
|
+
result.line line
|
277
|
+
result
|
259
278
|
end
|
260
279
|
|
261
280
|
def backref_assign_error ref
|
@@ -279,9 +298,9 @@ module RubyParserStuff
|
|
279
298
|
line = [head.line, tail.line].compact.min
|
280
299
|
|
281
300
|
head = remove_begin(head)
|
282
|
-
head = s(:block, head) unless head.
|
301
|
+
head = s(:block, head).line(line) unless head.sexp_type == :block
|
283
302
|
|
284
|
-
head.line = line
|
303
|
+
# head.line = line
|
285
304
|
head << tail
|
286
305
|
end
|
287
306
|
|
@@ -307,6 +326,10 @@ module RubyParserStuff
|
|
307
326
|
end
|
308
327
|
|
309
328
|
args.each do |arg|
|
329
|
+
if arg.instance_of? Array and arg.size == 2 and arg.last.is_a? Numeric then
|
330
|
+
arg = arg.first
|
331
|
+
end
|
332
|
+
|
310
333
|
case arg
|
311
334
|
when Sexp then
|
312
335
|
case arg.sexp_type
|
@@ -317,6 +340,9 @@ module RubyParserStuff
|
|
317
340
|
end
|
318
341
|
when Symbol then
|
319
342
|
result << arg
|
343
|
+
when Array then
|
344
|
+
id, _line = arg
|
345
|
+
result << id
|
320
346
|
when ",", nil, "(" then
|
321
347
|
# ignore
|
322
348
|
else
|
@@ -441,7 +467,7 @@ module RubyParserStuff
|
|
441
467
|
end
|
442
468
|
else
|
443
469
|
warn "unprocessed: %p" % [s]
|
444
|
-
end.map { |l| whitespace_width l
|
470
|
+
end.map { |l| whitespace_width l.chomp }
|
445
471
|
}.compact.min
|
446
472
|
end
|
447
473
|
|
@@ -465,7 +491,6 @@ module RubyParserStuff
|
|
465
491
|
end
|
466
492
|
|
467
493
|
def gettable(id)
|
468
|
-
lineno = id.lineno if id.respond_to? :lineno
|
469
494
|
id = id.to_sym if String === id
|
470
495
|
|
471
496
|
result = case id.to_s
|
@@ -486,8 +511,6 @@ module RubyParserStuff
|
|
486
511
|
end
|
487
512
|
end
|
488
513
|
|
489
|
-
result.line lineno if lineno
|
490
|
-
|
491
514
|
raise "identifier #{id.inspect} is not valid" unless result
|
492
515
|
|
493
516
|
result
|
@@ -546,7 +569,7 @@ module RubyParserStuff
|
|
546
569
|
header.map! { |s| s.force_encoding "ASCII-8BIT" } if has_enc
|
547
570
|
|
548
571
|
first = header.first || ""
|
549
|
-
encoding, str = "utf-8", str.b[3..-1] if first =~ /\A\xEF\xBB\xBF/
|
572
|
+
encoding, str = +"utf-8", str.b[3..-1] if first =~ /\A\xEF\xBB\xBF/
|
550
573
|
|
551
574
|
encoding = $1.strip if header.find { |s|
|
552
575
|
s[/^#.*?-\*-.*?coding:\s*([^ ;]+).*?-\*-/, 1] ||
|
@@ -630,7 +653,7 @@ module RubyParserStuff
|
|
630
653
|
when :evstr then
|
631
654
|
if htype == :str then
|
632
655
|
f, l = head.file, head.line
|
633
|
-
head = s(:dstr, *head.sexp_body)
|
656
|
+
head = s(:dstr, *head.sexp_body)
|
634
657
|
head.file = f
|
635
658
|
head.line = l
|
636
659
|
end
|
@@ -649,6 +672,13 @@ module RubyParserStuff
|
|
649
672
|
return head
|
650
673
|
end
|
651
674
|
|
675
|
+
def local_pop in_def
|
676
|
+
lexer.cond.pop # group = local_pop
|
677
|
+
lexer.cmdarg.pop
|
678
|
+
self.env.unextend
|
679
|
+
self.in_def = in_def
|
680
|
+
end
|
681
|
+
|
652
682
|
def logical_op type, left, right
|
653
683
|
left = value_expr left
|
654
684
|
|
@@ -678,6 +708,73 @@ module RubyParserStuff
|
|
678
708
|
new_call val[0], :"[]", val[2]
|
679
709
|
end
|
680
710
|
|
711
|
+
def new_arg val
|
712
|
+
arg, = val
|
713
|
+
|
714
|
+
case arg
|
715
|
+
when Symbol then
|
716
|
+
result = s(:args, arg).line line
|
717
|
+
when Sexp then
|
718
|
+
result = arg
|
719
|
+
when Array then
|
720
|
+
(arg, line), = val
|
721
|
+
result = s(:args, arg).line line
|
722
|
+
else
|
723
|
+
debug20 32
|
724
|
+
raise "Unknown f_arg type: #{val.inspect}"
|
725
|
+
end
|
726
|
+
|
727
|
+
result
|
728
|
+
end
|
729
|
+
|
730
|
+
def new_array_pattern const, pre_arg, arypat, loc
|
731
|
+
result = s(:array_pat, const).line loc
|
732
|
+
result << pre_arg if pre_arg
|
733
|
+
|
734
|
+
if arypat && arypat.sexp_type == :array_TAIL then
|
735
|
+
result.concat arypat.sexp_body
|
736
|
+
else
|
737
|
+
raise "NO?: %p" % [arypat]
|
738
|
+
end
|
739
|
+
|
740
|
+
result
|
741
|
+
end
|
742
|
+
|
743
|
+
def array_pat_concat lhs, rhs
|
744
|
+
case lhs.sexp_type
|
745
|
+
when :PATTERN then
|
746
|
+
lhs.sexp_type = :array_pat
|
747
|
+
end
|
748
|
+
|
749
|
+
if rhs then
|
750
|
+
case rhs.sexp_type
|
751
|
+
when :array_pat, :array_TAIL, :PATTERN then
|
752
|
+
lhs.concat rhs.sexp_body
|
753
|
+
else
|
754
|
+
lhs << rhs
|
755
|
+
end
|
756
|
+
end
|
757
|
+
end
|
758
|
+
|
759
|
+
def new_array_pattern_tail pre_args, has_rest, rest_arg, post_args
|
760
|
+
# TODO: remove has_rest once all tests pass !!!
|
761
|
+
rest_arg = if has_rest then
|
762
|
+
:"*#{rest_arg}"
|
763
|
+
else
|
764
|
+
nil
|
765
|
+
end
|
766
|
+
|
767
|
+
result = s(:array_TAIL).line 666
|
768
|
+
|
769
|
+
array_pat_concat result, pre_args
|
770
|
+
|
771
|
+
result << rest_arg if rest_arg
|
772
|
+
|
773
|
+
array_pat_concat result, post_args
|
774
|
+
|
775
|
+
result
|
776
|
+
end
|
777
|
+
|
681
778
|
def new_assign lhs, rhs
|
682
779
|
return nil unless lhs
|
683
780
|
|
@@ -697,6 +794,8 @@ module RubyParserStuff
|
|
697
794
|
end
|
698
795
|
|
699
796
|
def new_attrasgn recv, meth, call_op = :"."
|
797
|
+
call_op = call_op.first if Array === call_op
|
798
|
+
|
700
799
|
meth = :"#{meth}="
|
701
800
|
|
702
801
|
result = case call_op.to_sym
|
@@ -761,6 +860,8 @@ module RubyParserStuff
|
|
761
860
|
end
|
762
861
|
|
763
862
|
def new_call recv, meth, args = nil, call_op = :"."
|
863
|
+
call_op = call_op.first if Array === call_op
|
864
|
+
|
764
865
|
result = case call_op.to_sym
|
765
866
|
when :"."
|
766
867
|
s(:call, recv, meth)
|
@@ -788,10 +889,14 @@ module RubyParserStuff
|
|
788
889
|
result
|
789
890
|
end
|
790
891
|
|
892
|
+
def new_in pat, body, cases, line
|
893
|
+
s(:in, pat, body, cases).line line
|
894
|
+
end
|
895
|
+
|
791
896
|
def new_case expr, body, line
|
792
897
|
result = s(:case, expr)
|
793
898
|
|
794
|
-
while body and body.
|
899
|
+
while body and [:when, :in].include? body.sexp_type
|
795
900
|
result << body
|
796
901
|
body = body.delete_at 3
|
797
902
|
end
|
@@ -810,8 +915,11 @@ module RubyParserStuff
|
|
810
915
|
end
|
811
916
|
|
812
917
|
def new_class val
|
918
|
+
# TODO: get line from class keyword
|
813
919
|
line, path, superclass, body = val[1], val[2], val[3], val[5]
|
814
920
|
|
921
|
+
path = path.first if path.instance_of? Array
|
922
|
+
|
815
923
|
result = s(:class, path, superclass)
|
816
924
|
|
817
925
|
if body then
|
@@ -834,7 +942,8 @@ module RubyParserStuff
|
|
834
942
|
end
|
835
943
|
|
836
944
|
def new_const_op_asgn val
|
837
|
-
lhs, asgn_op, rhs = val
|
945
|
+
lhs, (asgn_op, _), rhs = val
|
946
|
+
asgn_op = asgn_op.to_sym
|
838
947
|
|
839
948
|
result = case asgn_op
|
840
949
|
when :"||" then
|
@@ -850,55 +959,71 @@ module RubyParserStuff
|
|
850
959
|
end
|
851
960
|
|
852
961
|
def new_defn val
|
853
|
-
|
854
|
-
|
962
|
+
_, (name, line), in_def, args, body, _ = val
|
963
|
+
|
964
|
+
body ||= s(:nil).line line
|
855
965
|
|
856
966
|
args.line line
|
857
967
|
|
858
968
|
result = s(:defn, name.to_sym, args).line line
|
859
969
|
|
860
|
-
if body then
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
result.push body
|
865
|
-
end
|
970
|
+
if body.sexp_type == :block then
|
971
|
+
result.push(*body.sexp_body)
|
972
|
+
else
|
973
|
+
result.push body
|
866
974
|
end
|
867
975
|
|
868
976
|
result.comments = self.comments.pop
|
869
977
|
|
870
|
-
result
|
978
|
+
[result, in_def]
|
871
979
|
end
|
872
980
|
|
873
981
|
def new_defs val
|
874
|
-
_, recv,
|
982
|
+
_, recv, (name, line), in_def, args, body, _ = val
|
875
983
|
|
876
984
|
body ||= s(:nil).line line
|
877
985
|
|
878
986
|
args.line line
|
879
987
|
|
880
|
-
result = s(:defs, recv, name.to_sym, args)
|
988
|
+
result = s(:defs, recv, name.to_sym, args).line line
|
881
989
|
|
882
990
|
# TODO: remove_begin
|
883
991
|
# TODO: reduce_nodes
|
884
992
|
|
885
|
-
if body then
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
result.push body
|
890
|
-
end
|
993
|
+
if body.sexp_type == :block then
|
994
|
+
result.push(*body.sexp_body)
|
995
|
+
else
|
996
|
+
result.push body
|
891
997
|
end
|
892
998
|
|
893
|
-
result.line = recv.line
|
894
999
|
result.comments = self.comments.pop
|
895
|
-
|
1000
|
+
|
1001
|
+
[result, in_def]
|
896
1002
|
end
|
897
1003
|
|
898
1004
|
def new_do_body args, body, lineno
|
899
1005
|
new_iter(nil, args, body).line(lineno)
|
900
1006
|
end
|
901
1007
|
|
1008
|
+
def new_find_pattern const, pat
|
1009
|
+
pat.sexp_type = :find_pat
|
1010
|
+
pat.insert 1, const
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
def new_find_pattern_tail lhs, mid, rhs
|
1014
|
+
lhs_id, line = lhs
|
1015
|
+
rhs_id, _line = rhs
|
1016
|
+
|
1017
|
+
# TODO: fpinfo->pre_rest_arg = pre_rest_arg ? assignable(p, pre_rest_arg, 0, loc) : NODE_SPECIAL_NO_NAME_REST;
|
1018
|
+
|
1019
|
+
lhs_id = "*#{lhs_id}".to_sym
|
1020
|
+
rhs_id = "*#{rhs_id}".to_sym
|
1021
|
+
|
1022
|
+
mid.sexp_type = :array_pat # HACK?
|
1023
|
+
|
1024
|
+
s(:find_pat_TAIL, lhs_id, mid, rhs_id).line line
|
1025
|
+
end
|
1026
|
+
|
902
1027
|
def new_for expr, var, body
|
903
1028
|
result = s(:for, expr, var).line(var.line)
|
904
1029
|
result << body if body
|
@@ -908,7 +1033,47 @@ module RubyParserStuff
|
|
908
1033
|
def new_hash val
|
909
1034
|
_, line, assocs = val
|
910
1035
|
|
911
|
-
s(:hash).line(line).concat assocs.
|
1036
|
+
s(:hash).line(line).concat assocs.sexp_body
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
def new_hash_pattern const, hash_pat, loc
|
1040
|
+
_, pat, kw_args, kw_rest_arg = hash_pat
|
1041
|
+
|
1042
|
+
line = (const||hash_pat).line
|
1043
|
+
|
1044
|
+
result = s(:hash_pat, const).line line
|
1045
|
+
result.concat pat.sexp_body if pat
|
1046
|
+
result << kw_args if kw_args
|
1047
|
+
result << kw_rest_arg if kw_rest_arg
|
1048
|
+
result
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
def new_hash_pattern_tail kw_args, kw_rest_arg, line # TODO: remove line arg
|
1052
|
+
# kw_rest_arg = assignable(kw_rest_arg, nil).line line if kw_rest_arg
|
1053
|
+
|
1054
|
+
result = s(:hash_pat).line line
|
1055
|
+
result << kw_args
|
1056
|
+
|
1057
|
+
if kw_rest_arg then
|
1058
|
+
name = kw_rest_arg.value
|
1059
|
+
# TODO: I _hate_ this:
|
1060
|
+
assignable [name, kw_rest_arg.line] if name != :**
|
1061
|
+
result << kw_rest_arg
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
result
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
def push_pktbl
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
def pop_pktbl
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
def push_pvtbl
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
def pop_pvtbl
|
912
1077
|
end
|
913
1078
|
|
914
1079
|
def new_if c, t, f
|
@@ -985,9 +1150,12 @@ module RubyParserStuff
|
|
985
1150
|
end
|
986
1151
|
|
987
1152
|
def new_module val
|
1153
|
+
# TODO: get line from module keyword
|
988
1154
|
line, path, body = val[1], val[2], val[4]
|
989
1155
|
|
990
|
-
|
1156
|
+
path = path.first if path.instance_of? Array
|
1157
|
+
|
1158
|
+
result = s(:module, path).line line
|
991
1159
|
|
992
1160
|
if body then # REFACTOR?
|
993
1161
|
if body.sexp_type == :block then
|
@@ -997,32 +1165,33 @@ module RubyParserStuff
|
|
997
1165
|
end
|
998
1166
|
end
|
999
1167
|
|
1000
|
-
result.line = line
|
1001
1168
|
result.comments = self.comments.pop
|
1002
1169
|
result
|
1003
1170
|
end
|
1004
1171
|
|
1005
1172
|
def new_op_asgn val
|
1006
|
-
lhs,
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1173
|
+
lhs, (op, _line), rhs = val
|
1174
|
+
op = op.to_sym
|
1175
|
+
|
1176
|
+
name = gettable(lhs.last).line lhs.line
|
1177
|
+
arg = remove_begin rhs
|
1178
|
+
result = case op # REFACTOR
|
1010
1179
|
when :"||" then
|
1011
1180
|
lhs << arg
|
1012
|
-
s(:op_asgn_or, name, lhs)
|
1181
|
+
s(:op_asgn_or, name, lhs).line lhs.line
|
1013
1182
|
when :"&&" then
|
1014
1183
|
lhs << arg
|
1015
|
-
s(:op_asgn_and, name, lhs)
|
1184
|
+
s(:op_asgn_and, name, lhs).line lhs.line
|
1016
1185
|
else
|
1017
|
-
lhs << new_call(name,
|
1186
|
+
lhs << new_call(name, op, argl(arg))
|
1018
1187
|
lhs
|
1019
1188
|
end
|
1020
|
-
|
1189
|
+
|
1021
1190
|
result
|
1022
1191
|
end
|
1023
1192
|
|
1024
1193
|
def new_op_asgn1 val
|
1025
|
-
lhs, _, args, _, op, rhs = val
|
1194
|
+
lhs, _, args, _, (op, _), rhs = val
|
1026
1195
|
|
1027
1196
|
args.sexp_type = :arglist if args
|
1028
1197
|
|
@@ -1032,7 +1201,7 @@ module RubyParserStuff
|
|
1032
1201
|
end
|
1033
1202
|
|
1034
1203
|
def new_op_asgn2 val
|
1035
|
-
recv, call_op, meth, op, arg = val
|
1204
|
+
recv, (call_op, _), (meth, _), (op, _), arg = val
|
1036
1205
|
meth = :"#{meth}="
|
1037
1206
|
|
1038
1207
|
result = case call_op.to_sym
|
@@ -1049,36 +1218,28 @@ module RubyParserStuff
|
|
1049
1218
|
end
|
1050
1219
|
|
1051
1220
|
def new_qsym_list
|
1052
|
-
|
1053
|
-
self.lexer.fixup_lineno
|
1054
|
-
result
|
1221
|
+
s(:array).line lexer.lineno
|
1055
1222
|
end
|
1056
1223
|
|
1057
1224
|
def new_qsym_list_entry val
|
1058
|
-
_, str, _ = val
|
1059
|
-
|
1060
|
-
self.lexer.fixup_lineno
|
1061
|
-
result
|
1225
|
+
_, (str, line), _ = val
|
1226
|
+
s(:lit, str.to_sym).line line
|
1062
1227
|
end
|
1063
1228
|
|
1064
1229
|
def new_qword_list
|
1065
|
-
|
1066
|
-
self.lexer.fixup_lineno
|
1067
|
-
result
|
1230
|
+
s(:array).line lexer.lineno
|
1068
1231
|
end
|
1069
1232
|
|
1070
1233
|
def new_qword_list_entry val
|
1071
|
-
_, str, _ = val
|
1234
|
+
_, (str, line), _ = val
|
1072
1235
|
str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
|
1073
|
-
|
1074
|
-
self.lexer.fixup_lineno
|
1075
|
-
result
|
1236
|
+
s(:str, str).line line
|
1076
1237
|
end
|
1077
1238
|
|
1078
1239
|
def new_regexp val
|
1079
|
-
_, node, options = val
|
1240
|
+
(_, line), node, (options, _) = val
|
1080
1241
|
|
1081
|
-
node ||= s(:str, "").line
|
1242
|
+
node ||= s(:str, "").line line
|
1082
1243
|
|
1083
1244
|
o, k = 0, nil
|
1084
1245
|
options.split(//).uniq.each do |c| # FIX: this has a better home
|
@@ -1105,12 +1266,12 @@ module RubyParserStuff
|
|
1105
1266
|
begin
|
1106
1267
|
Regexp.new(node[1], o)
|
1107
1268
|
rescue RegexpError => e
|
1108
|
-
warn "
|
1269
|
+
warn "WARNING: #{e.message} for #{node[1].inspect} #{options.inspect}"
|
1109
1270
|
begin
|
1110
|
-
warn "
|
1271
|
+
warn "WARNING: trying to recover with ENC_UTF8"
|
1111
1272
|
Regexp.new(node[1], Regexp::ENC_UTF8)
|
1112
1273
|
rescue RegexpError => e
|
1113
|
-
warn "
|
1274
|
+
warn "WARNING: trying to recover with ENC_NONE"
|
1114
1275
|
Regexp.new(node[1], Regexp::ENC_NONE)
|
1115
1276
|
end
|
1116
1277
|
end
|
@@ -1123,7 +1284,7 @@ module RubyParserStuff
|
|
1123
1284
|
end
|
1124
1285
|
node << o if o and o != 0
|
1125
1286
|
else
|
1126
|
-
node = s(:dregx, "", node).line
|
1287
|
+
node = s(:dregx, "", node).line line
|
1127
1288
|
node.sexp_type = :dregx_once if options =~ /o/
|
1128
1289
|
node << o if o and o != 0
|
1129
1290
|
end
|
@@ -1165,17 +1326,16 @@ module RubyParserStuff
|
|
1165
1326
|
end
|
1166
1327
|
|
1167
1328
|
def new_string val
|
1168
|
-
str, = val
|
1329
|
+
(str, line), = val
|
1330
|
+
|
1169
1331
|
str.force_encoding("UTF-8")
|
1170
1332
|
# TODO: remove:
|
1171
1333
|
str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
|
1172
|
-
|
1173
|
-
self.lexer.fixup_lineno str.count("\n")
|
1174
|
-
result
|
1334
|
+
s(:str, str).line line
|
1175
1335
|
end
|
1176
1336
|
|
1177
1337
|
def new_super args
|
1178
|
-
if args && args.
|
1338
|
+
if args && args.sexp_type == :block_pass then
|
1179
1339
|
s(:super, args).line args.line
|
1180
1340
|
else
|
1181
1341
|
args ||= s(:arglist).line lexer.lineno
|
@@ -1183,32 +1343,30 @@ module RubyParserStuff
|
|
1183
1343
|
end
|
1184
1344
|
end
|
1185
1345
|
|
1346
|
+
def new_symbol val
|
1347
|
+
name = val.last
|
1348
|
+
s(:lit, name.to_sym).line lexer.lineno
|
1349
|
+
end
|
1350
|
+
|
1186
1351
|
def new_symbol_list
|
1187
|
-
|
1188
|
-
|
1189
|
-
result
|
1352
|
+
# TODO: hunt down and try to remove ALL lexer.lineno usage!
|
1353
|
+
s(:array).line lexer.lineno
|
1190
1354
|
end
|
1191
1355
|
|
1192
1356
|
def new_symbol_list_entry val
|
1193
1357
|
_, sym, _ = val
|
1194
1358
|
|
1195
|
-
sym ||= s(:str, "")
|
1196
|
-
|
1197
|
-
line = lexer.lineno
|
1359
|
+
sym ||= s(:str, "").line lexer.lineno
|
1198
1360
|
|
1199
1361
|
case sym.sexp_type
|
1200
1362
|
when :dstr then
|
1201
1363
|
sym.sexp_type = :dsym
|
1202
1364
|
when :str then
|
1203
|
-
sym = s(:lit, sym.last.to_sym)
|
1365
|
+
sym = s(:lit, sym.last.to_sym).line sym.line
|
1204
1366
|
else
|
1205
|
-
sym = s(:dsym, "", sym
|
1367
|
+
sym = s(:dsym, "", sym).line sym.line
|
1206
1368
|
end
|
1207
1369
|
|
1208
|
-
sym.line line
|
1209
|
-
|
1210
|
-
self.lexer.fixup_lineno
|
1211
|
-
|
1212
1370
|
sym
|
1213
1371
|
end
|
1214
1372
|
|
@@ -1250,16 +1408,12 @@ module RubyParserStuff
|
|
1250
1408
|
end
|
1251
1409
|
|
1252
1410
|
def new_word_list
|
1253
|
-
|
1254
|
-
self.lexer.fixup_lineno
|
1255
|
-
result
|
1411
|
+
s(:array).line lexer.lineno
|
1256
1412
|
end
|
1257
1413
|
|
1258
1414
|
def new_word_list_entry val
|
1259
1415
|
_, word, _ = val
|
1260
|
-
|
1261
|
-
self.lexer.fixup_lineno
|
1262
|
-
result
|
1416
|
+
word.sexp_type == :evstr ? s(:dstr, "", word).line(word.line) : word
|
1263
1417
|
end
|
1264
1418
|
|
1265
1419
|
def new_xstring val
|
@@ -1283,9 +1437,9 @@ module RubyParserStuff
|
|
1283
1437
|
|
1284
1438
|
def new_yield args = nil
|
1285
1439
|
# TODO: raise args.inspect unless [:arglist].include? args.first # HACK
|
1286
|
-
raise "write a test 4" if args && args.
|
1440
|
+
raise "write a test 4" if args && args.sexp_type == :block_pass
|
1287
1441
|
raise SyntaxError, "Block argument should not be given." if
|
1288
|
-
args && args.
|
1442
|
+
args && args.sexp_type == :block_pass
|
1289
1443
|
|
1290
1444
|
args ||= s(:arglist).line lexer.lineno
|
1291
1445
|
|
@@ -1295,18 +1449,30 @@ module RubyParserStuff
|
|
1295
1449
|
s(:yield, *args.sexp_body).line args.line
|
1296
1450
|
end
|
1297
1451
|
|
1452
|
+
def prev_value_to_lineno v
|
1453
|
+
s, n = v
|
1454
|
+
if String === s then
|
1455
|
+
n
|
1456
|
+
else
|
1457
|
+
lexer.lineno
|
1458
|
+
end
|
1459
|
+
end
|
1460
|
+
|
1298
1461
|
def next_token
|
1299
1462
|
token = self.lexer.next_token
|
1300
1463
|
|
1301
1464
|
if token and token.first != RubyLexer::EOF then
|
1302
1465
|
self.last_token_type = token
|
1303
1466
|
return token
|
1467
|
+
elsif !token
|
1468
|
+
return self.lexer.next_token
|
1304
1469
|
else
|
1305
1470
|
return [false, false]
|
1306
1471
|
end
|
1307
1472
|
end
|
1308
1473
|
|
1309
1474
|
def on_error(et, ev, values)
|
1475
|
+
ev = ev.first if ev.instance_of?(Array) && ev.size == 2 && ev.last.is_a?(Integer)
|
1310
1476
|
super
|
1311
1477
|
rescue Racc::ParseError => e
|
1312
1478
|
# I don't like how the exception obscures the error message
|
@@ -1320,18 +1486,17 @@ module RubyParserStuff
|
|
1320
1486
|
# Timeout::Error if it runs for more than +time+ seconds.
|
1321
1487
|
|
1322
1488
|
def process(str, file = "(string)", time = 10)
|
1489
|
+
str.freeze
|
1490
|
+
|
1323
1491
|
Timeout.timeout time do
|
1324
1492
|
raise "bad val: #{str.inspect}" unless String === str
|
1325
1493
|
|
1326
|
-
|
1494
|
+
self.lexer.string = handle_encoding str
|
1327
1495
|
|
1328
1496
|
self.file = file.dup
|
1329
1497
|
|
1330
1498
|
@yydebug = ENV.has_key? "DEBUG"
|
1331
1499
|
|
1332
|
-
# HACK -- need to get tests passing more than have graceful code
|
1333
|
-
self.lexer.ss = RPStringScanner.new str
|
1334
|
-
|
1335
1500
|
do_parse
|
1336
1501
|
end
|
1337
1502
|
end
|
@@ -1387,6 +1552,14 @@ module RubyParserStuff
|
|
1387
1552
|
result
|
1388
1553
|
end
|
1389
1554
|
|
1555
|
+
def debug n
|
1556
|
+
if ENV["PRY"] then
|
1557
|
+
require "pry"; binding.pry
|
1558
|
+
end
|
1559
|
+
|
1560
|
+
raise RubyParser::SyntaxError, "debug #{n}"
|
1561
|
+
end
|
1562
|
+
|
1390
1563
|
def syntax_error msg
|
1391
1564
|
raise RubyParser::SyntaxError, msg
|
1392
1565
|
end
|
@@ -1431,6 +1604,8 @@ module RubyParserStuff
|
|
1431
1604
|
|
1432
1605
|
if remove_width then
|
1433
1606
|
line[idx..-1]
|
1607
|
+
elsif line[idx].nil?
|
1608
|
+
nil
|
1434
1609
|
else
|
1435
1610
|
col
|
1436
1611
|
end
|