ruby_parser 2.0.5 → 3.0.0.a1
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.
- data/.autotest +4 -4
- data/.gemtest +0 -0
- data/History.txt +124 -0
- data/Manifest.txt +6 -1
- data/README.txt +7 -6
- data/Rakefile +74 -27
- data/bin/ruby_parse +9 -1
- data/bin/ruby_parse_extract_error +75 -0
- data/lib/ruby18_parser.rb +5737 -0
- data/lib/{ruby_parser.y → ruby18_parser.y} +197 -124
- data/lib/ruby19_parser.rb +6147 -0
- data/lib/ruby19_parser.y +2014 -0
- data/lib/ruby_lexer.rb +146 -47
- data/lib/ruby_parser.rb +3 -5544
- data/lib/ruby_parser_extras.rb +392 -244
- data/test/test_ruby_lexer.rb +99 -15
- data/test/test_ruby_parser.rb +395 -130
- data/test/test_ruby_parser_extras.rb +10 -6
- data.tar.gz.sig +0 -0
- metadata +45 -39
- metadata.gz.sig +3 -1
data/test/test_ruby_lexer.rb
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
#!/usr/local/bin/ruby
|
|
2
2
|
|
|
3
3
|
require 'rubygems'
|
|
4
|
+
gem "minitest"
|
|
5
|
+
|
|
4
6
|
require 'minitest/autorun'
|
|
5
7
|
require 'ruby_lexer'
|
|
6
|
-
require '
|
|
8
|
+
require 'ruby18_parser'
|
|
7
9
|
|
|
8
10
|
class TestRubyLexer < MiniTest::Unit::TestCase
|
|
9
11
|
alias :deny :refute
|
|
10
12
|
|
|
11
13
|
def setup
|
|
12
|
-
|
|
14
|
+
setup_lexer Ruby18Parser
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def setup_lexer parser_class
|
|
18
|
+
p = parser_class.new
|
|
13
19
|
@lex = p.lexer
|
|
14
20
|
@lex.src = "blah blah"
|
|
15
21
|
@lex.lex_state = :expr_beg
|
|
@@ -125,6 +131,38 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
125
131
|
util_lex_token "=>", :tASSOC, "=>"
|
|
126
132
|
end
|
|
127
133
|
|
|
134
|
+
def test_yylex_label__18
|
|
135
|
+
util_lex_token("{a:",
|
|
136
|
+
:tLBRACE, "{",
|
|
137
|
+
:tIDENTIFIER, "a",
|
|
138
|
+
:tSYMBEG, ":")
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_yylex_label_in_params__18
|
|
142
|
+
util_lex_token("foo(a:",
|
|
143
|
+
:tIDENTIFIER, "foo",
|
|
144
|
+
:tLPAREN2, "(",
|
|
145
|
+
:tIDENTIFIER, "a",
|
|
146
|
+
:tSYMBEG, ":")
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def test_yylex_label__19
|
|
150
|
+
setup_lexer Ruby19Parser
|
|
151
|
+
|
|
152
|
+
util_lex_token("{a:",
|
|
153
|
+
:tLBRACE, "{",
|
|
154
|
+
:tLABEL, "a")
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def test_yylex_label_in_params__19
|
|
158
|
+
setup_lexer Ruby19Parser
|
|
159
|
+
|
|
160
|
+
util_lex_token("foo(a:",
|
|
161
|
+
:tIDENTIFIER, "foo",
|
|
162
|
+
:tLPAREN2, "(",
|
|
163
|
+
:tLABEL, "a")
|
|
164
|
+
end
|
|
165
|
+
|
|
128
166
|
def test_yylex_back_ref
|
|
129
167
|
util_lex_token("[$&, $`, $', $+]",
|
|
130
168
|
:tLBRACK, "[",
|
|
@@ -255,6 +293,11 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
255
293
|
assert_equal "=begin blah\nblah\n=end\n", @lex.comments
|
|
256
294
|
end
|
|
257
295
|
|
|
296
|
+
def test_yylex_comment_end_space_and_text
|
|
297
|
+
util_lex_token("=begin blah\nblah\n=end blab\n")
|
|
298
|
+
assert_equal "=begin blah\nblah\n=end blab\n", @lex.comments
|
|
299
|
+
end
|
|
300
|
+
|
|
258
301
|
def test_yylex_comment_eos
|
|
259
302
|
util_lex_token("# comment")
|
|
260
303
|
end
|
|
@@ -605,7 +648,6 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
605
648
|
:tEQL, "=",
|
|
606
649
|
:tSTRING_BEG, "\"",
|
|
607
650
|
:tSTRING_CONTENT, "blah\nblah\n",
|
|
608
|
-
:tSTRING_CONTENT, "",
|
|
609
651
|
:tSTRING_END, "EOF",
|
|
610
652
|
:tNL, nil)
|
|
611
653
|
end
|
|
@@ -623,7 +665,6 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
623
665
|
:tEQL, "=",
|
|
624
666
|
:tSTRING_BEG, "\"",
|
|
625
667
|
:tSTRING_CONTENT, "blah\nblah\n",
|
|
626
|
-
:tSTRING_CONTENT, "",
|
|
627
668
|
:tSTRING_END, "EOF",
|
|
628
669
|
:tNL, nil)
|
|
629
670
|
end
|
|
@@ -800,14 +841,30 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
800
841
|
util_bad_token "0d42__24"
|
|
801
842
|
end
|
|
802
843
|
|
|
803
|
-
def
|
|
804
|
-
|
|
844
|
+
def test_yylex_question_eh_a__18
|
|
845
|
+
@lex = RubyLexer.new 18
|
|
846
|
+
|
|
847
|
+
util_lex_token "?a", :tINTEGER, 97
|
|
805
848
|
end
|
|
806
849
|
|
|
807
|
-
def
|
|
850
|
+
def test_yylex_question_eh_a__19
|
|
851
|
+
@lex = RubyLexer.new 19
|
|
852
|
+
|
|
853
|
+
util_lex_token '?a', :tSTRING, "a"
|
|
854
|
+
end
|
|
855
|
+
|
|
856
|
+
def test_yylex_question_eh_escape_M_escape_C__18
|
|
857
|
+
@lex = RubyLexer.new 18
|
|
858
|
+
|
|
808
859
|
util_lex_token '?\M-\C-a', :tINTEGER, 129
|
|
809
860
|
end
|
|
810
861
|
|
|
862
|
+
def test_yylex_question_eh_escape_M_escape_C__19
|
|
863
|
+
@lex = RubyLexer.new 19
|
|
864
|
+
|
|
865
|
+
util_lex_token '?\M-\C-a', :tSTRING, "\M-\C-a"
|
|
866
|
+
end
|
|
867
|
+
|
|
811
868
|
def test_yylex_integer_hex
|
|
812
869
|
util_lex_token "0x2a", :tINTEGER, 42
|
|
813
870
|
end
|
|
@@ -1023,7 +1080,7 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1023
1080
|
def test_yylex_open_square_bracket_meth
|
|
1024
1081
|
util_lex_token("m[3]",
|
|
1025
1082
|
:tIDENTIFIER, "m",
|
|
1026
|
-
|
|
1083
|
+
:tLBRACK2, "[",
|
|
1027
1084
|
:tINTEGER, 3,
|
|
1028
1085
|
:tRBRACK, "]")
|
|
1029
1086
|
end
|
|
@@ -1084,10 +1141,18 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1084
1141
|
:tINTEGER, 42)
|
|
1085
1142
|
end
|
|
1086
1143
|
|
|
1087
|
-
def
|
|
1144
|
+
def test_yylex_question__18
|
|
1145
|
+
@lex = RubyLexer.new 18
|
|
1146
|
+
|
|
1088
1147
|
util_lex_token "?*", :tINTEGER, 42
|
|
1089
1148
|
end
|
|
1090
1149
|
|
|
1150
|
+
def test_yylex_question__19
|
|
1151
|
+
@lex = RubyLexer.new 19
|
|
1152
|
+
|
|
1153
|
+
util_lex_token "?*", :tSTRING, "*"
|
|
1154
|
+
end
|
|
1155
|
+
|
|
1091
1156
|
def test_yylex_question_bad_eos
|
|
1092
1157
|
util_bad_token "?"
|
|
1093
1158
|
end
|
|
@@ -1101,7 +1166,9 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1101
1166
|
util_lex_token "?\f", :tEH, "?"
|
|
1102
1167
|
end
|
|
1103
1168
|
|
|
1104
|
-
def
|
|
1169
|
+
def test_yylex_question_ws_backslashed__18
|
|
1170
|
+
@lex = RubyLexer.new 18
|
|
1171
|
+
|
|
1105
1172
|
@lex.lex_state = :expr_beg
|
|
1106
1173
|
util_lex_token "?\\ ", :tINTEGER, 32
|
|
1107
1174
|
@lex.lex_state = :expr_beg
|
|
@@ -1116,6 +1183,23 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1116
1183
|
util_lex_token "?\\f", :tINTEGER, 12
|
|
1117
1184
|
end
|
|
1118
1185
|
|
|
1186
|
+
def test_yylex_question_ws_backslashed__19
|
|
1187
|
+
@lex = RubyLexer.new 19
|
|
1188
|
+
|
|
1189
|
+
@lex.lex_state = :expr_beg
|
|
1190
|
+
util_lex_token "?\\ ", :tSTRING, " "
|
|
1191
|
+
@lex.lex_state = :expr_beg
|
|
1192
|
+
util_lex_token "?\\n", :tSTRING, "\n"
|
|
1193
|
+
@lex.lex_state = :expr_beg
|
|
1194
|
+
util_lex_token "?\\t", :tSTRING, "\t"
|
|
1195
|
+
@lex.lex_state = :expr_beg
|
|
1196
|
+
util_lex_token "?\\v", :tSTRING, "\v"
|
|
1197
|
+
@lex.lex_state = :expr_beg
|
|
1198
|
+
util_lex_token "?\\r", :tSTRING, "\r"
|
|
1199
|
+
@lex.lex_state = :expr_beg
|
|
1200
|
+
util_lex_token "?\\f", :tSTRING, "\f"
|
|
1201
|
+
end
|
|
1202
|
+
|
|
1119
1203
|
def test_yylex_rbracket
|
|
1120
1204
|
util_lex_token "]", :tRBRACK, "]"
|
|
1121
1205
|
end
|
|
@@ -1609,7 +1693,7 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1609
1693
|
|
|
1610
1694
|
def test_yylex_string_pct_w
|
|
1611
1695
|
util_bad_token("%w[s1 s2 ",
|
|
1612
|
-
:
|
|
1696
|
+
:tQWORDS_BEG, "%w[",
|
|
1613
1697
|
:tSTRING_CONTENT, "s1",
|
|
1614
1698
|
:tSPACE, nil,
|
|
1615
1699
|
:tSTRING_CONTENT, "s2",
|
|
@@ -1618,7 +1702,7 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1618
1702
|
|
|
1619
1703
|
def test_yylex_string_pct_w_bs_nl
|
|
1620
1704
|
util_lex_token("%w[s1 \\\ns2]",
|
|
1621
|
-
:
|
|
1705
|
+
:tQWORDS_BEG, "%w[",
|
|
1622
1706
|
:tSTRING_CONTENT, "s1",
|
|
1623
1707
|
:tSPACE, nil,
|
|
1624
1708
|
:tSTRING_CONTENT, "\ns2",
|
|
@@ -1628,7 +1712,7 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1628
1712
|
|
|
1629
1713
|
def test_yylex_string_pct_w_bs_sp
|
|
1630
1714
|
util_lex_token("%w[s\\ 1 s\\ 2]",
|
|
1631
|
-
:
|
|
1715
|
+
:tQWORDS_BEG, "%w[",
|
|
1632
1716
|
:tSTRING_CONTENT, "s 1",
|
|
1633
1717
|
:tSPACE, nil,
|
|
1634
1718
|
:tSTRING_CONTENT, "s 2",
|
|
@@ -1638,7 +1722,7 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1638
1722
|
|
|
1639
1723
|
def test_yylex_string_pct_w_tab
|
|
1640
1724
|
util_lex_token("%w[abc\tdef]",
|
|
1641
|
-
:
|
|
1725
|
+
:tQWORDS_BEG, "%w[",
|
|
1642
1726
|
:tSTRING_CONTENT, "abc\tdef",
|
|
1643
1727
|
:tSPACE, nil,
|
|
1644
1728
|
:tSTRING_END, nil)
|
|
@@ -1815,7 +1899,7 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
1815
1899
|
token = args.shift
|
|
1816
1900
|
value = args.shift
|
|
1817
1901
|
assert @lex.advance, "no more tokens"
|
|
1818
|
-
assert_equal [token, value], [@lex.token, @lex.yacc_value]
|
|
1902
|
+
assert_equal [token, value], [@lex.token, [@lex.yacc_value].flatten.first], input
|
|
1819
1903
|
end
|
|
1820
1904
|
|
|
1821
1905
|
deny @lex.advance, "must be empty, but had #{[@lex.token, @lex.yacc_value].inspect}"
|