ruby_parser 3.0.0.a4 → 3.0.0.a5
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.
Potentially problematic release.
This version of ruby_parser might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/History.txt +10 -0
- data/bin/ruby_parse_extract_error +3 -1
- data/lib/ruby19_parser.rb +2 -3
- data/lib/ruby19_parser.y +2 -3
- data/lib/ruby_lexer.rb +22 -15
- data/lib/ruby_parser_extras.rb +12 -2
- data/test/test_ruby_parser.rb +91 -13
- metadata +4 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 3.0.0.a5 / 2012-07-31
|
2
|
+
|
3
|
+
* 5 bug fixes:
|
4
|
+
|
5
|
+
* 1.9: Fix construction of 'f(:x, y: nil,)' w/ trailing comma.
|
6
|
+
* 1.9: cleaned up lexing exit lex_state handling. Fixes bug parsing 'if f :x; end'
|
7
|
+
* 1.9: fixed building of right-leaning masgns: 'f { |a, (b, c)| }'
|
8
|
+
* 1.9: fixed lexing 'when *splat'
|
9
|
+
* 1.9: fixed lexing of regexps in whens
|
10
|
+
|
1
11
|
=== 3.0.0.a4 / 2012-07-26
|
2
12
|
|
3
13
|
* 10 minor enhancements:
|
data/lib/ruby19_parser.rb
CHANGED
@@ -4315,8 +4315,7 @@ def _reduce_250(val, _values, result)
|
|
4315
4315
|
end
|
4316
4316
|
|
4317
4317
|
def _reduce_251(val, _values, result)
|
4318
|
-
|
4319
|
-
result = val[0].add val[2]
|
4318
|
+
result = val[0] << s(:hash, *val[2][1..-1])
|
4320
4319
|
|
4321
4320
|
result
|
4322
4321
|
end
|
@@ -5868,7 +5867,7 @@ def _reduce_526(val, _values, result)
|
|
5868
5867
|
end
|
5869
5868
|
|
5870
5869
|
def _reduce_527(val, _values, result)
|
5871
|
-
val[0] << val[2]
|
5870
|
+
val[0] << val[2]
|
5872
5871
|
result = val[0]
|
5873
5872
|
|
5874
5873
|
result
|
data/lib/ruby19_parser.y
CHANGED
@@ -809,8 +809,7 @@ rule
|
|
809
809
|
}
|
810
810
|
| args tCOMMA assocs tCOMMA
|
811
811
|
{
|
812
|
-
|
813
|
-
result = val[0].add val[2]
|
812
|
+
result = val[0] << s(:hash, *val[2][1..-1])
|
814
813
|
}
|
815
814
|
| assocs tCOMMA
|
816
815
|
{
|
@@ -1909,7 +1908,7 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
1909
1908
|
}
|
1910
1909
|
| f_arg tCOMMA f_arg_item
|
1911
1910
|
{
|
1912
|
-
val[0] << val[2]
|
1911
|
+
val[0] << val[2]
|
1913
1912
|
result = val[0]
|
1914
1913
|
}
|
1915
1914
|
|
data/lib/ruby_lexer.rb
CHANGED
@@ -239,7 +239,7 @@ class RubyLexer
|
|
239
239
|
end
|
240
240
|
|
241
241
|
def lex_state= o
|
242
|
-
# warn "wtf lex_state = #{o.inspect}"
|
242
|
+
# warn "wtf lex_state = #{o.inspect} from #{caller.first}"
|
243
243
|
raise "wtf\?" unless Symbol === o
|
244
244
|
@lex_state = o
|
245
245
|
end
|
@@ -485,6 +485,10 @@ class RubyLexer
|
|
485
485
|
Ruby18Parser === parser
|
486
486
|
end
|
487
487
|
|
488
|
+
def ruby19
|
489
|
+
Ruby19Parser === parser
|
490
|
+
end
|
491
|
+
|
488
492
|
def src= src
|
489
493
|
raise "bad src: #{src.inspect}" unless String === src
|
490
494
|
@src = RPStringScanner.new(src)
|
@@ -769,15 +773,16 @@ class RubyLexer
|
|
769
773
|
self.lex_state = :expr_dot
|
770
774
|
self.yacc_value = "::"
|
771
775
|
return :tCOLON2
|
772
|
-
elsif
|
776
|
+
elsif ! is_end? && src.scan(/:([a-zA-Z_]\w*(?:[?!]|=(?!>))?)/) then
|
777
|
+
# scanning shortcut to symbols
|
773
778
|
self.yacc_value = src[1]
|
774
779
|
self.lex_state = :expr_end
|
775
780
|
return :tSYMBOL
|
776
781
|
elsif src.scan(/\:/) then
|
777
782
|
# ?: / then / when
|
778
|
-
if
|
779
|
-
src.check(/\s/)) then
|
783
|
+
if is_end? || src.check(/\s/) then
|
780
784
|
self.lex_state = :expr_beg
|
785
|
+
# TODO warn_balanced(":", "symbol literal");
|
781
786
|
self.yacc_value = ":"
|
782
787
|
return :tCOLON
|
783
788
|
end
|
@@ -933,7 +938,7 @@ class RubyLexer
|
|
933
938
|
result = if lex_state.is_argument && space_seen && src.check(/\S/) then
|
934
939
|
warning("`*' interpreted as argument prefix")
|
935
940
|
:tSTAR
|
936
|
-
elsif
|
941
|
+
elsif is_beg? then
|
937
942
|
:tSTAR
|
938
943
|
else
|
939
944
|
:tSTAR2
|
@@ -1091,7 +1096,7 @@ class RubyLexer
|
|
1091
1096
|
return result
|
1092
1097
|
end
|
1093
1098
|
elsif src.scan(/\//) then
|
1094
|
-
if
|
1099
|
+
if is_beg? then
|
1095
1100
|
self.lex_strterm = [:strterm, STR_REGEXP, '/', "\0"]
|
1096
1101
|
self.yacc_value = "/"
|
1097
1102
|
return :tREGEXP_BEG
|
@@ -1394,17 +1399,19 @@ class RubyLexer
|
|
1394
1399
|
end
|
1395
1400
|
end
|
1396
1401
|
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
+
self.lex_state =
|
1403
|
+
if is_beg? || lex_state == :expr_dot || is_arg? then
|
1404
|
+
if command_state then
|
1405
|
+
:expr_cmdarg
|
1406
|
+
else
|
1407
|
+
:expr_arg
|
1408
|
+
end
|
1409
|
+
elsif ruby19 && lex_state == :expr_fname then
|
1410
|
+
:expr_endfn
|
1402
1411
|
else
|
1403
|
-
|
1412
|
+
:expr_end
|
1404
1413
|
end
|
1405
|
-
|
1406
|
-
self.lex_state = :expr_end
|
1407
|
-
end
|
1414
|
+
|
1408
1415
|
end
|
1409
1416
|
|
1410
1417
|
self.yacc_value = token
|
data/lib/ruby_parser_extras.rb
CHANGED
@@ -78,7 +78,7 @@ class RPStringScanner < StringScanner
|
|
78
78
|
end
|
79
79
|
|
80
80
|
module RubyParserStuff
|
81
|
-
VERSION = '3.0.0.
|
81
|
+
VERSION = '3.0.0.a5' unless constants.include? "VERSION" # SIGH
|
82
82
|
|
83
83
|
attr_accessor :lexer, :in_def, :in_single, :file
|
84
84
|
attr_reader :env, :comments
|
@@ -201,7 +201,16 @@ module RubyParserStuff
|
|
201
201
|
when Sexp then
|
202
202
|
case v.first
|
203
203
|
when :args then
|
204
|
-
r.concat v[1..-1].map { |s|
|
204
|
+
r.concat v[1..-1].map { |s| # FIX: this is a smell
|
205
|
+
case s
|
206
|
+
when Symbol then
|
207
|
+
s(:lasgn, s)
|
208
|
+
when Sexp then
|
209
|
+
s
|
210
|
+
else
|
211
|
+
raise "unhandled type: #{s.inspect}"
|
212
|
+
end
|
213
|
+
}
|
205
214
|
when :block_arg then
|
206
215
|
r << s(:lasgn, :"&#{v.last}")
|
207
216
|
when :masgn then
|
@@ -1221,6 +1230,7 @@ class Sexp
|
|
1221
1230
|
end
|
1222
1231
|
|
1223
1232
|
def to_sym
|
1233
|
+
raise "no"
|
1224
1234
|
self.value.to_sym
|
1225
1235
|
end
|
1226
1236
|
|
data/test/test_ruby_parser.rb
CHANGED
@@ -646,16 +646,31 @@ module TestRubyParserShared
|
|
646
646
|
assert_parse rb, pt
|
647
647
|
end
|
648
648
|
|
649
|
-
|
649
|
+
# according to 2.3.1 parser:
|
650
|
+
# rp.process("f { |(a,b),c| }") == rp.process("f { |((a,b),c)| }")
|
651
|
+
|
652
|
+
# def test_bug_args_masgn
|
653
|
+
# rb = "f { |(a, b), c| }"
|
654
|
+
# pt = s(:iter,
|
655
|
+
# s(:call, nil, :f),
|
656
|
+
# s(:masgn,
|
657
|
+
# s(:array,
|
658
|
+
# s(:masgn, s(:array, s(:lasgn, :a), s(:lasgn, :b))),
|
659
|
+
# s(:lasgn, :c))))
|
660
|
+
#
|
661
|
+
# assert_parse rb, pt.dup
|
662
|
+
# end
|
663
|
+
|
664
|
+
def test_bug_args_masgn_outer_parens
|
650
665
|
rb = "f { |((a, b), c)| }"
|
651
|
-
pt = s(:iter,
|
666
|
+
pt = s(:iter, # NOTE: same sexp as test_bug_args_masgn
|
652
667
|
s(:call, nil, :f),
|
653
668
|
s(:masgn,
|
654
669
|
s(:array,
|
655
670
|
s(:masgn, s(:array, s(:lasgn, :a), s(:lasgn, :b))),
|
656
671
|
s(:lasgn, :c))))
|
657
672
|
|
658
|
-
assert_parse rb, pt
|
673
|
+
assert_parse rb, pt.dup
|
659
674
|
end
|
660
675
|
|
661
676
|
# TODO:
|
@@ -675,16 +690,61 @@ module TestRubyParserShared
|
|
675
690
|
# assert_parse rb, pt
|
676
691
|
# end
|
677
692
|
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
693
|
+
def test_bug_comma
|
694
|
+
val = case self.processor
|
695
|
+
when Ruby18Parser then
|
696
|
+
s(:lit, 100)
|
697
|
+
when Ruby19Parser then
|
698
|
+
s(:str, "d")
|
699
|
+
else
|
700
|
+
raise "wtf"
|
701
|
+
end
|
702
|
+
|
703
|
+
rb = "if test ?d, dir then end"
|
704
|
+
pt = s(:if,
|
705
|
+
s(:call, nil, :test, val, s(:call, nil, :dir)),
|
706
|
+
nil,
|
707
|
+
nil)
|
708
|
+
|
709
|
+
assert_parse rb, pt
|
710
|
+
end
|
711
|
+
|
712
|
+
def test_bug_case_when_regexp
|
713
|
+
rb = "case :x; when /x/ then end"
|
714
|
+
pt = s(:case, s(:lit, :x),
|
715
|
+
s(:when, s(:array, s(:lit, /x/)), nil),
|
716
|
+
nil)
|
717
|
+
|
718
|
+
assert_parse rb, pt
|
719
|
+
end
|
720
|
+
|
721
|
+
def test_bug_masgn_right
|
722
|
+
rb = "f { |a, (b, c)| }"
|
723
|
+
pt = s(:iter,
|
724
|
+
s(:call, nil, :f),
|
725
|
+
s(:masgn,
|
726
|
+
s(:array,
|
727
|
+
s(:lasgn, :a),
|
728
|
+
s(:masgn, s(:array, s(:lasgn, :b), s(:lasgn, :c))))))
|
729
|
+
|
730
|
+
assert_parse rb, pt
|
731
|
+
end
|
732
|
+
|
733
|
+
def test_when_splat
|
734
|
+
rb = "case a; when *b then; end"
|
735
|
+
pt = s(:case, s(:call, nil, :a),
|
736
|
+
s(:when, s(:array, s(:splat, s(:call, nil, :b))), nil),
|
737
|
+
nil)
|
738
|
+
|
739
|
+
assert_parse rb, pt
|
740
|
+
end
|
741
|
+
|
742
|
+
def test_if_symbol
|
743
|
+
rb = "if f :x; end"
|
744
|
+
pt = s(:if, s(:call, nil, :f, s(:lit, :x)), nil, nil)
|
745
|
+
|
746
|
+
assert_parse rb, pt
|
747
|
+
end
|
688
748
|
end
|
689
749
|
|
690
750
|
class TestRubyParser < MiniTest::Unit::TestCase
|
@@ -1034,6 +1094,24 @@ class TestRuby19Parser < RubyParserTestCase
|
|
1034
1094
|
assert_parse rb, pt
|
1035
1095
|
end
|
1036
1096
|
|
1097
|
+
def test_bug_hash_args
|
1098
|
+
rb = "foo(:bar, baz: nil)"
|
1099
|
+
pt = s(:call, nil, :foo,
|
1100
|
+
s(:lit, :bar),
|
1101
|
+
s(:hash, s(:lit, :baz), s(:nil)))
|
1102
|
+
|
1103
|
+
assert_parse rb, pt
|
1104
|
+
end
|
1105
|
+
|
1106
|
+
def test_bug_hash_args_trailing_comma
|
1107
|
+
rb = "foo(:bar, baz: nil,)"
|
1108
|
+
pt = s(:call, nil, :foo, # NOTE: same sexp as test_bug_hash_args
|
1109
|
+
s(:lit, :bar),
|
1110
|
+
s(:hash, s(:lit, :baz), s(:nil)))
|
1111
|
+
|
1112
|
+
assert_parse rb, pt
|
1113
|
+
end
|
1114
|
+
|
1037
1115
|
# HACK: need to figure out the desired structure and get this working
|
1038
1116
|
# def test_wtf
|
1039
1117
|
# # lambda -> f_larglist lambda_body
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: -2559988010
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- a
|
11
|
-
-
|
12
|
-
version: 3.0.0.
|
11
|
+
- 5
|
12
|
+
version: 3.0.0.a5
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Ryan Davis
|
@@ -38,7 +38,7 @@ cert_chain:
|
|
38
38
|
FBHgymkyj/AOSqKRIpXPhjC6
|
39
39
|
-----END CERTIFICATE-----
|
40
40
|
|
41
|
-
date: 2012-
|
41
|
+
date: 2012-08-01 00:00:00 Z
|
42
42
|
dependencies:
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: sexp_processor
|
metadata.gz.sig
CHANGED
Binary file
|