ruby_parser 3.15.0 → 3.18.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  # encoding: ASCII-8BIT
2
- # TODO: remove
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.15.0"
33
+ VERSION = "3.18.0"
33
34
 
34
35
  attr_accessor :lexer, :in_def, :in_single, :file
35
36
  attr_accessor :in_kwarg
@@ -115,7 +116,7 @@ module RubyParserStuff
115
116
  def initialize(options = {})
116
117
  super()
117
118
 
118
- v = self.class.name[/2\d/]
119
+ v = self.class.name[/[23]\d/]
119
120
  raise "Bad Class name #{self.class}" unless v
120
121
 
121
122
  self.lexer = RubyLexer.new v && v.to_i
@@ -155,11 +156,31 @@ 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
- result.concat arg.sexp_body
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
178
+ when :forward_args then
179
+ self.env[:*] = :lvar # TODO: arg_var(p, idFWD_REST) ?
180
+ self.env[:**] = :lvar
181
+ self.env[:&] = :lvar
182
+
183
+ result << arg
163
184
  when :block_arg then
164
185
  result << :"&#{arg.last}"
165
186
  when :shadow then
@@ -179,6 +200,8 @@ module RubyParserStuff
179
200
  name = arg.to_s.delete("&*")
180
201
  self.env[name.to_sym] = :lvar unless name.empty?
181
202
  result << arg
203
+ when true, false then
204
+ self.in_kwarg = arg
182
205
  when ",", "|", ";", "(", ")", nil then
183
206
  # ignore
184
207
  else
@@ -189,6 +212,23 @@ module RubyParserStuff
189
212
  result
190
213
  end
191
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
+
192
232
  def array_to_hash array
193
233
  case array.sexp_type
194
234
  when :kwsplat then
@@ -208,17 +248,10 @@ module RubyParserStuff
208
248
  end
209
249
 
210
250
  def assignable(lhs, value = nil)
211
- id = lhs.to_sym unless Sexp === lhs
212
-
213
- raise "WTF" if Sexp === id
214
- id = id.to_sym if Sexp === id
215
-
216
- raise "write a test 1" if id.to_s =~ /^(?:self|nil|true|false|__LINE__|__FILE__)$/
251
+ id, line = lhs
252
+ id = id.to_sym
217
253
 
218
- raise SyntaxError, "Can't change the value of #{id}" if
219
- id.to_s =~ /^(?:self|nil|true|false|__LINE__|__FILE__)$/
220
-
221
- result = case id.to_s
254
+ result = case id
222
255
  when /^@@/ then
223
256
  asgn = in_def || in_single > 0
224
257
  s((asgn ? :cvasgn : :cvdecl), id)
@@ -239,17 +272,9 @@ module RubyParserStuff
239
272
 
240
273
  self.env[id] ||= :lvar if result.sexp_type == :lasgn
241
274
 
242
- line = case lhs
243
- when Sexp then
244
- lhs.line
245
- else
246
- value && value.line || lexer.lineno
247
- end
248
-
249
275
  result << value if value
250
- result.line = line
251
-
252
- return result
276
+ result.line line
277
+ result
253
278
  end
254
279
 
255
280
  def backref_assign_error ref
@@ -273,9 +298,9 @@ module RubyParserStuff
273
298
  line = [head.line, tail.line].compact.min
274
299
 
275
300
  head = remove_begin(head)
276
- head = s(:block, head) unless head.node_type == :block
301
+ head = s(:block, head).line(line) unless head.sexp_type == :block
277
302
 
278
- head.line = line
303
+ # head.line = line
279
304
  head << tail
280
305
  end
281
306
 
@@ -301,6 +326,10 @@ module RubyParserStuff
301
326
  end
302
327
 
303
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
+
304
333
  case arg
305
334
  when Sexp then
306
335
  case arg.sexp_type
@@ -311,7 +340,10 @@ module RubyParserStuff
311
340
  end
312
341
  when Symbol then
313
342
  result << arg
314
- when ",", nil then
343
+ when Array then
344
+ id, _line = arg
345
+ result << id
346
+ when ",", nil, "(" then
315
347
  # ignore
316
348
  else
317
349
  raise "unhandled: #{arg.inspect} in #{args.inspect}"
@@ -435,7 +467,7 @@ module RubyParserStuff
435
467
  end
436
468
  else
437
469
  warn "unprocessed: %p" % [s]
438
- end.map { |l| whitespace_width l[/^[ \t]*/] }
470
+ end.map { |l| whitespace_width l.chomp }
439
471
  }.compact.min
