jruby-parser 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jruby-parser.jar +0 -0
  3. data/lib/jruby-parser/util/coercer.rb +22 -16
  4. data/lib/jruby-parser/version.rb +1 -1
  5. data/spec/ast/node/array_spec.rb +24 -0
  6. data/spec/ast/node/break_spec.rb +19 -0
  7. data/spec/ast/node/comments_spec.rb +59 -0
  8. data/spec/{jruby-parser → ast/node}/find_scopes_spec.rb +4 -7
  9. data/spec/ast/node/get_declaration_spec.rb +50 -0
  10. data/spec/ast/node/get_defined_scope_spec.rb +89 -0
  11. data/spec/{jruby-parser → ast/node}/get_node_at_spec.rb +3 -7
  12. data/spec/ast/node/get_occurences_spec.rb +87 -0
  13. data/spec/{jruby-parser → ast/node}/is_block_parameter_spec.rb +4 -8
  14. data/spec/{jruby-parser → ast/node}/is_method_parameter_spec.rb +4 -8
  15. data/spec/ast/node/next_spec.rb +19 -0
  16. data/spec/ast/node/op_element_asgn_and_spec.rb +11 -0
  17. data/spec/ast/node/op_element_asgn_or_spec.rb +11 -0
  18. data/spec/ast/node/op_element_asgn_spec.rb +11 -0
  19. data/spec/ast/node/return_spec.rb +19 -0
  20. data/spec/ast/node_path.rb +1 -5
  21. data/spec/helpers.rb +4 -0
  22. data/spec/helpers/node_helpers.rb +17 -6
  23. data/spec/helpers/parser_helpers.rb +84 -8
  24. data/spec/jruby-parser/find_spec.rb +2 -6
  25. data/spec/jruby-parser/parse_spec.rb +17 -0
  26. data/spec/jruby-parser/rewriting_spec.rb +27 -12
  27. data/spec/jruby-parser/static_analysis_spec.rb +51 -48
  28. data/spec/parser/alias_spec.rb +2 -6
  29. data/spec/parser/broken_spec.rb +2 -6
  30. data/spec/parser/calls_spec.rb +100 -0
  31. data/spec/positions/alias_spec.rb +23 -0
  32. data/spec/positions/arg_spec.rb +2 -6
  33. data/spec/positions/attr_asgn_spec.rb +2 -6
  34. data/spec/positions/call_spec.rb +2 -10
  35. data/spec/positions/conditionals_spec.rb +2 -6
  36. data/spec/positions/hash_spec.rb +2 -6
  37. data/spec/positions/heredoc_spec.rb +2 -6
  38. data/spec/positions/name_spec.rb +56 -0
  39. data/spec/positions/op_asgn_or_spec.rb +15 -0
  40. data/spec/positions/str_spec.rb +2 -6
  41. metadata +51 -21
@@ -1,11 +1,7 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  describe Parser do
8
- [1.8, 1.9].each do |v|
4
+ VERSIONS.each do |v|
9
5
  it "should parse alias with quotationmarks" do
10
6
  parse(%Q{alias :'<==>' :"foo"}, v).find_node(:alias).tap do |aliasn|
11
7
  aliasn.new_name.find_node(:symbol).name.should == "<==>"
@@ -1,15 +1,11 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  import org.jrubyparser.lexer.StringTerm
8
4
  import org.jrubyparser.lexer.SyntaxException
9
5
 
10
6
  # tests for broken files
11
7
  describe Parser do
12
- [1.8, 1.9].each do |v|
8
+ VERSIONS.each do |v|
13
9
  it "should raise an unterminated string exception" do
