ruby_parser 3.2.0 → 3.2.1
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.tar.gz.sig +0 -0
- data/History.txt +6 -0
- data/README.txt +16 -10
- data/lib/ruby20_parser.rb +6 -4
- data/lib/ruby20_parser.y +6 -4
- data/lib/ruby_parser_extras.rb +7 -2
- data/test/test_ruby_parser.rb +28 -0
- metadata +19 -13
- metadata.gz.sig +3 -1
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -13,19 +13,25 @@ base types.
|
|
13
13
|
|
14
14
|
As an example:
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def conditional1 arg1
|
17
|
+
return 1 if arg1 == 0
|
18
|
+
return 0
|
19
|
+
end
|
20
20
|
|
21
21
|
becomes:
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
s(:defn, :conditional1, s(:args, :arg1),
|
24
|
+
s(:if,
|
25
|
+
s(:call, s(:lvar, :arg1), :==, s(:lit, 0)),
|
26
|
+
s(:return, s(:lit, 1)),
|
27
|
+
nil),
|
28
|
+
s(:return, s(:lit, 0)))
|
29
|
+
|
30
|
+
Tested against 801,039 files from the latest of all rubygems (as of 2013-05):
|
31
|
+
|
32
|
+
* 1.8 parser is at 99.9739% accuracy, 3.651 sigma
|
33
|
+
* 1.9 parser is at 99.9940% accuracy, 4.013 sigma
|
34
|
+
* 2.0 parser is at 99.9939% accuracy, 4.008 sigma
|
29
35
|
|
30
36
|
== FEATURES/PROBLEMS:
|
31
37
|
|
data/lib/ruby20_parser.rb
CHANGED
@@ -4510,13 +4510,14 @@ def _reduce_244(val, _values, result)
|
|
4510
4510
|
end
|
4511
4511
|
|
4512
4512
|
def _reduce_245(val, _values, result)
|
4513
|
-
result = args [val[0],
|
4513
|
+
result = args [val[0], array_to_hash(val[2])]
|
4514
4514
|
|
4515
4515
|
result
|
4516
4516
|
end
|
4517
4517
|
|
4518
4518
|
def _reduce_246(val, _values, result)
|
4519
|
-
result =
|
4519
|
+
result = args [array_to_hash(val[0])]
|
4520
|
+
result[0] = :array # TODO: switch to args?
|
4520
4521
|
|
4521
4522
|
result
|
4522
4523
|
end
|
@@ -4583,7 +4584,8 @@ def _reduce_257(val, _values, result)
|
|
4583
4584
|
end
|
4584
4585
|
|
4585
4586
|
def _reduce_258(val, _values, result)
|
4586
|
-
result = call_args val
|
4587
|
+
result = call_args [val[0], array_to_hash(val[2])]
|
4588
|
+
result = self.arg_blk_pass result, val[3]
|
4587
4589
|
|
4588
4590
|
result
|
4589
4591
|
end
|
@@ -4753,7 +4755,7 @@ def _reduce_291(val, _values, result)
|
|
4753
4755
|
end
|
4754
4756
|
|
4755
4757
|
def _reduce_292(val, _values, result)
|
4756
|
-
result = s(:hash, *val[1].values)
|
4758
|
+
result = s(:hash, *val[1].values) # TODO: array_to_hash?
|
4757
4759
|
|
4758
4760
|
result
|
4759
4761
|
end
|
data/lib/ruby20_parser.y
CHANGED
@@ -794,11 +794,12 @@ rule
|
|
794
794
|
}
|
795
795
|
| args tCOMMA assocs trailer
|
796
796
|
{
|
797
|
-
result = args [val[0],
|
797
|
+
result = args [val[0], array_to_hash(val[2])]
|
798
798
|
}
|
799
799
|
| assocs trailer
|
800
800
|
{
|
801
|
-
result =
|
801
|
+
result = args [array_to_hash(val[0])]
|
802
|
+
result[0] = :array # TODO: switch to args?
|
802
803
|
}
|
803
804
|
|
804
805
|
paren_args: tLPAREN2 opt_call_args rparen
|
@@ -847,7 +848,8 @@ rule
|
|
847
848
|
}
|
848
849
|
| args tCOMMA assocs opt_block_arg
|
849
850
|
{
|
850
|
-
result = call_args val
|
851
|
+
result = call_args [val[0], array_to_hash(val[2])]
|
852
|
+
result = self.arg_blk_pass result, val[3]
|
851
853
|
}
|
852
854
|
| block_arg
|
853
855
|
{
|
@@ -965,7 +967,7 @@ rule
|
|
965
967
|
}
|
966
968
|
| tLBRACE assoc_list tRCURLY
|
967
969
|
{
|
968
|
-
result = s(:hash, *val[1].values)
|
970
|
+
result = s(:hash, *val[1].values) # TODO: array_to_hash?
|
969
971
|
}
|
970
972
|
| kRETURN
|
971
973
|
{
|
data/lib/ruby_parser_extras.rb
CHANGED
@@ -111,7 +111,7 @@ class RPStringScanner < StringScanner
|
|
111
111
|
end
|
112
112
|
|
113
113
|
module RubyParserStuff
|
114
|
-
VERSION = "3.2.
|
114
|
+
VERSION = "3.2.1" unless constants.include? "VERSION" # SIGH
|
115
115
|
|
116
116
|
attr_accessor :lexer, :in_def, :in_single, :file
|
117
117
|
attr_reader :env, :comments
|
@@ -214,7 +214,12 @@ module RubyParserStuff
|
|
214
214
|
end
|
215
215
|
|
216
216
|
def array_to_hash array
|
217
|
-
|
217
|
+
case array.sexp_type
|
218
|
+
when :kwsplat then
|
219
|
+
array
|
220
|
+
else
|
221
|
+
s(:hash, *array[1..-1])
|
222
|
+
end
|
218
223
|
end
|
219
224
|
|
220
225
|
def call_args args
|
data/test/test_ruby_parser.rb
CHANGED
@@ -1681,6 +1681,27 @@ module TestRubyParserShared1920
|
|
1681
1681
|
assert_parse rb, pt
|
1682
1682
|
end
|
1683
1683
|
|
1684
|
+
def test_call_arg_assoc
|
1685
|
+
rb = "f(1, 2=>3)"
|
1686
|
+
pt = s(:call, nil, :f, s(:lit, 1), s(:hash, s(:lit, 2), s(:lit, 3)))
|
1687
|
+
|
1688
|
+
assert_parse rb, pt
|
1689
|
+
end
|
1690
|
+
|
1691
|
+
def test_call_assoc
|
1692
|
+
rb = "f(2=>3)"
|
1693
|
+
pt = s(:call, nil, :f, s(:hash, s(:lit, 2), s(:lit, 3)))
|
1694
|
+
|
1695
|
+
assert_parse rb, pt
|
1696
|
+
end
|
1697
|
+
|
1698
|
+
def test_call_assoc_new
|
1699
|
+
rb = "f(a:3)"
|
1700
|
+
pt = s(:call, nil, :f, s(:hash, s(:lit, :a), s(:lit, 3)))
|
1701
|
+
|
1702
|
+
assert_parse rb, pt
|
1703
|
+
end
|
1704
|
+
|
1684
1705
|
def test_do_lambda
|
1685
1706
|
rb = "->() do end"
|
1686
1707
|
pt = s(:iter, s(:call, nil, :lambda), 0)
|
@@ -2750,6 +2771,13 @@ class TestRuby20Parser < RubyParserTestCase
|
|
2750
2771
|
assert_parse rb, pt
|
2751
2772
|
end
|
2752
2773
|
|
2774
|
+
def test_call_kwsplat
|
2775
|
+
rb = "a(**1)"
|
2776
|
+
pt = s(:call, nil, :a, s(:kwsplat, s(:lit, 1)))
|
2777
|
+
|
2778
|
+
assert_parse rb, pt
|
2779
|
+
end
|
2780
|
+
|
2753
2781
|
def test_iter_kwarg
|
2754
2782
|
rb = "a { |b: 1| }"
|
2755
2783
|
pt = s(:iter, s(:call, nil, :a), s(:args, s(:kwarg, :b, s(:lit, 1))))
|
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: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 3.2.
|
9
|
+
- 1
|
10
|
+
version: 3.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Davis
|
@@ -136,19 +136,25 @@ description: |-
|
|
136
136
|
|
137
137
|
As an example:
|
138
138
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
139
|
+
def conditional1 arg1
|
140
|
+
return 1 if arg1 == 0
|
141
|
+
return 0
|
142
|
+
end
|
143
143
|
|
144
144
|
becomes:
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
146
|
+
s(:defn, :conditional1, s(:args, :arg1),
|
147
|
+
s(:if,
|
148
|
+
s(:call, s(:lvar, :arg1), :==, s(:lit, 0)),
|
149
|
+
s(:return, s(:lit, 1)),
|
150
|
+
nil),
|
151
|
+
s(:return, s(:lit, 0)))
|
152
|
+
|
153
|
+
Tested against 801,039 files from the latest of all rubygems (as of 2013-05):
|
154
|
+
|
155
|
+
* 1.8 parser is at 99.9739% accuracy, 3.651 sigma
|
156
|
+
* 1.9 parser is at 99.9940% accuracy, 4.013 sigma
|
157
|
+
* 2.0 parser is at 99.9939% accuracy, 4.008 sigma
|
152
158
|
email:
|
153
159
|
- ryand-ruby@zenspider.com
|
154
160
|
executables:
|
metadata.gz.sig
CHANGED
@@ -1 +1,3 @@
|
|
1
|
-
|
1
|
+
5�� �G�s�ڶ��)1�X\5+��BCј&�%'�o�6�g�f7�v�<)�g]?��J7��K���G����exE8
|
2
|
+
�g L�Ún��h��Dl+��p�;�ڟ� ���;[xF�
|
3
|
+
~�U�6��8_أ3��� �!4�!xM��k��v�$���R���#��+�*r��
|