440
472
  end
441
473
 
@@ -459,7 +491,6 @@ module RubyParserStuff
459
491
  end
460
492
 
461
493
  def gettable(id)
462
- lineno = id.lineno if id.respond_to? :lineno
463
494
  id = id.to_sym if String === id
464
495
 
465
496
  result = case id.to_s
@@ -480,8 +511,6 @@ module RubyParserStuff
480
511
  end
481
512
  end
482
513
 
483
- result.line lineno if lineno
484
-
485
514
  raise "identifier #{id.inspect} is not valid" unless result
486
515
 
487
516
  result
@@ -540,7 +569,7 @@ module RubyParserStuff
540
569
  header.map! { |s| s.force_encoding "ASCII-8BIT" } if has_enc
541
570
 
542
571
  first = header.first || ""
543
- 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/
544
573
 
545
574
  encoding = $1.strip if header.find { |s|
546
575
  s[/^#.*?-\*-.*?coding:\s*([^ ;]+).*?-\*-/, 1] ||
@@ -624,7 +653,7 @@ module RubyParserStuff
624
653
  when :evstr then
625
654
  if htype == :str then
626
655
  f, l = head.file, head.line
627
- head = s(:dstr, *head.sexp_body).line head.line
656
+ head = s(:dstr, *head.sexp_body)
628
657
  head.file = f
629
658
  head.line = l
630
659
  end
@@ -643,6 +672,13 @@ module RubyParserStuff
643
672
  return head
644
673
  end
645
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
+
646
682
  def logical_op type, left, right
647
683
  left = value_expr left
648
684
 
@@ -672,6 +708,73 @@ module RubyParserStuff
672
708
  new_call val[0], :"[]", val[2]
673
709
  end
674
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
+
675
778
  def new_assign lhs, rhs
676
779
  return nil unless lhs
677
780
 
@@ -691,6 +794,8 @@ module RubyParserStuff
691
794
  end
692
795
 
693
796
  def new_attrasgn recv, meth, call_op = :"."
797
+ call_op = call_op.first if Array === call_op
798
+
694
799
  meth = :"#{meth}="
695
800
 
696
801
  result = case call_op.to_sym
@@ -755,6 +860,8 @@ module RubyParserStuff
755
860
  end
756
861
 
757
862
  def new_call recv, meth, args = nil, call_op = :"."
863
+ call_op = call_op.first if Array === call_op
864
+
758
865
  result = case call_op.to_sym
759
866
  when :"."
760
867
  s(:call, recv, meth)
@@ -782,10 +889,14 @@ module RubyParserStuff
782
889
  result
783
890
  end
784
891
 
892
+ def new_in pat, body, cases, line
893
+ s(:in, pat, body, cases).line line
894
+ end
895
+
785
896
  def new_case expr, body, line
786
897
  result = s(:case, expr)
787
898
 
788
- while body and body.node_type == :when
899
+ while body and [:when, :in].include? body.sexp_type
789
900
  result << body
790
901
  body = body.delete_at 3
791
902
  end
@@ -804,8 +915,11 @@ module RubyParserStuff
804
915
  end
805
916
 
806
917
  def new_class val
918
+ # TODO: get line from class keyword
807
919
  line, path, superclass, body = val[1], val[2], val[3], val[5]
808
920
 
921
+ path = path.first if path.instance_of? Array
922
+
809
923
  result = s(:class, path, superclass)
810
924
 
811
925
  if body then
@@ -828,7 +942,8 @@ module RubyParserStuff
828
942
  end
829
943
 
830
944
  def new_const_op_asgn val
831
- lhs, asgn_op, rhs = val[0], val[1].to_sym, val[2]
945
+ lhs, (asgn_op, _), rhs = val
946
+ asgn_op = asgn_op.to_sym
832
947
 
833
948
  result = case asgn_op
834
949
  when :"||" then
@@ -844,55 +959,71 @@ module RubyParserStuff
844
959
  end
845
960
 
846
961
  def new_defn val
847
- (_, line), name, _, args, body, nil_body_line, * = val
848
- body ||= s(:nil).line nil_body_line
962
+ _, (name, line), in_def, args, body, _ = val
963
+
964
+ body ||= s(:nil).line line
849
965
 
850
966
  args.line line
851
967
 
852
968
  result = s(:defn, name.to_sym, args).line line
853
969
 
854
- if body then
855
- if body.sexp_type == :block then
856
- result.push(*body.sexp_body)
857
- else
858
- result.push body
859
- end
970
+ if body.sexp_type == :block then
971
+ result.push(*body.sexp_body)
972
+ else
973
+ result.push body
860
974
  end
861
975
 
862
976
  result.comments = self.comments.pop
863
977
 
864
- result
978
+ [result, in_def]
865
979
  end
866
980
 
867
981
  def new_defs val
868
- _, recv, _, _, name, (_in_def, line), args, body, _ = val
982
+ _, recv, (name, line), in_def, args, body, _ = val
869
983
 
870
984
  body ||= s(:nil).line line
871
985
 
872
986
  args.line line
873
987
 
874
- result = s(:defs, recv, name.to_sym, args)
988
+ result = s(:defs, recv, name.to_sym, args).line line
875
989
 
876
990
  # TODO: remove_begin
877
991
  # TODO: reduce_nodes
878
992
 
879
- if body then
880
- if body.sexp_type == :block then
881
- result.push(*body.sexp_body)
882
- else
883
- result.push body
884
- end
993
+ if body.sexp_type == :block then
994
+ result.push(*body.sexp_body)
995
+ else
996
+ result.push body
885
997
  end
886
998
 
887
- result.line = recv.line
888
999
  result.comments = self.comments.pop
889
- result
1000
+
1001
+ [result, in_def]
890
1002
  end
891
1003
 
892
1004
  def new_do_body args, body, lineno
893
1005
  new_iter(nil, args, body).line(lineno)
894
1006
  end
895
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
+
896
1027
  def new_for expr, var, body
897
1028
  result = s(:for, expr, var).line(var.line)
898
1029
  result << body if body
@@ -902,7 +1033,47 @@ module RubyParserStuff
902
1033
  def new_hash val
903
1034
  _, line, assocs = val
904
1035
 
905
- s(:hash).line(line).concat assocs.values
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
906
1077
  end
907
1078
 
908
1079
  def new_if c, t, f
@@ -979,9 +1150,12 @@ module RubyParserStuff
979
1150
  end
980
1151
 
981
1152
  def new_module val
1153
+ # TODO: get line from module keyword
982
1154
  line, path, body = val[1], val[2], val[4]
983
1155
 
984
- result = s(:module, path)
1156
+ path = path.first if path.instance_of? Array
1157
+
1158
+ result = s(:module, path).line line
985
1159
 
986
1160
  if body then # REFACTOR?
987
1161
  if body.sexp_type == :block then
@@ -991,32 +1165,33 @@ module RubyParserStuff
991
1165
  end
992
1166
  end
993
1167
 
994
- result.line = line
995
1168
  result.comments = self.comments.pop
996
1169
  result
997
1170
  end
998
1171
 
999
1172
  def new_op_asgn val
1000
- lhs, asgn_op, arg = val[0], val[1].to_sym, val[2]
1001
- name = gettable(lhs.value).line lhs.line
1002
- arg = remove_begin(arg)
1003
- result = case asgn_op # REFACTOR
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
1004
1179
  when :"||" then
1005
1180
  lhs << arg
1006
- s(:op_asgn_or, name, lhs)
1181
+ s(:op_asgn_or, name, lhs).line lhs.line
1007
1182
  when :"&&" then
1008
1183
  lhs << arg
1009
- s(:op_asgn_and, name, lhs)
1184
+ s(:op_asgn_and, name, lhs).line lhs.line
1010
1185
  else
1011
- lhs << new_call(name, asgn_op, argl(arg))
1186
+ lhs << new_call(name, op, argl(arg))
1012
1187
  lhs
1013
1188
  end
1014
- result.line = lhs.line
1189
+
1015
1190
  result
1016
1191
  end
1017
1192
 
1018
1193
  def new_op_asgn1 val
1019
- lhs, _, args, _, op, rhs = val
1194
+ lhs, _, args, _, (op, _), rhs = val
1020
1195
 
1021
1196
  args.sexp_type = :arglist if args
1022
1197
 
@@ -1026,7 +1201,7 @@ module RubyParserStuff
1026
1201
  end
1027
1202
 
1028
1203
  def new_op_asgn2 val
1029
- recv, call_op, meth, op, arg = val
1204
+ recv, (call_op, _), (meth, _), (op, _), arg = val
1030
1205
  meth = :"#{meth}="
1031
1206
 
1032
1207
  result = case call_op.to_sym
@@ -1043,36 +1218,28 @@ module RubyParserStuff
1043
1218
  end
1044
1219
 
1045
1220
  def new_qsym_list
1046
- result = s(:array).line lexer.lineno
1047
- self.lexer.fixup_lineno
1048
- result
1221
+ s(:array).line lexer.lineno
1049
1222
  end
1050
1223
 
1051
1224
  def new_qsym_list_entry val
1052
- _, str, _ = val
1053
- result = s(:lit, str.to_sym).line lexer.lineno
1054
- self.lexer.fixup_lineno
1055
- result
1225
+ _, (str, line), _ = val
1226
+ s(:lit, str.to_sym).line line
1056
1227
  end
1057
1228
 
1058
1229
  def new_qword_list
1059
- result = s(:array).line lexer.lineno
1060
- self.lexer.fixup_lineno
1061
- result
1230
+ s(:array).line lexer.lineno
1062
1231
  end
1063
1232
 
1064
1233
  def new_qword_list_entry val
1065
- _, str, _ = val
1234
+ _, (str, line), _ = val
1066
1235
  str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
1067
- result = s(:str, str).line lexer.lineno # TODO: problematic? grab from parser
1068
- self.lexer.fixup_lineno
1069
- result
1236
+ s(:str, str).line line
1070
1237
  end
1071
1238
 
1072
1239
  def new_regexp val
1073
- _, node, options = val
1240
+ (_, line), node, (options, _) = val
1074
1241
 
1075
- node ||= s(:str, "").line lexer.lineno
1242
+ node ||= s(:str, "").line line
1076
1243
 
1077
1244
  o, k = 0, nil
1078
1245
  options.split(//).uniq.each do |c| # FIX: this has a better home
@@ -1099,12 +1266,12 @@ module RubyParserStuff
1099
1266
  begin
1100
1267
  Regexp.new(node[1], o)
1101
1268
  rescue RegexpError => e
1102
- warn "WA\RNING: #{e.message} for #{node[1].inspect} #{options.inspect}"
1269
+ warn "WARNING: #{e.message} for #{node[1].inspect} #{options.inspect}"
1103
1270
  begin
1104
- warn "WA\RNING: trying to recover with ENC_UTF8"
1271
+ warn "WARNING: trying to recover with ENC_UTF8"
1105
1272
  Regexp.new(node[1], Regexp::ENC_UTF8)
1106
1273
  rescue RegexpError => e
1107
- warn "WA\RNING: trying to recover with ENC_NONE"
1274
+ warn "WARNING: trying to recover with ENC_NONE"
1108
1275
  Regexp.new(node[1], Regexp::ENC_NONE)
1109
1276
  end
1110
1277
  end
@@ -1117,7 +1284,7 @@ module RubyParserStuff
1117
1284
  end
1118
1285
  node << o if o and o != 0
1119
1286
  else
1120
- node = s(:dregx, "", node).line node.line
1287
+ node = s(:dregx, "", node).line line
1121
1288
  node.sexp_type = :dregx_once if options =~ /o/
1122
1289
  node << o if o and o != 0
1123
1290
  end
@@ -1159,17 +1326,16 @@ module RubyParserStuff
1159
1326
  end
1160
1327
 
1161
1328
  def new_string val
1162
- str, = val
1329
+ (str, line), = val
1330
+
1163
1331
  str.force_encoding("UTF-8")
1164
1332
  # TODO: remove:
1165
1333
  str.force_encoding("ASCII-8BIT") unless str.valid_encoding?
1166
- result = s(:str, str).line lexer.lineno
1167
- self.lexer.fixup_lineno str.count("\n")
1168
- result
1334
+ s(:str, str).line line
1169
1335
  end
1170
1336
 
1171
1337
  def new_super args
1172
- if args && args.node_type == :block_pass then
1338
+ if args && args.sexp_type == :block_pass then
1173
1339
  s(:super, args).line args.line
1174
1340
  else
1175
1341
  args ||= s(:arglist).line lexer.lineno
@@ -1177,32 +1343,30 @@ module RubyParserStuff
1177
1343
  end
1178
1344
  end
1179
1345
 
1346
+ def new_symbol val
1347
+ name = val.last
1348
+ s(:lit, name.to_sym).line lexer.lineno
1349
+ end
1350
+
1180
1351
  def new_symbol_list
1181
- result = s(:array).line lexer.lineno
1182
- self.lexer.fixup_lineno
1183
- result
1352
+ # TODO: hunt down and try to remove ALL lexer.lineno usage!
1353
+ s(:array).line lexer.lineno
1184
1354
  end
1185
1355
 
1186
1356
  def new_symbol_list_entry val
1187
1357
  _, sym, _ = val
1188
1358
 
1189
- sym ||= s(:str, "")
1190
-
1191
- line = lexer.lineno
1359
+ sym ||= s(:str, "").line lexer.lineno
1192
1360
 
1193
1361
  case sym.sexp_type
1194
1362
  when :dstr then
1195
1363
  sym.sexp_type = :dsym
1196
1364
  when :str then
1197
- sym = s(:lit, sym.last.to_sym)
1365
+ sym = s(:lit, sym.last.to_sym).line sym.line
1198
1366
  else
1199
- sym = s(:dsym, "", sym || s(:str, "").line(line))
1367
+ sym = s(:dsym, "", sym).line sym.line
1200
1368
  end
1201
1369
 
1202
- sym.line line
1203
-
1204
- self.lexer.fixup_lineno
1205
-
1206
1370
  sym
1207
1371
  end
1208
1372
 
@@ -1244,16 +1408,12 @@ module RubyParserStuff
1244
1408
  end
1245
1409
 
1246
1410
  def new_word_list
1247
- result = s(:array).line lexer.lineno
1248
- self.lexer.fixup_lineno
1249
- result
1411
+ s(:array).line lexer.lineno
1250
1412
  end
1251
1413
 
1252
1414
  def new_word_list_entry val
1253
1415
  _, word, _ = val
1254
- result = word.sexp_type == :evstr ? s(:dstr, "", word).line(word.line) : word
1255
- self.lexer.fixup_lineno
1256
- result
1416
+ word.sexp_type == :evstr ? s(:dstr, "", word).line(word.line) : word
1257
1417
  end
1258
1418
 
1259
1419
  def new_xstring val
@@ -1277,9 +1437,9 @@ module RubyParserStuff
1277
1437
 
1278
1438
  def new_yield args = nil
1279
1439
  # TODO: raise args.inspect unless [:arglist].include? args.first # HACK
1280
- raise "write a test 4" if args && args.node_type == :block_pass
1440
+ raise "write a test 4" if args && args.sexp_type == :block_pass
1281
1441
  raise SyntaxError, "Block argument should not be given." if
1282
- args && args.node_type == :block_pass
1442
+ args && args.sexp_type == :block_pass
1283
1443
 
1284
1444
  args ||= s(:arglist).line lexer.lineno
1285
1445
 
@@ -1289,18 +1449,30 @@ module RubyParserStuff
1289
1449
  s(:yield, *args.sexp_body).line args.line
1290
1450
  end
1291
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
+
1292
1461
  def next_token
1293
1462
  token = self.lexer.next_token
1294
1463
 
1295
1464
  if token and token.first != RubyLexer::EOF then
1296
1465
  self.last_token_type = token
1297
1466
  return token
1467
+ elsif !token
1468
+ return self.lexer.next_token
1298
1469
  else
1299
1470
  return [false, false]
1300
1471
  end
1301
1472
  end
1302
1473
 
1303
1474
  def on_error(et, ev, values)
1475
+ ev = ev.first if ev.instance_of?(Array) && ev.size == 2 && ev.last.is_a?(Integer)
1304
1476
  super
1305
1477
  rescue Racc::ParseError => e
1306
1478
  # I don't like how the exception obscures the error message
@@ -1314,18 +1486,17 @@ module RubyParserStuff
1314
1486
  # Timeout::Error if it runs for more than +time+ seconds.
1315
1487
 
1316
1488
  def process(str, file = "(string)", time = 10)
1489
+ str.freeze
1490
+
1317
1491
  Timeout.timeout time do
1318
1492
  raise "bad val: #{str.inspect}" unless String === str
1319
1493
 
1320
- str = handle_encoding str
1494
+ self.lexer.string = handle_encoding str
1321
1495
 
1322
1496
  self.file = file.dup
1323
1497
 
1324
1498
  @yydebug = ENV.has_key? "DEBUG"
1325
1499
 
1326
- # HACK -- need to get tests passing more than have graceful code
1327
- self.lexer.ss = RPStringScanner.new str
1328
-
1329
1500
  do_parse
1330
1501
  end
1331
1502
  end
@@ -1381,6 +1552,14 @@ module RubyParserStuff
1381
1552
  result
1382
1553
  end
1383
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
+
1384
1563
  def syntax_error msg
1385
1564
  raise RubyParser::SyntaxError, msg
1386
1565
  end
@@ -1425,6 +1604,8 @@ module RubyParserStuff
1425
1604
 
1426
1605
  if remove_width then
1427
1606
  line[idx..-1]
1607
+ elsif line[idx].nil?
1608
+ nil
1428
1609
  else
1429
1610
  col
1430
1611
  end