ruby_parser 2.0.5 → 2.1.0
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 +3 -3
- data/.gemtest +0 -0
- data/History.txt +22 -0
- data/Manifest.txt +1 -0
- data/README.txt +2 -1
- data/Rakefile +6 -29
- data/lib/ruby_lexer.rb +5 -4
- data/lib/ruby_parser.rb +7 -7
- data/lib/ruby_parser.y +1 -1
- data/lib/ruby_parser_extras.rb +46 -35
- data/test/test_ruby_lexer.rb +5 -0
- data/test/test_ruby_parser.rb +97 -11
- data.tar.gz.sig +0 -0
- metadata +25 -43
- metadata.gz.sig +0 -0
data/.autotest
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# -*- ruby -*-
|
|
2
2
|
|
|
3
3
|
require 'autotest/restart'
|
|
4
|
+
require 'autotest/isolate'
|
|
4
5
|
require 'autotest/rcov' if ENV['RCOV']
|
|
5
6
|
|
|
6
7
|
Autotest.add_hook :initialize do |at|
|
|
7
|
-
at.extra_files << "../../
|
|
8
|
-
at.libs << ":../../
|
|
8
|
+
at.extra_files << "../../sexp_processor/dev/lib/pt_testcase.rb"
|
|
9
|
+
at.libs << ":../../sexp_processor/dev/lib"
|
|
9
10
|
at.add_exception 'unit'
|
|
10
11
|
at.add_exception 'coverage'
|
|
11
12
|
at.add_exception 'coverage.info'
|
|
@@ -13,7 +14,6 @@ Autotest.add_hook :initialize do |at|
|
|
|
13
14
|
|
|
14
15
|
at.libs << ':../../minitest/dev/lib'
|
|
15
16
|
at.testlib = "minitest/autorun"
|
|
16
|
-
at.unit_diff = "unit_diff -u -b"
|
|
17
17
|
|
|
18
18
|
at.add_mapping(/^lib\/.*\.y$/) do |f, _|
|
|
19
19
|
at.files_matching %r%^test/.*#{File.basename(f, '.y').gsub '_', '_?'}.rb$%
|
data/.gemtest
ADDED
|
File without changes
|
data/History.txt
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
=== 2.1.0 / 2011-08-15
|
|
2
|
+
|
|
3
|
+
* 2 minor enhancements:
|
|
4
|
+
|
|
5
|
+
* Added new accessor canonicalize_conditions to toggle conditional canonicalization (on by default). (confused)
|
|
6
|
+
* Awesome cleanup: Replaced call to append_block by block_append. (Confusion)
|
|
7
|
+
|
|
8
|
+
* 2 bug fixes:
|
|
9
|
+
|
|
10
|
+
* Fixed handling last line of =begin/=end. (raybaxter)
|
|
11
|
+
* Fixed source line numbers after heredocs. (jbarreneche)
|
|
12
|
+
|
|
13
|
+
=== 2.0.6 / 2011-02-18
|
|
14
|
+
|
|
15
|
+
* 1 minor enhancement:
|
|
16
|
+
|
|
17
|
+
* Switched to hoe's racc plugin to clean up rakefile and builds
|
|
18
|
+
|
|
19
|
+
* 1 bug fix:
|
|
20
|
+
|
|
21
|
+
* Fixed empty =begin/end.
|
|
22
|
+
|
|
1
23
|
=== 2.0.5 / 2010-09-01
|
|
2
24
|
|
|
3
25
|
* 1 minor enhancement:
|
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
data/Rakefile
CHANGED
|
@@ -4,41 +4,19 @@ require 'rubygems'
|
|
|
4
4
|
require 'hoe'
|
|
5
5
|
|
|
6
6
|
Hoe.plugin :seattlerb
|
|
7
|
+
Hoe.plugin :racc
|
|
8
|
+
Hoe.plugin :isolate
|
|
7
9
|
|
|
8
|
-
Hoe.add_include_dirs
|
|
9
|
-
"../../RubyInline/dev/lib",
|
|
10
|
-
"../../sexp_processor/dev/lib")
|
|
10
|
+
Hoe.add_include_dirs "../../sexp_processor/dev/lib"
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Hoe.spec 'ruby_parser' do
|
|
13
13
|
developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
|
|
14
14
|
|
|
15
15
|
self.rubyforge_name = 'parsetree'
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
extra_deps << ['sexp_processor', '~> 3.0']
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
hoe.spec.files += ['lib/ruby_parser.rb'] # jim.... cmon man
|
|
22
|
-
|
|
23
|
-
[:default, :multi, :test].each do |t|
|
|
24
|
-
task t => :parser
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
path = "pkg/ruby_parser-#{hoe.version}"
|
|
28
|
-
task path => :parser do
|
|
29
|
-
Dir.chdir path do
|
|
30
|
-
sh "rake parser"
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
desc "build the parser"
|
|
35
|
-
task :parser => ["lib/ruby_parser.rb"]
|
|
17
|
+
dependency 'sexp_processor', '~> 3.0'
|
|
36
18
|
|
|
37
|
-
|
|
38
|
-
# -v = verbose
|
|
39
|
-
# -t = debugging parser ~4% reduction in speed -- keep for now
|
|
40
|
-
# -l = no-line-convert
|
|
41
|
-
sh "racc -v -t -l -o #{t.name} #{t.source}"
|
|
19
|
+
self.perforce_ignore << "lib/ruby_parser.rb" if plugin? :perforce
|
|
42
20
|
end
|
|
43
21
|
|
|
44
22
|
task :clean do
|
|
@@ -46,7 +24,6 @@ task :clean do
|
|
|
46
24
|
Dir["**/*.diff"] +
|
|
47
25
|
Dir["coverage.info"] +
|
|
48
26
|
Dir["coverage"] +
|
|
49
|
-
Dir["lib/ruby_parser.rb"] +
|
|
50
27
|
Dir["lib/*.output"])
|
|
51
28
|
end
|
|
52
29
|
|
data/lib/ruby_lexer.rb
CHANGED
|
@@ -199,6 +199,7 @@ class RubyLexer
|
|
|
199
199
|
# TODO: think about storing off the char range instead
|
|
200
200
|
line = src.string[src.pos, src.matched_size]
|
|
201
201
|
src.string[src.pos, src.matched_size] = "\n"
|
|
202
|
+
src.extra_lines_added += 1
|
|
202
203
|
src.pos += 1
|
|
203
204
|
else
|
|
204
205
|
line = nil
|
|
@@ -231,7 +232,7 @@ class RubyLexer
|
|
|
231
232
|
end
|
|
232
233
|
|
|
233
234
|
def lex_state= o
|
|
234
|
-
raise "wtf
|
|
235
|
+
raise "wtf\?" unless Symbol === o
|
|
235
236
|
@lex_state = o
|
|
236
237
|
end
|
|
237
238
|
|
|
@@ -655,7 +656,7 @@ class RubyLexer
|
|
|
655
656
|
self.lineno = nil
|
|
656
657
|
c = src.matched
|
|
657
658
|
if c == '#' then
|
|
658
|
-
src.
|
|
659
|
+
src.pos -= 1
|
|
659
660
|
|
|
660
661
|
while src.scan(/\s*#.*(\n+|\z)/) do
|
|
661
662
|
@comments << src.matched.gsub(/^ +#/, '#').gsub(/^ +$/, '')
|
|
@@ -723,11 +724,11 @@ class RubyLexer
|
|
|
723
724
|
self.fix_arg_lex_state
|
|
724
725
|
tok = self.yacc_value = src.matched
|
|
725
726
|
return TOKENS[tok]
|
|
726
|
-
elsif src.
|
|
727
|
+
elsif src.scan(/\=begin(?=\s)/) then
|
|
727
728
|
# @comments << '=' << src.matched
|
|
728
729
|
@comments << src.matched
|
|
729
730
|
|
|
730
|
-
unless src.scan(/.*?\n=end\
|
|
731
|
+
unless src.scan(/.*?\n=end( |\t|\f)*[^(\n|\z)]*(\n|\z)/m) then
|
|
731
732
|
@comments.clear
|
|
732
733
|
rb_compile_error("embedded document meets end of file")
|
|
733
734
|
end
|
data/lib/ruby_parser.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#
|
|
2
2
|
# DO NOT MODIFY!!!!
|
|
3
|
-
# This file is automatically generated by Racc 1.4.
|
|
3
|
+
# This file is automatically generated by Racc 1.4.6
|
|
4
4
|
# from Racc grammer file "".
|
|
5
5
|
#
|
|
6
6
|
|
|
@@ -773,7 +773,7 @@ clist = [
|
|
|
773
773
|
'299,300,276,279,282,285,288,290,292,294,296,,301,278,,281,284,287,,',
|
|
774
774
|
',,,,,,,,,,,295,,298,,277,280,283,286,289,291,293,,297,,,,,,,,,,,,,,',
|
|
775
775
|
',281' ]
|
|
776
|
-
racc_action_table = arr =
|
|
776
|
+
racc_action_table = arr = Array.new(23872, nil)
|
|
777
777
|
idx = 0
|
|
778
778
|
clist.each do |str|
|
|
779
779
|
str.split(',', -1).each do |i|
|
|
@@ -1617,7 +1617,7 @@ clist = [
|
|
|
1617
1617
|
'747,747,747,747,747,747,747,,747,640,640,640,640,640,640,640,640,640',
|
|
1618
1618
|
'640,640,,640,640,,747,640,640,,,,,,,,,,,,,,640,,640,,640,640,640,640',
|
|
1619
1619
|
'640,640,640,,640,,,,,,,,,,,,,,,,640' ]
|
|
1620
|
-
racc_action_check = arr =
|
|
1620
|
+
racc_action_check = arr = Array.new(23872, nil)
|
|
1621
1621
|
idx = 0
|
|
1622
1622
|
clist.each do |str|
|
|
1623
1623
|
str.split(',', -1).each do |i|
|
|
@@ -1881,7 +1881,7 @@ clist = [
|
|
|
1881
1881
|
',,,,,,,,,,,,,,,,,,820,,,,823,,,,,,,,,,,38,,849,,832,,,835,,,,,38,,,',
|
|
1882
1882
|
',38,,,,,,,,,,,38,,,38,,,,,,,,,,,,38,661,38,,,,,,,584,,,589,,,,,,,,,',
|
|
1883
1883
|
',,,,,,,,,,,,,,880,,,,,882,,,885,,,,,,,,,,,,,,,,,,589,,,,,,,,,,,,,,900' ]
|
|
1884
|
-
racc_goto_table = arr =
|
|
1884
|
+
racc_goto_table = arr = Array.new(2455, nil)
|
|
1885
1885
|
idx = 0
|
|
1886
1886
|
clist.each do |str|
|
|
1887
1887
|
str.split(',', -1).each do |i|
|
|
@@ -1952,7 +1952,7 @@ clist = [
|
|
|
1952
1952
|
'45,,,,,45,,,,,,,,,,,,,,,,,,,24,,,,24,,,,,,,,,,,45,,45,,24,,,24,,,,,45',
|
|
1953
1953
|
',,,,45,,,,,,,,,,,45,,,45,,,,,,,,,,,,45,24,45,,,,,,,24,,,24,,,,,,,,,',
|
|
1954
1954
|
',,,,,,,,,,,,,,24,,,,,24,,,24,,,,,,,,,,,,,,,,,,24,,,,,,,,,,,,,,24' ]
|
|
1955
|
-
racc_goto_check = arr =
|
|
1955
|
+
racc_goto_check = arr = Array.new(2455, nil)
|
|
1956
1956
|
idx = 0
|
|
1957
1957
|
clist.each do |str|
|
|
1958
1958
|
str.split(',', -1).each do |i|
|
|
@@ -2941,7 +2941,7 @@ Racc_token_to_s_table = [
|
|
|
2941
2941
|
"@39",
|
|
2942
2942
|
"assoc" ]
|
|
2943
2943
|
|
|
2944
|
-
Racc_debug_parser =
|
|
2944
|
+
Racc_debug_parser = false
|
|
2945
2945
|
|
|
2946
2946
|
##### State transition tables end #####
|
|
2947
2947
|
|
|
@@ -5370,7 +5370,7 @@ def _reduce_460(val, _values, result)
|
|
|
5370
5370
|
end
|
|
5371
5371
|
|
|
5372
5372
|
def _reduce_461(val, _values, result)
|
|
5373
|
-
result = self.
|
|
5373
|
+
result = self.block_append val[0], val[2]
|
|
5374
5374
|
|
|
5375
5375
|
result
|
|
5376
5376
|
end
|
data/lib/ruby_parser.y
CHANGED
data/lib/ruby_parser_extras.rb
CHANGED
|
@@ -29,13 +29,20 @@ class RPStringScanner < StringScanner
|
|
|
29
29
|
# old_getch
|
|
30
30
|
# end
|
|
31
31
|
# end
|
|
32
|
-
|
|
33
32
|
def current_line # HAHA fuck you (HACK)
|
|
34
33
|
string[0..pos][/\A.*__LINE__/m].split(/\n/).size
|
|
35
34
|
end
|
|
36
35
|
|
|
36
|
+
def extra_lines_added
|
|
37
|
+
@extra_lines_added ||= 0
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def extra_lines_added= val
|
|
41
|
+
@extra_lines_added = val
|
|
42
|
+
end
|
|
43
|
+
|
|
37
44
|
def lineno
|
|
38
|
-
string[0...pos].count("\n") + 1
|
|
45
|
+
string[0...pos].count("\n") + 1 - extra_lines_added
|
|
39
46
|
end
|
|
40
47
|
|
|
41
48
|
# TODO: once we get rid of these, we can make things like
|
|
@@ -48,6 +55,7 @@ class RPStringScanner < StringScanner
|
|
|
48
55
|
|
|
49
56
|
def unread_many str # TODO: remove this entirely - we should not need it
|
|
50
57
|
warn({:unread_many => caller[0]}.inspect) if ENV['TALLY']
|
|
58
|
+
self.extra_lines_added += str.count("\n")
|
|
51
59
|
string[pos, 0] = str
|
|
52
60
|
end
|
|
53
61
|
|
|
@@ -115,20 +123,11 @@ class RPStringScanner < StringScanner
|
|
|
115
123
|
end
|
|
116
124
|
|
|
117
125
|
class RubyParser < Racc::Parser
|
|
118
|
-
VERSION = '2.0
|
|
126
|
+
VERSION = '2.1.0' unless constants.include? "VERSION" # SIGH
|
|
119
127
|
|
|
120
128
|
attr_accessor :lexer, :in_def, :in_single, :file
|
|
121
129
|
attr_reader :env, :comments
|
|
122
130
|
|
|
123
|
-
def append_to_block head, tail # FIX: wtf is this?!? switch to block_append
|
|
124
|
-
return head if tail.nil?
|
|
125
|
-
return tail if head.nil?
|
|
126
|
-
|
|
127
|
-
head = s(:block, head) unless head.node_type == :block
|
|
128
|
-
head << tail
|
|
129
|
-
head
|
|
130
|
-
end
|
|
131
|
-
|
|
132
131
|
def arg_add(node1, node2) # TODO: nuke
|
|
133
132
|
return s(:arglist, node2) unless node1
|
|
134
133
|
|
|
@@ -217,9 +216,9 @@ class RubyParser < Racc::Parser
|
|
|
217
216
|
return result
|
|
218
217
|
end
|
|
219
218
|
|
|
220
|
-
def block_append(head, tail
|
|
221
|
-
return head
|
|
222
|
-
return tail
|
|
219
|
+
def block_append(head, tail)
|
|
220
|
+
return head if tail.nil?
|
|
221
|
+
return tail if head.nil?
|
|
223
222
|
|
|
224
223
|
case head[0]
|
|
225
224
|
when :lit, :str then
|
|
@@ -229,16 +228,10 @@ class RubyParser < Racc::Parser
|
|
|
229
228
|
line = [head.line, tail.line].compact.min
|
|
230
229
|
|
|
231
230
|
head = remove_begin(head)
|
|
232
|
-
head = s(:block, head) unless head
|
|
233
|
-
|
|
234
|
-
if strip_tail_block and Sexp === tail and tail[0] == :block then
|
|
235
|
-
head.push(*tail.values)
|
|
236
|
-
else
|
|
237
|
-
head << tail
|
|
238
|
-
end
|
|
231
|
+
head = s(:block, head) unless head.node_type == :block
|
|
239
232
|
|
|
240
233
|
head.line = line
|
|
241
|
-
head
|
|
234
|
+
head << tail
|
|
242
235
|
end
|
|
243
236
|
|
|
244
237
|
def cond node
|
|
@@ -335,13 +328,26 @@ class RubyParser < Racc::Parser
|
|
|
335
328
|
raise "identifier #{id.inspect} is not valid"
|
|
336
329
|
end
|
|
337
330
|
|
|
338
|
-
|
|
339
|
-
|
|
331
|
+
##
|
|
332
|
+
# Canonicalize conditionals. Eg:
|
|
333
|
+
#
|
|
334
|
+
# not x ? a : b
|
|
335
|
+
#
|
|
336
|
+
# becomes:
|
|
337
|
+
#
|
|
338
|
+
# x ? b : a
|
|
339
|
+
|
|
340
|
+
attr_accessor :canonicalize_conditions
|
|
341
|
+
|
|
342
|
+
def initialize(options = {})
|
|
343
|
+
super()
|
|
340
344
|
self.lexer = RubyLexer.new
|
|
341
345
|
self.lexer.parser = self
|
|
342
346
|
@env = Environment.new
|
|
343
347
|
@comments = []
|
|
344
348
|
|
|
349
|
+
@canonicalize_conditions = true
|
|
350
|
+
|
|
345
351
|
self.reset
|
|
346
352
|
end
|
|
347
353
|
|
|
@@ -534,7 +540,7 @@ class RubyParser < Racc::Parser
|
|
|
534
540
|
def new_if c, t, f
|
|
535
541
|
l = [c.line, t && t.line, f && f.line].compact.min
|
|
536
542
|
c = cond c
|
|
537
|
-
c, t, f = c.last, f, t if c[0] == :not
|
|
543
|
+
c, t, f = c.last, f, t if c[0] == :not and canonicalize_conditions
|
|
538
544
|
s(:if, c, t, f).line(l)
|
|
539
545
|
end
|
|
540
546
|
|
|
@@ -658,26 +664,31 @@ class RubyParser < Racc::Parser
|
|
|
658
664
|
end
|
|
659
665
|
end
|
|
660
666
|
|
|
661
|
-
def
|
|
662
|
-
|
|
663
|
-
new_while block, expr, pre
|
|
664
|
-
end
|
|
665
|
-
|
|
666
|
-
def new_while block, expr, pre
|
|
667
|
+
def new_until_or_while type, block, expr, pre
|
|
668
|
+
other = type == :until ? :while : :until
|
|
667
669
|
line = [block && block.line, expr.line].compact.min
|
|
668
670
|
block, pre = block.last, false if block && block[0] == :begin
|
|
669
671
|
|
|
670
672
|
expr = cond expr
|
|
671
|
-
|
|
672
|
-
|
|
673
|
+
|
|
674
|
+
result = unless expr.first == :not and canonicalize_conditions then
|
|
675
|
+
s(type, expr, block, pre)
|
|
673
676
|
else
|
|
674
|
-
s(
|
|
677
|
+
s(other, expr.last, block, pre)
|
|
675
678
|
end
|
|
676
679
|
|
|
677
680
|
result.line = line
|
|
678
681
|
result
|
|
679
682
|
end
|
|
680
683
|
|
|
684
|
+
def new_until block, expr, pre
|
|
685
|
+
new_until_or_while :until, block, expr, pre
|
|
686
|
+
end
|
|
687
|
+
|
|
688
|
+
def new_while block, expr, pre
|
|
689
|
+
new_until_or_while :while, block, expr, pre
|
|
690
|
+
end
|
|
691
|
+
|
|
681
692
|
def new_xstring str
|
|
682
693
|
if str then
|
|
683
694
|
case str[0]
|
data/test/test_ruby_lexer.rb
CHANGED
|
@@ -255,6 +255,11 @@ class TestRubyLexer < MiniTest::Unit::TestCase
|
|
|
255
255
|
assert_equal "=begin blah\nblah\n=end\n", @lex.comments
|
|
256
256
|
end
|
|
257
257
|
|
|
258
|
+
def test_yylex_comment_end_space_and_text
|
|
259
|
+
util_lex_token("=begin blah\nblah\n=end blab\n")
|
|
260
|
+
assert_equal "=begin blah\nblah\n=end blab\n", @lex.comments
|
|
261
|
+
end
|
|
262
|
+
|
|
258
263
|
def test_yylex_comment_eos
|
|
259
264
|
util_lex_token("# comment")
|
|
260
265
|
end
|
data/test/test_ruby_parser.rb
CHANGED
|
@@ -33,8 +33,6 @@ class TestRubyParser < RubyParserTestCase
|
|
|
33
33
|
def setup
|
|
34
34
|
super
|
|
35
35
|
|
|
36
|
-
# puts self.name
|
|
37
|
-
|
|
38
36
|
@processor = RubyParser.new
|
|
39
37
|
end
|
|
40
38
|
|
|
@@ -175,6 +173,15 @@ class TestRubyParser < RubyParserTestCase
|
|
|
175
173
|
assert_equal pt, @processor.parse(rb)
|
|
176
174
|
end
|
|
177
175
|
|
|
176
|
+
def test_bug_comment_eq_begin
|
|
177
|
+
rb = "\n\n#\n=begin\nblah\n=end\n\n"
|
|
178
|
+
pt = nil
|
|
179
|
+
exp = rb.strip + "\n"
|
|
180
|
+
|
|
181
|
+
assert_equal pt, @processor.parse(rb)
|
|
182
|
+
assert_equal exp, @processor.lexer.comments
|
|
183
|
+
end
|
|
184
|
+
|
|
178
185
|
def test_dstr_evstr
|
|
179
186
|
rb = "\"#\{'a'}#\{b}\""
|
|
180
187
|
pt = s(:dstr, "a", s(:evstr, s(:call, nil, :b, s(:arglist))))
|
|
@@ -413,13 +420,13 @@ class TestRubyParser < RubyParserTestCase
|
|
|
413
420
|
"case_nested_inner_no_expr" => 2,
|
|
414
421
|
"case_no_expr" => 2,
|
|
415
422
|
"case_splat" => 2,
|
|
416
|
-
"dstr_heredoc_expand" =>
|
|
417
|
-
"dstr_heredoc_windoze_sucks" =>
|
|
418
|
-
"dstr_heredoc_yet_again" =>
|
|
419
|
-
"str_heredoc" =>
|
|
420
|
-
"str_heredoc_call" =>
|
|
421
|
-
"str_heredoc_empty" =>
|
|
422
|
-
"str_heredoc_indent" =>
|
|
423
|
+
"dstr_heredoc_expand" => 1,
|
|
424
|
+
"dstr_heredoc_windoze_sucks" => 1,
|
|
425
|
+
"dstr_heredoc_yet_again" => 1,
|
|
426
|
+
"str_heredoc" => 1,
|
|
427
|
+
"str_heredoc_call" => 1,
|
|
428
|
+
"str_heredoc_empty" => 1,
|
|
429
|
+
"str_heredoc_indent" => 1,
|
|
423
430
|
"structure_unused_literal_wwtt" => 3, # yes, 3... odd test
|
|
424
431
|
"undef_block_1" => 2,
|
|
425
432
|
"undef_block_2" => 2,
|
|
@@ -432,7 +439,7 @@ class TestRubyParser < RubyParserTestCase
|
|
|
432
439
|
assert_equal expected, @result.line, "should have proper line number"
|
|
433
440
|
end
|
|
434
441
|
|
|
435
|
-
def
|
|
442
|
+
def test_position_info_block
|
|
436
443
|
rb = "a = 42\np a"
|
|
437
444
|
pt = s(:block,
|
|
438
445
|
s(:lasgn, :a, s(:lit, 42)),
|
|
@@ -456,7 +463,7 @@ class TestRubyParser < RubyParserTestCase
|
|
|
456
463
|
assert_same result.file, result.call.file
|
|
457
464
|
end
|
|
458
465
|
|
|
459
|
-
def
|
|
466
|
+
def test_position_info_defn
|
|
460
467
|
rb = "def x(y)\n p(y)\n y *= 2\n return y;\nend" # TODO: remove () & ;
|
|
461
468
|
pt = s(:defn, :x, s(:args, :y),
|
|
462
469
|
s(:scope,
|
|
@@ -477,4 +484,83 @@ class TestRubyParser < RubyParserTestCase
|
|
|
477
484
|
assert_equal 3, body.lasgn.line, "lasgn should have line number"
|
|
478
485
|
assert_equal 4, body.return.line, "return should have line number"
|
|
479
486
|
end
|
|
487
|
+
|
|
488
|
+
def test_position_info_heredoc
|
|
489
|
+
rb = <<-CODE
|
|
490
|
+
string = <<-HEREDOC
|
|
491
|
+
very long string
|
|
492
|
+
HEREDOC
|
|
493
|
+
puts string
|
|
494
|
+
CODE
|
|
495
|
+
|
|
496
|
+
result = @processor.parse rb
|
|
497
|
+
assert_equal 1, result.lasgn.line
|
|
498
|
+
assert_equal 4, result.call.line
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
def test_parse_if_not_canonical
|
|
502
|
+
rb = "if not var.nil? then 'foo' else 'bar'\nend"
|
|
503
|
+
pt = s(:if,
|
|
504
|
+
s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist)),
|
|
505
|
+
s(:str, "bar"),
|
|
506
|
+
s(:str, "foo"))
|
|
507
|
+
|
|
508
|
+
assert_equal pt, @processor.parse(rb)
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
def test_parse_if_not_noncanonical
|
|
512
|
+
rb = "if not var.nil? then 'foo' else 'bar'\nend"
|
|
513
|
+
pt = s(:if,
|
|
514
|
+
s(:not,
|
|
515
|
+
s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist))),
|
|
516
|
+
s(:str, "foo"),
|
|
517
|
+
s(:str, "bar"))
|
|
518
|
+
|
|
519
|
+
@processor.canonicalize_conditions = false
|
|
520
|
+
|
|
521
|
+
assert_equal pt, @processor.parse(rb)
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
def test_parse_while_not_canonical
|
|
525
|
+
rb = "while not var.nil?\n 'foo'\nend"
|
|
526
|
+
pt = s(:until,
|
|
527
|
+
s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist)),
|
|
528
|
+
s(:str, "foo"), true)
|
|
529
|
+
|
|
530
|
+
assert_equal pt, @processor.parse(rb)
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
def test_parse_while_not_noncanonical
|
|
534
|
+
rb = "while not var.nil?\n 'foo'\nend"
|
|
535
|
+
pt = s(:while,
|
|
536
|
+
s(:not,
|
|
537
|
+
s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist))),
|
|
538
|
+
s(:str, "foo"), true)
|
|
539
|
+
|
|
540
|
+
@processor.canonicalize_conditions = false
|
|
541
|
+
|
|
542
|
+
assert_equal pt, @processor.parse(rb)
|
|
543
|
+
end
|
|
544
|
+
|
|
545
|
+
def test_parse_until_not_canonical
|
|
546
|
+
rb = "until not var.nil?\n 'foo'\nend"
|
|
547
|
+
|
|
548
|
+
pt = s(:while,
|
|
549
|
+
s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist)),
|
|
550
|
+
s(:str, "foo"), true)
|
|
551
|
+
|
|
552
|
+
assert_equal pt, @processor.parse(rb)
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
def test_parse_until_not_noncanonical
|
|
556
|
+
rb = "until not var.nil?\n 'foo'\nend"
|
|
557
|
+
pt = s(:until,
|
|
558
|
+
s(:not,
|
|
559
|
+
s(:call, s(:call, nil, :var, s(:arglist)), :nil?, s(:arglist))),
|
|
560
|
+
s(:str, "foo"), true)
|
|
561
|
+
|
|
562
|
+
@processor.canonicalize_conditions = false
|
|
563
|
+
|
|
564
|
+
assert_equal pt, @processor.parse(rb)
|
|
565
|
+
end
|
|
480
566
|
end
|
data.tar.gz.sig
CHANGED
|
Binary file
|
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:
|
|
5
|
-
prerelease:
|
|
4
|
+
hash: 11
|
|
5
|
+
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 2
|
|
8
|
+
- 1
|
|
8
9
|
- 0
|
|
9
|
-
|
|
10
|
-
version: 2.0.5
|
|
10
|
+
version: 2.1.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Ryan Davis
|
|
@@ -36,8 +36,7 @@ cert_chain:
|
|
|
36
36
|
FBHgymkyj/AOSqKRIpXPhjC6
|
|
37
37
|
-----END CERTIFICATE-----
|
|
38
38
|
|
|
39
|
-
date:
|
|
40
|
-
default_executable:
|
|
39
|
+
date: 2011-08-15 00:00:00 Z
|
|
41
40
|
dependencies:
|
|
42
41
|
- !ruby/object:Gem::Dependency
|
|
43
42
|
name: sexp_processor
|
|
@@ -55,19 +54,19 @@ dependencies:
|
|
|
55
54
|
type: :runtime
|
|
56
55
|
version_requirements: *id001
|
|
57
56
|
- !ruby/object:Gem::Dependency
|
|
58
|
-
name:
|
|
57
|
+
name: racc
|
|
59
58
|
prerelease: false
|
|
60
59
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
61
60
|
none: false
|
|
62
61
|
requirements:
|
|
63
|
-
- -
|
|
62
|
+
- - ~>
|
|
64
63
|
- !ruby/object:Gem::Version
|
|
65
|
-
hash:
|
|
64
|
+
hash: 11
|
|
66
65
|
segments:
|
|
67
|
-
-
|
|
68
|
-
- 0
|
|
66
|
+
- 1
|
|
69
67
|
- 4
|
|
70
|
-
|
|
68
|
+
- 6
|
|
69
|
+
version: 1.4.6
|
|
71
70
|
type: :development
|
|
72
71
|
version_requirements: *id002
|
|
73
72
|
- !ruby/object:Gem::Dependency
|
|
@@ -76,47 +75,30 @@ dependencies:
|
|
|
76
75
|
requirement: &id003 !ruby/object:Gem::Requirement
|
|
77
76
|
none: false
|
|
78
77
|
requirements:
|
|
79
|
-
- -
|
|
78
|
+
- - ~>
|
|
80
79
|
- !ruby/object:Gem::Version
|
|
81
|
-
hash:
|
|
80
|
+
hash: 11
|
|
82
81
|
segments:
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
|
|
86
|
-
version: 1.7.1
|
|
82
|
+
- 2
|
|
83
|
+
- 4
|
|
84
|
+
version: "2.4"
|
|
87
85
|
type: :development
|
|
88
86
|
version_requirements: *id003
|
|
89
87
|
- !ruby/object:Gem::Dependency
|
|
90
|
-
name:
|
|
88
|
+
name: hoe
|
|
91
89
|
prerelease: false
|
|
92
90
|
requirement: &id004 !ruby/object:Gem::Requirement
|
|
93
91
|
none: false
|
|
94
92
|
requirements:
|
|
95
93
|
- - ~>
|
|
96
94
|
- !ruby/object:Gem::Version
|
|
97
|
-
hash:
|
|
95
|
+
hash: 21
|
|
98
96
|
segments:
|
|
99
|
-
- 3
|
|
100
|
-
- 0
|
|
101
|
-
version: "3.0"
|
|
102
|
-
type: :development
|
|
103
|
-
version_requirements: *id004
|
|
104
|
-
- !ruby/object:Gem::Dependency
|
|
105
|
-
name: hoe
|
|
106
|
-
prerelease: false
|
|
107
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
|
108
|
-
none: false
|
|
109
|
-
requirements:
|
|
110
|
-
- - ">="
|
|
111
|
-
- !ruby/object:Gem::Version
|
|
112
|
-
hash: 19
|
|
113
|
-
segments:
|
|
114
|
-
- 2
|
|
115
|
-
- 6
|
|
116
97
|
- 2
|
|
117
|
-
|
|
98
|
+
- 11
|
|
99
|
+
version: "2.11"
|
|
118
100
|
type: :development
|
|
119
|
-
version_requirements: *
|
|
101
|
+
version_requirements: *id004
|
|
120
102
|
description: |-
|
|
121
103
|
ruby_parser (RP) is a ruby parser written in pure ruby (utilizing
|
|
122
104
|
racc--which does by default use a C extension). RP's output is
|
|
@@ -163,13 +145,13 @@ files:
|
|
|
163
145
|
- lib/gauntlet_rubyparser.rb
|
|
164
146
|
- lib/ruby_lexer.rb
|
|
165
147
|
- lib/ruby_parser.y
|
|
148
|
+
- lib/ruby_parser.rb
|
|
166
149
|
- lib/ruby_parser_extras.rb
|
|
167
150
|
- test/test_ruby_lexer.rb
|
|
168
151
|
- test/test_ruby_parser.rb
|
|
169
152
|
- test/test_ruby_parser_extras.rb
|
|
170
|
-
-
|
|
171
|
-
|
|
172
|
-
homepage: http://parsetree.rubyforge.org/
|
|
153
|
+
- .gemtest
|
|
154
|
+
homepage: https://github.com/seattlerb/ruby_parser
|
|
173
155
|
licenses: []
|
|
174
156
|
|
|
175
157
|
post_install_message:
|
|
@@ -199,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
199
181
|
requirements: []
|
|
200
182
|
|
|
201
183
|
rubyforge_project: parsetree
|
|
202
|
-
rubygems_version: 1.
|
|
184
|
+
rubygems_version: 1.8.5
|
|
203
185
|
signing_key:
|
|
204
186
|
specification_version: 3
|
|
205
187
|
summary: ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which does by default use a C extension)
|
metadata.gz.sig
CHANGED
|
Binary file
|