jruby-parser 0.3

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.
@@ -0,0 +1,23 @@
1
+ require 'java'
2
+
3
+ import java.io.StringReader
4
+ import org.jrubyparser.Parser
5
+ import org.jrubyparser.parser.ParserConfiguration
6
+ import org.jrubyparser.CompatVersion
7
+
8
+ PARSER = Parser.new
9
+ CONFIG_18 = ParserConfiguration.new
10
+ CONFIG_19 = ParserConfiguration.new(0, CompatVersion::RUBY1_9)
11
+
12
+ class Object
13
+ # Wrap the code in what the JRubyParser expects
14
+ def source(code)
15
+ StringReader.new code.to_s
16
+ end
17
+
18
+ # Parse the provided code into an AST
19
+ def parse(code, version=1.8)
20
+ config = version == 1.8 ? CONFIG_18 : CONFIG_19
21
+ PARSER.parse "<code>", source(code), config
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
2
+ require 'java'
3
+ require 'jruby-parser'
4
+
5
+ describe JRubyParser do
6
+ [JRubyParser::Compat::RUBY1_8, JRubyParser::Compat::RUBY1_9].each do |v|
7
+ it "finds fcall via simple symbol search" do
8
+ JRubyParser.parse("b = foo(1)").tap do |root|
9
+ fcall = root.find_type(:fcall)
10
+ fcall.should_not == nil
11
+ end
12
+ end
13
+
14
+ it "finds specific fcall by block and simple symbol" do
15
+ JRubyParser.parse("foo(1); bar(2)").tap do |root|
16
+ fcall = root.find_type(:fcall) { |n| n.name == "bar" }
17
+ fcall.name.should == "bar"
18
+ end
19
+ end
20
+
21
+ it "finds type and method named based on Enumerable find" do
22
+ JRubyParser.parse("foo(1); bar(2)").tap do |root|
23
+ fcall = root.find { |n| n.short_name == "fcall" && n.name == "bar"}
24
+ fcall.name.should == "bar"
25
+ fcalls = root.find_all { |n| n.short_name == "fcall" }
26
+ fcalls.size.should == 2
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,57 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
2
+ require 'jruby-parser'
3
+
4
+ describe JRubyParser do
5
+ [JRubyParser::Compat::RUBY1_8, JRubyParser::Compat::RUBY1_9].each do |v|
6
+ it "rewrites method name from foo to bar" do
7
+ JRubyParser.parse("b = foo(1)").tap do |root|
8
+ fcall = root.find_node(:fcall)
9
+ fcall.name = 'bar'
10
+ end.to_source.should == "b = bar(1)"
11
+
12
+ JRubyParser.parse("b = foo 1").tap do |root|
13
+ fcall = root.find_node(:fcall)
14
+ fcall.name = 'bar'
15
+ end.to_source.should == "b = bar 1"
16
+ end
17
+
18
+ it "rewrites between different coercible ruby types" do
19
+ [1, 1.0, true, false, nil, "a"].each do |replace|
20
+ JRubyParser.parse("foo 1").tap do |root|
21
+ fcall = root.find_node(:fcall)
22
+ fcall.args[0] = replace
23
+ end.to_source.should == "foo #{replace.inspect}"
24
+ end
25
+ end
26
+
27
+ it "rewrites receiver of a call" do
28
+ JRubyParser.parse("1.to_f(1)").tap do |root|
29
+ call = root.find_node(:call)
30
+ call.receiver = 2
31
+ end.to_source.should == "2.to_f(1)"
32
+ end
33
+
34
+ it "rewrites can add to simple args" do
35
+ JRubyParser.parse("foo(1)").tap do |root|
36
+ call = root.find_node(:fcall)
37
+ call.args << 2
38
+ end.to_source.should == "foo(1, 2)"
39
+ end
40
+
41
+ it "rewrites can add to simple args" do
42
+ JRubyParser.parse("foo(1)").tap do |root|
43
+ call = root.find_node(:fcall)
44
+ call.args = [3, 4]
45
+ end.to_source.should == "foo(3, 4)"
46
+ end
47
+
48
+ it "rewrites op element assignment" do
49
+ JRubyParser.parse("a[3] += 5").tap do |root|
50
+ op = root.find_node(:opelementasgn)
51
+ op.receiver = 1
52
+ op.args[0] = 2
53
+ op.value = 3
54
+ end.to_source.should == "1[2] += 3"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
3
+ require 'jruby-parser'
4
+ require 'parser_helpers'
5
+ require 'node_helpers'
6
+
7
+ describe Parser do
8
+ [1.8, 1.9].each do |v|
9
+ it "should parse alias with quotationmarks" do
10
+ parse(%Q{alias :'<==>' :"foo"}, v).find_node(:alias).tap do |aliasn|
11
+ aliasn.new_name.find_node(:symbol).name.should == "<==>"
12
+ aliasn.old_name.find_node(:symbol).name.should == "foo"
13
+ aliasn.should have_position(0,0,0,20)
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
3
+ require 'jruby-parser'
4
+ require 'parser_helpers'
5
+ require 'node_helpers'
6
+
7
+ import org.jrubyparser.lexer.StringTerm
8
+ import org.jrubyparser.lexer.SyntaxException
9
+
10
+ # tests for broken files
11
+ describe Parser do
12
+ [1.8, 1.9].each do |v|
13
+ it "should raise an unterminated string exception" do
14
+ lambda {
15
+ parse('str = "', v)
16
+ }.should raise_error StringTerm::UnterminatedStringException
17
+ end
18
+
19
+ it "should raise a syntax exception" do
20
+ lambda {
21
+ parse("class Foo\n def\nend\n", v)
22
+ }.should raise_error SyntaxException
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,129 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
3
+ require 'jruby-parser'
4
+ require 'parser_helpers'
5
+ require 'node_helpers'
6
+
7
+ describe Parser do
8
+ [1.8, 1.9].each do |v|
9
+ it "parses a 0-arg method sans parens [#{v}]" do
10
+ parse("def foo\nend\n", v).find_node(:defn).tap do |defn|
11
+ defn.should have_name_and_position("foo", 0, 1, 0, 11)
12
+ defn.args_node.should have_arg_counts(0, 0, false, false)
13
+ end
14
+ end
15
+
16
+ it "parses a 0-arg method with parens [#{v}]" do
17
+ parse("def foo()\nend\n", v).find_node(:defn).tap do |defn|
18
+ defn.should have_name_and_position("foo", 0, 1, 0, 13)
19
+ defn.args_node.should have_arg_counts(0, 0, false, false)
20
+ end
21
+ end
22
+
23
+ it "parses a 1-arg method sans parens [#{v}]" do
24
+ parse("def foo a\nend\n", v).find_node(:defn).tap do |defn|
25
+ defn.should have_name_and_position("foo", 0, 1, 0, 13)
26
+ defn.args_node.should have_arg_counts(1, 0, false, false)
27
+ defn.args_node.pre.tap do |pre|
28
+ pre.should have_position(0, 0, 8, 9)
29
+ pre[0].should have_name_and_position("a", 0, 0, 8, 9)
30
+ end
31
+ end
32
+ end
33
+
34
+ it "parses a 1-arg method with parens [#{v}]" do
35
+ parse("def foo(a)\nend\n", v).find_node(:defn).tap do |defn|
36
+ defn.should have_name_and_position("foo", 0, 1, 0, 14)
37
+ defn.args_node.should have_arg_counts(1, 0, false, false)
38
+ defn.args_node.pre.tap do |pre|
39
+ pre.should have_position(0, 0, 8, 9)
40
+ pre[0].should have_name_and_position("a", 0, 0, 8, 9)
41
+ end
42
+ end
43
+ end
44
+
45
+ it "parses a 2-arg method sans parens [#{v}]" do
46
+ parse("def foo a, b\nend\n", v).find_node(:defn).tap do |defn|
47
+ defn.should have_name_and_position("foo", 0, 1, 0, 16)
48
+ defn.args_node.should have_arg_counts(2, 0, false, false)
49
+ defn.args_node.pre.tap do |pre|
50
+ pre.should have_position(0, 0, 8, 12)
51
+ pre[0].should have_name_and_position("a", 0, 0, 8, 9)
52
+ pre[1].should have_name_and_position("b", 0, 0, 11, 12)
53
+ end
54
+ end
55
+ end
56
+
57
+ it "parses a 2-arg method with parens [#{v}]" do
58
+ parse("def foo(a, b)\nend\n", v).find_node(:defn) do |defn|
59
+ defn.should have_name_and_position("foo", 0, 1, 0, 17)
60
+ defn.args_node.should have_arg_counts(2, 0, false, false)
61
+ defn.args_node.pre.tap do |pre|
62
+ pre.should have_position(0, 0, 8, 12)
63
+ pre[0].should have_name_and_position("a", 0, 0, 8, 9)
64
+ pre[1].should have_name_and_position("b", 0, 0, 11, 12)
65
+ end
66
+ end
67
+ end
68
+
69
+ it "parses a 1-optarg method sans parens [#{v}]" do
70
+ parse("def foo a=1\nend\n", v).find_node(:defn).tap do |defn|
71
+ defn.should have_name_and_position("foo", 0, 1, 0, 15)
72
+ defn.args_node.should have_arg_counts(0, 1, false, false)
73
+ lasgn = defn.args_node.optional.find_node(:localasgn)
74
+ lasgn.should have_name_and_position("a", 0, 0, 8, 11)
75
+ end
76
+ end
77
+
78
+ it "parses a 1-optarg method with parens [#{v}]" do
79
+ parse("def foo(a=1)\nend\n", v).find_node(:defn).tap do |defn|
80
+ defn.should have_name_and_position("foo", 0, 1, 0, 16)
81
+ defn.args_node.should have_arg_counts(0, 1, false, false)
82
+ lasgn = defn.args_node.optional.find_node(:localasgn)
83
+ lasgn.should have_name_and_position("a", 0, 0, 8, 11)
84
+ end
85
+ end
86
+
87
+ it "parses a rest-arg method sans parens [#{v}]" do
88
+ parse("def foo *a\nend\n", v).find_node(:defn).tap do |defn|
89
+ defn.should have_name_and_position("foo", 0, 1, 0, 14)
90
+ defn.args_node.should have_arg_counts(0, 0, true, false)
91
+ end
92
+ end
93
+
94
+ it "parses a rest-arg method with parens [#{v}]" do
95
+ parse("def foo(*a)\nend\n", v).find_node(:defn).tap do |defn|
96
+ defn.should have_name_and_position("foo", 0, 1, 0, 15)
97
+ defn.args_node.should have_arg_counts(0, 0, true, false)
98
+ end
99
+ end
100
+
101
+ it "parses a block-arg method sans parens [#{v}]" do
102
+ parse("def foo &a\nend\n", v).find_node(:defn).tap do |defn|
103
+ defn.should have_name_and_position("foo", 0, 1, 0, 14)
104
+ defn.args_node.should have_arg_counts(0, 0, false, true)
105
+ end
106
+ end
107
+
108
+ it "parses a block-arg method with parens [#{v}]" do
109
+ parse("def foo(&a)\nend\n", v).find_node(:defn).tap do |defn|
110
+ defn.should have_name_and_position("foo", 0, 1, 0, 15)
111
+ defn.args_node.should have_arg_counts(0, 0, false, true)
112
+ end
113
+ end
114
+
115
+ it "parses a mixed-arg method sans parens [#{v}]" do
116
+ parse("def foo a, b, c = 1, *d\nend\n", v).find_node(:defn).tap do |defn|
117
+ defn.should have_name_and_position("foo", 0, 1, 0, 27)
118
+ defn.args_node.should have_arg_counts(2, 1, true, false)
119
+ end
120
+ end
121
+
122
+ it "parses a mixed-arg method with parens [#{v}]" do
123
+ parse("def foo(a, b, c = 1, *d)\nend\n", v).find_node(:defn).tap do |defn|
124
+ defn.should have_name_and_position("foo", 0, 1, 0, 28)
125
+ defn.args_node.should have_arg_counts(2, 1, true, false)
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,132 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
3
+ require 'jruby-parser'
4
+ require 'parser_helpers'
5
+ require 'node_helpers'
6
+
7
+ describe Parser do
8
+ [1.8, 1.9].each do |v|
9
+ it "parses a 0-arg method call sans parens +extra line [#{v}]" do
10
+ parse("\nputs\n", v).find_node(:vcall).tap do |call|
11
+ call.should have_name_and_position("puts", 1, 1, 1, 5)
12
+ end
13
+ end
14
+
15
+ it "parses a 0-arg method call with parens [#{v}]" do
16
+ parse("puts()", v).find_node(:fcall).tap do |call|
17
+ call.should have_name_and_position("puts", 0, 0, 0, 6)
18
+ call.args_node.size.should == 0
19
+ end
20
+ end
21
+
22
+ it "parses a 1-arg method call with parens [#{v}]" do
23
+ parse("puts(1)", v).find_node(:fcall).tap do |call|
24
+ call.should have_name_and_position("puts", 0, 0, 0, 7)
25
+ call.args_node.size.should == 1
26
+ end
27
+ end
28
+
29
+ it "parses a 1-arg method call without parens [#{v}]" do
30
+ parse("puts 1", v).find_node(:fcall).tap do |call|
31
+ call.should have_name_and_position("puts", 0, 0, 0, 6)
32
+ call.args_node.size.should == 1
33
+ end
34
+ end
35
+
36
+ it "parses a 2-arg method call with parens [#{v}]" do
37
+ parse("puts(1,2)", v).find_node(:fcall).tap do |call|
38
+ call.should have_name_and_position("puts", 0, 0, 0, 9)
39
+ call.args_node.size.should == 2
40
+ end
41
+ end
42
+
43
+ it "parses a 2-arg method call without parens [#{v}]" do
44
+ parse("puts 1, 2", v).find_node(:fcall).tap do |call|
45
+ call.should have_name_and_position("puts", 0, 0, 0, 9)
46
+ call.args_node.size.should == 2
47
+ end
48
+ end
49
+
50
+ it "parses a 0-arg object.method call without parens [#{v}]" do
51
+ parse("Array.new", v).find_node(:call).tap do |call|
52
+ call.should have_name_and_position("new", 0, 0, 0, 9)
53
+ call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5)
54
+ call.args_node.size.should == 0
55
+ end
56
+ end
57
+
58
+ it "parses a 0-arg object.method call with parens [#{v}]" do
59
+ parse("Array.new()", v).find_node(:call).tap do |call|
60
+ call.should have_name_and_position("new", 0, 0, 0, 11)
61
+ call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5)
62
+ call.args_node.size.should == 0
63
+ end
64
+ end
65
+
66
+ it "parses a 1-arg object.method call without parens [#{v}]" do
67
+ parse("Array.new 1", v).find_node(:call).tap do |call|
68
+ call.should have_name_and_position("new", 0, 0, 0, 11)
69
+ call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5)
70
+ call.args_node.size.should == 1
71
+ end
72
+ end
73
+
74
+ it "parses a 1-arg object.method call with parens [#{v}]" do
75
+ parse("Array.new(1)", v).find_node(:call).tap do |call|
76
+ call.should have_name_and_position("new", 0, 0, 0, 12)
77
+ call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5)
78
+ call.args_node.size.should == 1
79
+ end
80
+ end
81
+
82
+ it "parses a 1-arg infix method [#{v}]" do
83
+ parse("4 + 5", v).find_node(:call).tap do |call|
84
+ call.should have_name_and_position("+", 0, 0, 0, 5)
85
+ call.receiver_node.should have_position(0, 0, 0, 1)
86
+ call.args_node.size.should == 1
87
+ end
88
+ end
89
+
90
+ it "parses a 1-arg object.method call with infix operator as arg [#{v}]" do
91
+ parse("Array.new 4 + 5", v).find_node(:call).tap do |call|
92
+ call.should have_name_and_position("new", 0, 0, 0, 15)
93
+ call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5)
94
+ call.args_node.size.should == 1
95
+ end
96
+ end
97
+
98
+ it "parses an empty method with a block({}) [#{v}]" do
99
+ parse("foo() {}", v).find_node(:fcall).tap do |call|
100
+ call.should have_name_and_position("foo", 0, 0, 0, 8)
101
+ call.iter_node.should have_position(0, 0, 6, 8)
102
+ end
103
+ end
104
+
105
+ it "parses an empty method with a block(do...end) [#{v}]" do
106
+ parse("foo() do\nend\n", v).find_node(:fcall).tap do |call|
107
+ call.should have_name_and_position("foo", 0, 1, 0, 12)
108
+ call.iter_node.should have_position(0, 1, 6, 12)
109
+ end
110
+ end
111
+
112
+ it "parses an empty method with a block({}) +1 arg [#{v}]" do
113
+ parse("foo() { |a| }", v).find_node(:fcall).tap do |call|
114
+ call.should have_name_and_position("foo", 0, 0, 0, 13)
115
+ call.iter_node.should have_position(0, 0, 6, 13)
116
+ # FIXME: Need arg tests
117
+ end
118
+ end
119
+
120
+ it "parses an empty method with a block(do...end) [#{v}]" do
121
+ parse("foo() do |a|\nend\n", v).find_node(:fcall).tap do |call|
122
+ call.should have_name_and_position("foo", 0, 1, 0, 16)
123
+ call.iter_node.should have_position(0, 1, 6, 16)
124
+ # FIXME: Need arg tests
125
+ end
126
+ end
127
+
128
+ it "parses an nil receiver [#{v}]" do
129
+ parse("().foo", v).find_node(:call).receiver_node.should_not be_nil
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
3
+ require 'jruby-parser'
4
+ require 'parser_helpers'
5
+ require 'node_helpers'
6
+
7
+ describe Parser do
8
+ [1.8, 1.9].each do |v|
9
+ it "should parse an unless on alias [#{v}]" do
10
+ ast = parse("alias p ** unless method_defined? :p", v)
11
+ ast.find_node(:alias).tap { |a| a.should have_position(0, 0, 0, 10) }
12
+ ast.find_node(:if).tap { |i| i.should have_position(0, 0, 0, 36) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
3
+ require 'jruby-parser'
4
+ require 'parser_helpers'
5
+ require 'node_helpers'
6
+
7
+ describe Parser do
8
+ [1.8, 1.9].each do |v|
9
+ it "should parse a hash literal (a=>b) [#{v}]" do
10
+ parse("{:one => 1, :two => 2}", v).find_node(:hash).tap do |hash|
11
+ hash.should have_position(0, 0, 0, 22)
12
+ end
13
+ end
14
+ end
15
+
16
+ it "should parse a hash literal (a,b) [1.8]" do
17
+ parse("{:one, 1, :two, 2}", 1.8).find_node(:hash).tap do |hash|
18
+ hash.should have_position(0, 0, 0, 18)
19
+ end
20
+ end
21
+
22
+ it "should parse a hash literal (a: b) [1.9]" do
23
+ parse("{one: 1, two: 2}", 1.9).find_node(:hash).should have_position(0, 0, 0, 16)
24
+ end
25
+ end
@@ -0,0 +1,109 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
3
+ require 'jruby-parser'
4
+ require 'parser_helpers'
5
+ require 'node_helpers'
6
+
7
+ # Notes:
8
+ # 1. All heredocs include end newline right after end marker because that whitespace is part of
9
+ # the markers definition.
10
+
11
+ describe Parser do
12
+ [1.8, 1.9].each do |v|
13
+ it "parses a heredoc with marker at beginning of line[#{v}]" do
14
+ ast = parse(<<-EOF, v)
15
+ <<END
16
+ hello
17
+ END
18
+ EOF
19
+
20
+ ast.find_node(:str).should have_position(0, 2, 0, 15)
21
+ end
22
+
23
+ it "parses an empty heredoc with marker at beginning of line[#{v}]" do
24
+ ast = parse(<<-EOF, v)
25
+ <<END
26
+ END
27
+ EOF
28
+
29
+ ast.find_node(:str).should have_position(0, 1, 0, 9)
30
+ end
31
+
32
+ it "parses a heredoc with minus(-) and marker not at beginning of line[#{v}]" do
33
+ ast = parse(<<-EOF, v)
34
+ <<-END
35
+ hello
36
+ END
37
+ EOF
38
+
39
+ ast.find_node(:str).should have_position(0, 2, 0, 17)
40
+ end
41
+
42
+ it "parses an empty heredoc with minus(-) and marker not at beginning of line[#{v}]" do
43
+ ast = parse(<<-EOF, v)
44
+ <<-END
45
+ END
46
+ EOF
47
+
48
+ ast.find_node(:str).should have_position(0, 1, 0, 11)
49
+ end
50
+
51
+ it "parses a heredoc in quotes with marker at beginning of line[#{v}]" do
52
+ ast = parse(<<-EOF, v)
53
+ <<'END'
54
+ hello
55
+ END
56
+ EOF
57
+
58
+ ast.find_node(:str).should have_position(0, 2, 0, 17)
59
+ end
60
+
61
+ it "parses a heredoc in quotes with minus(-) and marker not at beginning of line[#{v}]" do
62
+ ast = parse(<<-EOF, v)
63
+ <<-'END'
64
+ hello
65
+ END
66
+ EOF
67
+
68
+ ast.find_node(:str).should have_position(0, 2, 0, 19)
69
+ end
70
+
71
+ it "parses a heredoc in double quotes with minus(-) and marker not at beginning of line[#{v}]" do
72
+ ast = parse(<<-EOF, v)
73
+ <<-"end;"
74
+ hello
75
+ end;
76
+ EOF
77
+
78
+ ast.find_node(:str).should have_position(0, 2, 0, 21)
79
+ end
80
+
81
+ it "parses an empty heredoc in double quotes with minus(-) and marker not at beginning of line[#{v}]" do
82
+ ast = parse(<<-EOF, v)
83
+ <<-"end;"
84
+ end;
85
+ EOF
86
+
87
+ ast.find_node(:str).should have_position(0, 1, 0, 15)
88
+ end
89
+
90
+ it "parses a heredoc in method call with other arguments[#{v}]" do
91
+ ast = parse(<<-EOF, v)
92
+ module_eval <<-"end;", "file", 123
93
+ hello world
94
+ end;
95
+ EOF
96
+
97
+ ast.find_node(:str).should have_position(0, 2, 12, 41)
98
+ end
99
+
100
+ it "parses an empty heredoc in method call with other arguments[#{v}]" do
101
+ ast = parse(<<-EOF, v)
102
+ module_eval <<-"end;", "file", 123
103
+ end;
104
+ EOF
105
+
106
+ ast.find_node(:str).should have_position(0, 1, 12, 27)
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../helpers"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../lib"
3
+ require 'jruby-parser'
4
+ require 'parser_helpers'
5
+ require 'node_helpers'
6
+
7
+ describe Parser do
8
+ [1.8, 1.9].each do |v|
9
+ it "should parse a string value [#{v}]" do
10
+ parse('str = "my str"', v).find_node(:str).value.should == "my str"
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jruby-parser
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ version: "0.3"
9
+ platform: ruby
10
+ authors:
11
+ - Thomas E. Enebo
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2012-04-18 00:00:00 -05:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: A Gem for syntactically correct parse trees of Ruby source
21
+ email: tom.enebo@gmail.com
22
+ executables:
23
+ - generate_parser
24
+ - optimize_parser.rb
25
+ - patch_parser.rb
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/jruby-parser.rb
32
+ - lib/jruby-parser/core_ext/array.rb
33
+ - lib/jruby-parser/core_ext/attr_assign_node.rb
34
+ - lib/jruby-parser/core_ext/boolean.rb
35
+ - lib/jruby-parser/core_ext/call_node.rb
36
+ - lib/jruby-parser/core_ext/fcall_node.rb
37
+ - lib/jruby-parser/core_ext/list_node.rb
38
+ - lib/jruby-parser/core_ext/nil.rb
39
+ - lib/jruby-parser/core_ext/node.rb
40
+ - lib/jruby-parser/core_ext/numeric.rb
41
+ - lib/jruby-parser/core_ext/op_element_asgn_node.rb
42
+ - lib/jruby-parser/core_ext/string.rb
43
+ - lib/jruby-parser/core_ext/super_node.rb
44
+ - lib/jruby-parser/util/coercer.rb
45
+ - lib/jruby-parser/version.rb
46
+ - lib/yydebug.jar
47
+ - sample/simple.rb
48
+ - spec/ast/node_path.rb
49
+ - spec/helpers/node_helpers.rb
50
+ - spec/helpers/parser_helpers.rb
51
+ - spec/jruby-parser/find_spec.rb
52
+ - spec/jruby-parser/rewriting_spec.rb
53
+ - spec/parser/alias_spec.rb
54
+ - spec/parser/broken_spec.rb
55
+ - spec/positions/arg_spec.rb
56
+ - spec/positions/call_spec.rb
57
+ - spec/positions/conditionals_spec.rb
58
+ - spec/positions/hash_spec.rb
59
+ - spec/positions/heredoc_spec.rb
60
+ - spec/positions/str_spec.rb
61
+ - lib/jruby-parser.jar
62
+ has_rdoc: true
63
+ homepage: http://github.com/jruby/jruby-parser
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project: jruby-parser
88
+ rubygems_version: 1.3.6
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A Gem for syntactically correct parse trees of Ruby source
92
+ test_files:
93
+ - spec/ast/node_path.rb
94
+ - spec/helpers/node_helpers.rb
95
+ - spec/helpers/parser_helpers.rb
96
+ - spec/jruby-parser/find_spec.rb
97
+ - spec/jruby-parser/rewriting_spec.rb
98
+ - spec/parser/alias_spec.rb
99
+ - spec/parser/broken_spec.rb
100
+ - spec/positions/arg_spec.rb
101
+ - spec/positions/call_spec.rb
102
+ - spec/positions/conditionals_spec.rb
103
+ - spec/positions/hash_spec.rb
104
+ - spec/positions/heredoc_spec.rb
105
+ - spec/positions/str_spec.rb