ruby_parser 3.0.4 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
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 +13 -0
- data/lib/ruby18_parser.rb +5 -0
- data/lib/ruby18_parser.y +5 -1
- data/lib/ruby19_parser.rb +5 -0
- data/lib/ruby19_parser.y +5 -1
- data/lib/ruby_lexer.rb +2 -6
- data/lib/ruby_parser_extras.rb +13 -5
- data/test/test_ruby_lexer.rb +1 -0
- data/test/test_ruby_parser.rb +62 -32
- metadata +4 -4
- metadata.gz.sig +1 -2
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
=== 3.1.0 / 2012-12-06
|
2
|
+
|
3
|
+
* 2 minor enhancements:
|
4
|
+
|
5
|
+
* Added RubyParser.for_current_ruby to provide a parser that matches your runtime. (neilconway)
|
6
|
+
* Duck-typed IDENT_CHAR_RE instead of using RUBY_VERSION
|
7
|
+
|
8
|
+
* 3 bug fixes:
|
9
|
+
|
10
|
+
* Cleared out body comments in class/module/defn/defs
|
11
|
+
* Flipped lexer tests to US-ASCII to avoid encoding hell
|
12
|
+
* yyerror is now an alias for syntax_error
|
13
|
+
|
1
14
|
=== 3.0.4 / 2012-11-26
|
2
15
|
|
3
16
|
* 1 bug fix:
|
data/lib/ruby18_parser.rb
CHANGED
@@ -4617,6 +4617,7 @@ end
|
|
4617
4617
|
def _reduce_310(val, _values, result)
|
4618
4618
|
result = new_class val
|
4619
4619
|
self.env.unextend
|
4620
|
+
self.lexer.comments # we don't care about comments in the body
|
4620
4621
|
|
4621
4622
|
result
|
4622
4623
|
end
|
@@ -4645,6 +4646,7 @@ end
|
|
4645
4646
|
def _reduce_314(val, _values, result)
|
4646
4647
|
result = new_sclass val
|
4647
4648
|
self.env.unextend
|
4649
|
+
self.lexer.comments # we don't care about comments in the body
|
4648
4650
|
|
4649
4651
|
result
|
4650
4652
|
end
|
@@ -4668,6 +4670,7 @@ end
|
|
4668
4670
|
def _reduce_317(val, _values, result)
|
4669
4671
|
result = new_module val
|
4670
4672
|
self.env.unextend
|
4673
|
+
self.lexer.comments # we don't care about comments in the body
|
4671
4674
|
|
4672
4675
|
result
|
4673
4676
|
end
|
@@ -4685,6 +4688,7 @@ def _reduce_319(val, _values, result)
|
|
4685
4688
|
result = new_defn val
|
4686
4689
|
self.env.unextend
|
4687
4690
|
self.in_def = false
|
4691
|
+
self.lexer.comments # we don't care about comments in the body
|
4688
4692
|
|
4689
4693
|
result
|
4690
4694
|
end
|
@@ -4709,6 +4713,7 @@ def _reduce_322(val, _values, result)
|
|
4709
4713
|
|
4710
4714
|
self.env.unextend
|
4711
4715
|
self.in_single -= 1
|
4716
|
+
self.lexer.comments # we don't care about comments in the body
|
4712
4717
|
|
4713
4718
|
result
|
4714
4719
|
end
|
data/lib/ruby18_parser.y
CHANGED
@@ -537,7 +537,6 @@ rule
|
|
537
537
|
result = s(:op_asgn, val[0], val[4], val[2], val[3])
|
538
538
|
}
|
539
539
|
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg
|
540
|
-
|
541
540
|
{
|
542
541
|
yyerror "constant re-assignment"
|
543
542
|
}
|
@@ -1083,6 +1082,7 @@ rule
|
|
1083
1082
|
{
|
1084
1083
|
result = new_class val
|
1085
1084
|
self.env.unextend
|
1085
|
+
self.lexer.comments # we don't care about comments in the body
|
1086
1086
|
}
|
1087
1087
|
| kCLASS tLSHFT
|
1088
1088
|
{
|
@@ -1103,6 +1103,7 @@ rule
|
|
1103
1103
|
{
|
1104
1104
|
result = new_sclass val
|
1105
1105
|
self.env.unextend
|
1106
|
+
self.lexer.comments # we don't care about comments in the body
|
1106
1107
|
}
|
1107
1108
|
| kMODULE
|
1108
1109
|
{
|
@@ -1120,6 +1121,7 @@ rule
|
|
1120
1121
|
{
|
1121
1122
|
result = new_module val
|
1122
1123
|
self.env.unextend
|
1124
|
+
self.lexer.comments # we don't care about comments in the body
|
1123
1125
|
}
|
1124
1126
|
| kDEF fname
|
1125
1127
|
{
|
@@ -1133,6 +1135,7 @@ rule
|
|
1133
1135
|
result = new_defn val
|
1134
1136
|
self.env.unextend
|
1135
1137
|
self.in_def = false
|
1138
|
+
self.lexer.comments # we don't care about comments in the body
|
1136
1139
|
}
|
1137
1140
|
| kDEF singleton dot_or_colon
|
1138
1141
|
{
|
@@ -1151,6 +1154,7 @@ rule
|
|
1151
1154
|
|
1152
1155
|
self.env.unextend
|
1153
1156
|
self.in_single -= 1
|
1157
|
+
self.lexer.comments # we don't care about comments in the body
|
1154
1158
|
}
|
1155
1159
|
| kBREAK
|
1156
1160
|
{
|
data/lib/ruby19_parser.rb
CHANGED
@@ -4681,6 +4681,7 @@ end
|
|
4681
4681
|
def _reduce_314(val, _values, result)
|
4682
4682
|
result = new_class val
|
4683
4683
|
self.env.unextend
|
4684
|
+
self.lexer.comments # we don't care about comments in the body
|
4684
4685
|
|
4685
4686
|
result
|
4686
4687
|
end
|
@@ -4709,6 +4710,7 @@ end
|
|
4709
4710
|
def _reduce_318(val, _values, result)
|
4710
4711
|
result = new_sclass val
|
4711
4712
|
self.env.unextend
|
4713
|
+
self.lexer.comments # we don't care about comments in the body
|
4712
4714
|
|
4713
4715
|
result
|
4714
4716
|
end
|
@@ -4732,6 +4734,7 @@ end
|
|
4732
4734
|
def _reduce_321(val, _values, result)
|
4733
4735
|
result = new_module val
|
4734
4736
|
self.env.unextend
|
4737
|
+
self.lexer.comments # we don't care about comments in the body
|
4735
4738
|
|
4736
4739
|
result
|
4737
4740
|
end
|
@@ -4751,6 +4754,7 @@ def _reduce_323(val, _values, result)
|
|
4751
4754
|
|
4752
4755
|
self.env.unextend
|
4753
4756
|
self.in_def = false
|
4757
|
+
self.lexer.comments # we don't care about comments in the body
|
4754
4758
|
|
4755
4759
|
result
|
4756
4760
|
end
|
@@ -4777,6 +4781,7 @@ def _reduce_326(val, _values, result)
|
|
4777
4781
|
|
4778
4782
|
self.env.unextend
|
4779
4783
|
self.in_single -= 1
|
4784
|
+
self.lexer.comments # we don't care about comments in the body
|
4780
4785
|
|
4781
4786
|
result
|
4782
4787
|
end
|
data/lib/ruby19_parser.y
CHANGED
@@ -608,7 +608,6 @@ rule
|
|
608
608
|
result = s(:op_asgn, val[0], val[4], val[2], val[3])
|
609
609
|
}
|
610
610
|
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg
|
611
|
-
|
612
611
|
{
|
613
612
|
yyerror "constant re-assignment"
|
614
613
|
}
|
@@ -1066,6 +1065,7 @@ rule
|
|
1066
1065
|
{
|
1067
1066
|
result = new_class val
|
1068
1067
|
self.env.unextend
|
1068
|
+
self.lexer.comments # we don't care about comments in the body
|
1069
1069
|
}
|
1070
1070
|
| kCLASS tLSHFT
|
1071
1071
|
{
|
@@ -1086,6 +1086,7 @@ rule
|
|
1086
1086
|
{
|
1087
1087
|
result = new_sclass val
|
1088
1088
|
self.env.unextend
|
1089
|
+
self.lexer.comments # we don't care about comments in the body
|
1089
1090
|
}
|
1090
1091
|
| kMODULE
|
1091
1092
|
{
|
@@ -1103,6 +1104,7 @@ rule
|
|
1103
1104
|
{
|
1104
1105
|
result = new_module val
|
1105
1106
|
self.env.unextend
|
1107
|
+
self.lexer.comments # we don't care about comments in the body
|
1106
1108
|
}
|
1107
1109
|
| kDEF fname
|
1108
1110
|
{
|
@@ -1118,6 +1120,7 @@ rule
|
|
1118
1120
|
|
1119
1121
|
self.env.unextend
|
1120
1122
|
self.in_def = false
|
1123
|
+
self.lexer.comments # we don't care about comments in the body
|
1121
1124
|
}
|
1122
1125
|
| kDEF singleton dot_or_colon
|
1123
1126
|
{
|
@@ -1138,6 +1141,7 @@ rule
|
|
1138
1141
|
|
1139
1142
|
self.env.unextend
|
1140
1143
|
self.in_single -= 1
|
1144
|
+
self.lexer.comments # we don't care about comments in the body
|
1141
1145
|
}
|
1142
1146
|
| kBREAK
|
1143
1147
|
{
|
data/lib/ruby_lexer.rb
CHANGED
@@ -4,13 +4,10 @@ class RubyLexer
|
|
4
4
|
|
5
5
|
RUBY19 = "".respond_to? :encoding
|
6
6
|
|
7
|
-
IDENT_CHAR_RE =
|
8
|
-
when /^1\.8/ then
|
9
|
-
/[\w\x80-\xFF]/
|
10
|
-
when /^(1\.9|2\.0)/ then # HACK - matching 2.0 for now
|
7
|
+
IDENT_CHAR_RE = if RUBY19 then
|
11
8
|
/[\w\u0080-\uFFFF]/u
|
12
9
|
else
|
13
|
-
|
10
|
+
/[\w\x80-\xFF]/
|
14
11
|
end
|
15
12
|
|
16
13
|
IDENT_RE = /^#{IDENT_CHAR_RE}+/
|
@@ -752,7 +749,6 @@ class RubyLexer
|
|
752
749
|
tok = self.yacc_value = src.matched
|
753
750
|
return TOKENS[tok]
|
754
751
|
elsif src.scan(/\=begin(?=\s)/) then
|
755
|
-
# @comments << '=' << src.matched
|
756
752
|
@comments << src.matched
|
757
753
|
|
758
754
|
unless src.scan(/.*?\n=end( |\t|\f)*[^\n]*(\n|\z)/m) then
|
data/lib/ruby_parser_extras.rb
CHANGED
@@ -108,7 +108,7 @@ class RPStringScanner < StringScanner
|
|
108
108
|
end
|
109
109
|
|
110
110
|
module RubyParserStuff
|
111
|
-
VERSION = '3.0
|
111
|
+
VERSION = '3.1.0' unless constants.include? "VERSION" # SIGH
|
112
112
|
|
113
113
|
attr_accessor :lexer, :in_def, :in_single, :file
|
114
114
|
attr_reader :env, :comments
|
@@ -1049,10 +1049,7 @@ module RubyParserStuff
|
|
1049
1049
|
# do nothing for now
|
1050
1050
|
end
|
1051
1051
|
|
1052
|
-
|
1053
|
-
warn msg if $DEBUG
|
1054
|
-
super()
|
1055
|
-
end
|
1052
|
+
alias yyerror syntax_error
|
1056
1053
|
|
1057
1054
|
def on_error(et, ev, values)
|
1058
1055
|
super
|
@@ -1301,6 +1298,17 @@ class RubyParser
|
|
1301
1298
|
@p18.reset
|
1302
1299
|
@p19.reset
|
1303
1300
|
end
|
1301
|
+
|
1302
|
+
def self.for_current_ruby
|
1303
|
+
case RUBY_VERSION
|
1304
|
+
when /^1\.8/ then
|
1305
|
+
Ruby18Parser.new
|
1306
|
+
when /^1\.9/ then
|
1307
|
+
Ruby19Parser.new
|
1308
|
+
else
|
1309
|
+
raise "unrecognized RUBY_VERSION #{RUBY_VERSION}"
|
1310
|
+
end
|
1311
|
+
end
|
1304
1312
|
end
|
1305
1313
|
|
1306
1314
|
############################################################
|
data/test/test_ruby_lexer.rb
CHANGED
data/test/test_ruby_parser.rb
CHANGED
@@ -27,6 +27,8 @@ end
|
|
27
27
|
class RubyParserTestCase < ParseTreeTestCase
|
28
28
|
attr_accessor :result, :processor
|
29
29
|
|
30
|
+
make_my_diffs_pretty!
|
31
|
+
|
30
32
|
def self.previous key
|
31
33
|
"Ruby"
|
32
34
|
end
|
@@ -880,8 +882,8 @@ module TestRubyParserShared
|
|
880
882
|
end
|
881
883
|
|
882
884
|
def test_i_fucking_hate_line_numbers
|
883
|
-
rb = <<-
|
884
|
-
|
885
|
+
rb = <<-END.gsub(/^ {6}/, '')
|
886
|
+
if true
|
885
887
|
p 1
|
886
888
|
a.b 2
|
887
889
|
c.d 3, 4
|
@@ -893,53 +895,81 @@ module TestRubyParserShared
|
|
893
895
|
e.f(5)
|
894
896
|
g.h(6, 7)
|
895
897
|
end
|
896
|
-
|
898
|
+
END
|
897
899
|
|
898
|
-
pt = s(:
|
899
|
-
s(:
|
900
|
-
|
901
|
-
s(:
|
902
|
-
|
903
|
-
s(:
|
904
|
-
|
905
|
-
s(:
|
906
|
-
|
907
|
-
s(:
|
908
|
-
|
909
|
-
|
910
|
-
s(:
|
911
|
-
|
912
|
-
s(:
|
913
|
-
|
914
|
-
s(:
|
915
|
-
|
916
|
-
s(:
|
917
|
-
|
900
|
+
pt = s(:if, s(:true).line(1),
|
901
|
+
s(:block,
|
902
|
+
s(:call, nil, :p, s(:lit, 1).line(2)).line(2),
|
903
|
+
s(:call, s(:call, nil, :a).line(3), :b,
|
904
|
+
s(:lit, 2).line(3)).line(3),
|
905
|
+
s(:call, s(:call, nil, :c).line(4), :d,
|
906
|
+
s(:lit, 3).line(4), s(:lit, 4).line(4)).line(4),
|
907
|
+
s(:call, s(:call, nil, :e).line(5), :f,
|
908
|
+
s(:lit, 5).line(5)).line(5),
|
909
|
+
s(:call, s(:call, nil, :g).line(6), :h,
|
910
|
+
s(:lit, 6).line(6), s(:lit, 7).line(6)).line(6),
|
911
|
+
s(:call, nil, :p, s(:lit, 1).line(7)).line(7),
|
912
|
+
s(:call, s(:call, nil, :a).line(8), :b,
|
913
|
+
s(:lit, 2).line(8)).line(8),
|
914
|
+
s(:call, s(:call, nil, :c).line(9), :d,
|
915
|
+
s(:lit, 3).line(9), s(:lit, 4).line(9)).line(9),
|
916
|
+
s(:call, s(:call, nil, :e).line(10), :f,
|
917
|
+
s(:lit, 5).line(10)).line(10),
|
918
|
+
s(:call, s(:call, nil, :g).line(11), :h,
|
919
|
+
s(:lit, 6).line(11), s(:lit, 7).line(11)).line(11)).line(2),
|
920
|
+
nil).line(1)
|
918
921
|
|
919
922
|
assert_parse rb, pt
|
920
923
|
end
|
921
924
|
|
922
925
|
def test_i_fucking_hate_line_numbers2
|
923
926
|
rb = <<-EOM.gsub(/^ {6}/, '')
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
927
|
+
if true then
|
928
|
+
p('a')
|
929
|
+
b = 1
|
930
|
+
p b
|
931
|
+
c =1
|
929
932
|
end
|
930
933
|
a
|
931
934
|
EOM
|
932
935
|
|
933
|
-
|
934
|
-
|
936
|
+
pt = s(:block,
|
937
|
+
s(:if, s(:true).line(1),
|
938
|
+
s(:block,
|
935
939
|
s(:call, nil, :p, s(:str, "a").line(2)).line(2),
|
936
940
|
s(:lasgn, :b, s(:lit, 1).line(3)).line(3),
|
937
941
|
s(:call, nil, :p, s(:lvar, :b).line(4)).line(4),
|
938
|
-
s(:lasgn, :c, s(:lit, 1).line(5)).line(5)).line(
|
939
|
-
|
942
|
+
s(:lasgn, :c, s(:lit, 1).line(5)).line(5)).line(2), # TODO line 2?
|
943
|
+
nil).line(1),
|
944
|
+
s(:call, nil, :a).line(7)).line(1)
|
940
945
|
|
941
946
|
assert_parse rb, pt
|
942
947
|
end
|
948
|
+
|
949
|
+
def test_parse_comments
|
950
|
+
p = RubyParser.new
|
951
|
+
sexp = p.parse <<-CODE
|
952
|
+
# class comment
|
953
|
+
class Inline
|
954
|
+
def show
|
955
|
+
# woot
|
956
|
+
end
|
957
|
+
|
958
|
+
# Returns a list of things
|
959
|
+
def list
|
960
|
+
# woot
|
961
|
+
end
|
962
|
+
end
|
963
|
+
CODE
|
964
|
+
|
965
|
+
assert_equal "# class comment\n", sexp.comments
|
966
|
+
act = sexp.find_nodes(:defn).map(&:comments)
|
967
|
+
exp = ["", "# Returns a list of things\n"]
|
968
|
+
|
969
|
+
assert_equal exp, act
|
970
|
+
assert_equal [], processor.comments
|
971
|
+
assert_equal "", processor.lexer.comments
|
972
|
+
end
|
943
973
|
end
|
944
974
|
|
945
975
|
class TestRubyParser < MiniTest::Unit::TestCase
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 3
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 3.0.4
|
10
|
+
version: 3.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Davis
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
FBHgymkyj/AOSqKRIpXPhjC6
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2012-
|
39
|
+
date: 2012-12-07 00:00:00 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sexp_processor
|
metadata.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
ޜl*�GTq H4�;|���E.#�9�M����2)&���Y� ����o�P]��Q���
|
1
|
+
�ۇ�o�����?�^iu�vS�?��bx
|