14
10
  lambda {
15
11
  parse('str = "', v)
@@ -0,0 +1,100 @@
1
+ require_relative '../helpers'
2
+
3
+ describe Parser do
4
+ VERSIONS.each do |v|
5
+ # Parsing normal forms of Ruby method calls.
6
+
7
+ it "should parse a call" do
8
+ parse("def foo; end; self.foo", v).find_node(:call).tap do |call|
9
+ call.name.should == "foo"
10
+ end
11
+
12
+ parse("def foo; end; self.foo()", v).find_node(:call).tap do |call|
13
+ call.name.should == "foo"
14
+ end
15
+ end
16
+
17
+ it "should parse a vcall" do
18
+ parse("def foo; end; foo", v).find_node(:vcall).tap do |vcall|
19
+ vcall.name.should == "foo"
20
+ end
21
+ end
22
+
23
+ it "should parse a fcall" do
24
+ parse("def foo; end; foo()", v).find_node(:fcall).tap do |fcall|
25
+ fcall.name.should == "foo"
26
+ end
27
+ end
28
+
29
+ # Parsing - and + as operator calls, which are unique in that they have
30
+ # both binary and unary forms.
31
+
32
+ it "should parse unary plus and minus expressed as an operator" do
33
+ ["+", "-"].each do |op|
34
+ parse("#{op}x", v).find_node(:unarycall).tap do |unarycall|
35
+ unarycall.name.should == "#{op}@"
36
+ unarycall.lexical_name.should == op
37
+ end
38
+ end
39
+ end
40
+
41
+ # Parsing the unary form of - and + as an explicit call.
42
+
43
+ it "should parse unary plus and minus expressed as an call without parens" do
44
+ ["+", "-"].each do |op|
45
+ parse("x.#{op}@", v).find_node(:call).tap do |call|
46
+ call.name.should == "#{op}@"
47
+ end
48
+ end
49
+ end
50
+
51
+ it "should parse unary plus and minus expressed as an call with parens" do
52
+ ["+", "-"].each do |op|
53
+ parse("x.#{op}@()", v).find_node(:call).tap do |call|
54
+ call.name.should == "#{op}@"
55
+ end
56
+ end
57
+ end
58
+
59
+ # Unlike - and +, other unary operators such as ~ are not decorated.
60
+
61
+ it "should not decorate ~" do
62
+ parse("~x", v).find_node(:call).tap do |call|
63
+ call.name.should == "~"
64
+ end
65
+ end
66
+
67
+ if v == 1.8
68
+ # 'not' and '!' in 1.8 were both simply a not node
69
+
70
+ it "should parse 'not' as a node" do
71
+ parse("not x", 1.8).find_node(:not).tap do |notn|
72
+ notn.should_not == nil
73
+ end
74
+ end
75
+
76
+ it "should parse '!' as a node" do
77
+ parse("! x", 1.8).find_node(:not).tap do |notn|
78
+ notn.should_not == nil
79
+ end
80
+ end
81
+ else
82
+ # In 1.9 and 2.0 'not' was a call to '!', but we annotate the name of the
83
+ # method as lexically being 'not'. '!' is still just a call.
84
+
85
+ it "should parse 'not' as a call to '!' with lexical name 'not'" do
86
+ parse("not x", v).find_node(:call).tap do |call|
87
+ call.name.should == "!"
88
+ call.lexical_name.should == "not"
89
+ end
90
+ end
91
+
92
+ it "should parse '!' as a call" do
93
+ parse("! x", v).find_node(:call).tap do |call|
94
+ call.name.should == "!"
95
+ call.lexical_name.should == "!"
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../helpers'
2
+
3
+ describe Parser do
4
+ VERSIONS.each do |v|
5
+ it "Should parse alias node of symbols" do
6
+ parse("alias :new_name :old_name", v).find_node(:alias).tap do |a|
7
+ a.new_name_string.should == "new_name"
8
+ a.old_name_string.should == "old_name"
9
+ a.new_name.should have_position(0, 0, 6, 15)
10
+ a.old_name.should have_position(0, 0, 16, 25)
11
+ end
12
+ end
13
+
14
+ it "Should parse alias node of CONSTANTS" do
15
+ parse("alias NEW OLD", v).find_node(:alias).tap do |a|
16
+ a.new_name_string.should == "NEW"
17
+ a.old_name_string.should == "OLD"
18
+ a.new_name.should have_position(0, 0, 6, 9)
19
+ a.old_name.should have_position(0, 0, 10, 13)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,11 +1,7 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  describe Parser do
8
- [1.8, 1.9].each do |v|
4
+ VERSIONS.each do |v|
9
5
  it "parses a 0-arg method sans parens [#{v}]" do
10
6
  parse("def foo\nend\n", v).find_node(:defn).tap do |defn|
11
7
  defn.should have_name_and_position("foo", 0, 1, 0, 11)
@@ -1,11 +1,7 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  describe Parser do
8
- [1.8, 1.9].each do |v|
4
+ VERSIONS.each do |v|
9
5
  it "Should parse attr assign" do
10
6
  parse("a[1] = 2", v).find_node(:attrassign).tap do |asgn|
11
7
  asgn.should_not == nil
@@ -1,11 +1,7 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  describe Parser do
8
- [1.8, 1.9].each do |v|
4
+ VERSIONS.each do |v|
9
5
  it "parses a 0-arg method call sans parens +extra line [#{v}]" do
10
6
  parse("\nblock_given?\n", v).find_node(:fcall).tap do |call|
11
7
  call.should have_name_and_position("block_given?", 1, 1, 1, 13)
@@ -130,9 +126,5 @@ describe Parser do
130
126
  # FIXME: Need arg tests
131
127
  end
132
128
  end
133
-
134
- it "parses an nil receiver [#{v}]" do
135
- parse("().foo", v).find_node(:call).receiver_node.should_not be_nil
136
- end
137
129
  end
138
130
  end
@@ -1,11 +1,7 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  describe Parser do
8
- [1.8, 1.9].each do |v|
4
+ VERSIONS.each do |v|
9
5
  it "should parse an unless on alias [#{v}]" do
10
6
  ast = parse("alias p ** unless method_defined? :p", v)
11
7
  ast.find_node(:alias).tap { |a| a.should have_position(0, 0, 0, 10) }
@@ -1,11 +1,7 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  describe Parser do
8
- [1.8, 1.9].each do |v|
4
+ VERSIONS.each do |v|
9
5
  it "should parse a hash literal (a=>b) [#{v}]" do
10
6
  parse("{:one => 1, :two => 2}", v).find_node(:hash).tap do |hash|
11
7
  hash.should have_position(0, 0, 0, 22)
@@ -1,15 +1,11 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  # Notes:
8
4
  # 1. All heredocs include end newline right after end marker because that whitespace is part of
9
5
  # the markers definition.
10
6
 
11
7
  describe Parser do
12
- [1.8, 1.9].each do |v|
8
+ VERSIONS.each do |v|
13
9
  it "parses a heredoc with marker at beginning of line[#{v}]" do
14
10
  ast = parse(<<-EOF, v)
15
11
  <<END
@@ -0,0 +1,56 @@
1
+ require_relative '../helpers'
2
+
3
+ describe Parser do
4
+ VERSIONS.each do |v|
5
+ it "should get name position for lvars [#{v}]" do
6
+ carets_parse("^foo = 1; ^foo", v).tap do |_, (asgn, var)|
7
+ asgn.should have_name_position(0, 0, 0, 3)
8
+ var.should have_name_position(0, 0, 9, 12)
9
+ end
10
+ end
11
+ it "should get name position for ivars [#{v}]" do
12
+ carets_parse("^@foo = 1; ^@foo", v).tap do |_, (asgn, var)|
13
+ asgn.should have_name_position(0, 0, 1, 4)
14
+ var.should have_name_position(0, 0, 11, 14)
15
+ end
16
+ end
17
+ it "should get name position for cvars [#{v}]" do
18
+ carets_parse("^@@foo = 1; ^@@foo", v).tap do |_, (asgn, var)|
19
+ asgn.should have_name_position(0, 0, 2, 5)
20
+ var.should have_name_position(0, 0, 13, 16)
21
+ end
22
+ end
23
+ it "should get name position for gvars [#{v}]" do
24
+ carets_parse("^$foo = 1; ^$foo", v).tap do |_, (asgn, var)|
25
+ asgn.should have_name_position(0, 0, 1, 4)
26
+ var.should have_name_position(0, 0, 11, 14)
27
+ end
28
+ end
29
+ it "should get name position for constants [#{v}]" do
30
+ carets_parse("^FOO = 1; ^FOO", v).tap do |_, (asgn, var)|
31
+ asgn.should have_name_position(0, 0, 0, 3)
32
+ var.should have_name_position(0, 0, 9, 12)
33
+ end
34
+ end
35
+ it "should get name position for method parameters [#{v}]" do
36
+ carets_parse("def foo(^a, ^b=1, *^c, &^d);end", v).tap do |_, (a, b, c, d)|
37
+ a.should have_name_position(0, 0, 8, 9)
38
+ b.should have_name_position(0, 0, 11, 12)
39
+ c.should have_name_position(0, 0, 17, 18)
40
+ d.should have_name_position(0, 0, 21, 22)
41
+ end
42
+ if v != 1.8
43
+ carets_parse("def foo(^a, ^b=1, ^c);end", v).tap do |_, (a, b, c)|
44
+ c.should have_name_position(0, 0, 16,17)
45
+ end
46
+ end
47
+ end
48
+ it "should get name position for block parameters [#{v}]" do
49
+ carets_parse("proc {|^a, *^b, &^c|}", v).tap do |_, (a, b, c)|
50
+ a.should have_name_position(0, 0, 7, 8)
51
+ b.should have_name_position(0, 0, 11, 12)
52
+ c.should have_name_position(0, 0, 15, 16)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../helpers'
2
+
3
+ describe Parser do
4
+ VERSIONS.each do |v|
5
+ it "Should parse attr assign" do
6
+ parse("foo ||= bar", v).find_node(:opasgnor).tap do |opasgn|
7
+ opasgn.should have_position(0, 0, 0, 11)
8
+ reference, assignment = opasgn.first, opasgn.second
9
+ reference.should have_name_and_position("foo", 0, 0, 0, 3)
10
+ # assignment.should have_name_and_position("foo", 0, 0, 0, 11)
11
+ assignment.value.should have_name_and_position("bar", 0, 0, 8, 11)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,11 +1,7 @@
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'
1
+ require_relative '../helpers'
6
2
 
7
3
  describe Parser do
8
- [1.8, 1.9].each do |v|
4
+ VERSIONS.each do |v|
9
5
  it "should parse a string value [#{v}]" do
10
6
  parse('str = "my str"', v).find_node(:str).value.should == "my str"
11
7
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-parser
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.4.2
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Thomas E. Enebo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-29 00:00:00.000000000 Z
11
+ date: 2013-08-17 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A Gem for syntactically correct parse trees of Ruby source
15
14
  email: tom.enebo@gmail.com
@@ -34,69 +33,100 @@ files:
34
33
  - lib/jruby-parser/version.rb
35
34
  - lib/yydebug.jar
36
35
  - sample/simple.rb
36
+ - spec/ast/node/array_spec.rb
37
+ - spec/ast/node/break_spec.rb
38
+ - spec/ast/node/comments_spec.rb
39
+ - spec/ast/node/find_scopes_spec.rb
40
+ - spec/ast/node/get_declaration_spec.rb
41
+ - spec/ast/node/get_defined_scope_spec.rb
42
+ - spec/ast/node/get_node_at_spec.rb
43
+ - spec/ast/node/get_occurences_spec.rb
44
+ - spec/ast/node/is_block_parameter_spec.rb
45
+ - spec/ast/node/is_method_parameter_spec.rb
46
+ - spec/ast/node/next_spec.rb
47
+ - spec/ast/node/op_element_asgn_and_spec.rb
48
+ - spec/ast/node/op_element_asgn_or_spec.rb
49
+ - spec/ast/node/op_element_asgn_spec.rb
50
+ - spec/ast/node/return_spec.rb
37
51
  - spec/ast/node_path.rb
52
+ - spec/helpers.rb
38
53
  - spec/helpers/node_helpers.rb
39
54
  - spec/helpers/parser_helpers.rb
40
- - spec/jruby-parser/find_scopes_spec.rb
41
55
  - spec/jruby-parser/find_spec.rb
42
- - spec/jruby-parser/get_node_at_spec.rb
43
- - spec/jruby-parser/is_block_parameter_spec.rb
44
- - spec/jruby-parser/is_method_parameter_spec.rb
56
+ - spec/jruby-parser/parse_spec.rb
45
57
  - spec/jruby-parser/rewriting_spec.rb
46
58
  - spec/jruby-parser/static_analysis_spec.rb
47
59
  - spec/parser/alias_spec.rb
48
60
  - spec/parser/broken_spec.rb
61
+ - spec/parser/calls_spec.rb
62
+ - spec/positions/alias_spec.rb
49
63
  - spec/positions/arg_spec.rb
50
64
  - spec/positions/attr_asgn_spec.rb
51
65
  - spec/positions/call_spec.rb
52
66
  - spec/positions/conditionals_spec.rb
53
67
  - spec/positions/hash_spec.rb
54
68
  - spec/positions/heredoc_spec.rb
69
+ - spec/positions/name_spec.rb
70
+ - spec/positions/op_asgn_or_spec.rb
55
71
  - spec/positions/str_spec.rb
56
72
  - lib/jruby-parser.jar
57
73
  homepage: http://github.com/jruby/jruby-parser
58
74
  licenses: []
75
+ metadata: {}
59
76
  post_install_message:
60
77
  rdoc_options: []
61
78
  require_paths:
62
79
  - lib
63
80
  required_ruby_version: !ruby/object:Gem::Requirement
64
81
  requirements:
65
- - - ">="
82
+ - - '>='
66
83
  - !ruby/object:Gem::Version
67
- version: !binary |-
68
- MA==
69
- none: false
84
+ version: '0'
70
85
  required_rubygems_version: !ruby/object:Gem::Requirement
71
86
  requirements:
72
- - - ">="
87
+ - - '>='
73
88
  - !ruby/object:Gem::Version
74
- version: !binary |-
75
- MA==
76
- none: false
89
+ version: '0'
77
90
  requirements: []
78
91
  rubyforge_project: jruby-parser
79
- rubygems_version: 1.8.24
92
+ rubygems_version: 2.0.3
80
93
  signing_key:
81
- specification_version: 3
94
+ specification_version: 4
82
95
  summary: A Gem for syntactically correct parse trees of Ruby source
83
96
  test_files:
97
+ - spec/ast/node/array_spec.rb
98
+ - spec/ast/node/break_spec.rb
99
+ - spec/ast/node/comments_spec.rb
100
+ - spec/ast/node/find_scopes_spec.rb
101
+ - spec/ast/node/get_declaration_spec.rb
102
+ - spec/ast/node/get_defined_scope_spec.rb
103
+ - spec/ast/node/get_node_at_spec.rb
104
+ - spec/ast/node/get_occurences_spec.rb
105
+ - spec/ast/node/is_block_parameter_spec.rb
106
+ - spec/ast/node/is_method_parameter_spec.rb
107
+ - spec/ast/node/next_spec.rb
108
+ - spec/ast/node/op_element_asgn_and_spec.rb
109
+ - spec/ast/node/op_element_asgn_or_spec.rb
110
+ - spec/ast/node/op_element_asgn_spec.rb
111
+ - spec/ast/node/return_spec.rb
84
112
  - spec/ast/node_path.rb
113
+ - spec/helpers.rb
85
114
  - spec/helpers/node_helpers.rb
86
115
  - spec/helpers/parser_helpers.rb
87
- - spec/jruby-parser/find_scopes_spec.rb
88
116
  - spec/jruby-parser/find_spec.rb
89
- - spec/jruby-parser/get_node_at_spec.rb
90
- - spec/jruby-parser/is_block_parameter_spec.rb
91
- - spec/jruby-parser/is_method_parameter_spec.rb
117
+ - spec/jruby-parser/parse_spec.rb
92
118
  - spec/jruby-parser/rewriting_spec.rb
93
119
  - spec/jruby-parser/static_analysis_spec.rb
94
120
  - spec/parser/alias_spec.rb
95
121
  - spec/parser/broken_spec.rb
122
+ - spec/parser/calls_spec.rb
123
+ - spec/positions/alias_spec.rb
96
124
  - spec/positions/arg_spec.rb
97
125
  - spec/positions/attr_asgn_spec.rb
98
126
  - spec/positions/call_spec.rb
99
127
  - spec/positions/conditionals_spec.rb
100
128
  - spec/positions/hash_spec.rb
101
129
  - spec/positions/heredoc_spec.rb
130
+ - spec/positions/name_spec.rb
131
+ - spec/positions/op_asgn_or_spec.rb
102
132
  - spec/positions/str_spec.rb