parser 1.4.2 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/CHANGELOG.md +167 -0
- data/CONTRIBUTING.md +10 -0
- data/Gemfile +4 -0
- data/README.md +56 -6
- data/Rakefile +66 -3
- data/doc/AST_FORMAT.md +3 -16
- data/lib/parser.rb +3 -0
- data/lib/parser/ast/node.rb +4 -4
- data/lib/parser/ast/processor.rb +1 -2
- data/lib/parser/base.rb +30 -2
- data/lib/parser/builders/default.rb +90 -70
- data/lib/parser/lexer.rl +98 -73
- data/lib/parser/lexer/explanation.rb +2 -11
- data/lib/parser/rewriter.rb +1 -2
- data/lib/parser/ruby18.y +2 -11
- data/lib/parser/ruby19.y +3 -14
- data/lib/parser/ruby20.y +3 -14
- data/lib/parser/ruby21.y +3 -14
- data/lib/parser/runner/ruby_parse.rb +1 -1
- data/lib/parser/source/buffer.rb +8 -18
- data/lib/parser/source/comment.rb +46 -0
- data/lib/parser/source/comment/associator.rb +70 -0
- data/lib/parser/source/map.rb +4 -0
- data/lib/parser/source/range.rb +2 -2
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +4 -3
- data/test/parse_helper.rb +6 -6
- data/test/test_lexer.rb +263 -15
- data/test/test_parser.rb +86 -48
- data/test/test_source_comment.rb +34 -0
- data/test/test_source_comment_associator.rb +48 -0
- data/test/test_source_range.rb +22 -16
- metadata +13 -5
- data/.jrubyrc +0 -1
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSourceComment < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@buf = Parser::Source::Buffer.new('(string)')
|
6
|
+
@buf.source = "# foo\n=begin foo\nbar\n=end baz\n"
|
7
|
+
end
|
8
|
+
|
9
|
+
def range(s, e)
|
10
|
+
Parser::Source::Range.new(@buf, s, e)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize
|
14
|
+
comment = Parser::Source::Comment.new(range(0, 5))
|
15
|
+
assert comment.frozen?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_text
|
19
|
+
comment = Parser::Source::Comment.new(range(0, 5))
|
20
|
+
assert_equal '# foo', comment.text
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_inline
|
24
|
+
comment = Parser::Source::Comment.new(range(0, 5))
|
25
|
+
assert_equal :inline, comment.type
|
26
|
+
assert comment.inline?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_document
|
30
|
+
comment = Parser::Source::Comment.new(range(6, 25))
|
31
|
+
assert_equal :document, comment.type
|
32
|
+
assert comment.document?
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'parser/ruby18'
|
3
|
+
|
4
|
+
class TestSourceCommentAssociator < MiniTest::Unit::TestCase
|
5
|
+
def test_associate
|
6
|
+
parser = Parser::Ruby18.new
|
7
|
+
|
8
|
+
buffer = Parser::Source::Buffer.new('(comments)')
|
9
|
+
buffer.source = <<-END
|
10
|
+
# Class comment
|
11
|
+
# another class comment
|
12
|
+
class Foo
|
13
|
+
# attr_accessor comment
|
14
|
+
attr_accessor :foo
|
15
|
+
|
16
|
+
# method comment
|
17
|
+
def bar
|
18
|
+
# expr comment
|
19
|
+
1 + # intermediate comment
|
20
|
+
2
|
21
|
+
# stray comment
|
22
|
+
end
|
23
|
+
end
|
24
|
+
END
|
25
|
+
|
26
|
+
ast, comments = parser.parse_with_comments(buffer)
|
27
|
+
associations = Parser::Source::Comment.associate(ast, comments)
|
28
|
+
|
29
|
+
klass_node = ast
|
30
|
+
attr_accessor_node = ast.children[2].children[0]
|
31
|
+
method_node = ast.children[2].children[1]
|
32
|
+
expr_node = method_node.children[2]
|
33
|
+
intermediate_node = expr_node.children[2]
|
34
|
+
|
35
|
+
assert_equal 5, associations.size
|
36
|
+
assert_equal ['# Class comment', '# another class comment'],
|
37
|
+
associations[klass_node].map(&:text)
|
38
|
+
assert_equal ['# attr_accessor comment'],
|
39
|
+
associations[attr_accessor_node].map(&:text)
|
40
|
+
assert_equal ['# method comment'],
|
41
|
+
associations[method_node].map(&:text)
|
42
|
+
assert_equal ['# expr comment'],
|
43
|
+
associations[expr_node].map(&:text)
|
44
|
+
assert_equal ['# intermediate comment'],
|
45
|
+
associations[intermediate_node].map(&:text)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/test/test_source_range.rb
CHANGED
@@ -2,25 +2,25 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestSourceRange < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@
|
6
|
-
@
|
5
|
+
@buf = Parser::Source::Buffer.new('(string)')
|
6
|
+
@buf.source = "foobar\nbaz"
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_initialize
|
10
|
-
sr = Parser::Source::Range.new(@
|
10
|
+
sr = Parser::Source::Range.new(@buf, 1, 2)
|
11
11
|
assert_equal 1, sr.begin_pos
|
12
12
|
assert_equal 2, sr.end_pos
|
13
13
|
assert sr.frozen?
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_size
|
17
|
-
sr = Parser::Source::Range.new(@
|
17
|
+
sr = Parser::Source::Range.new(@buf, 1, 3)
|
18
18
|
assert_equal 2, sr.size
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_join
|
22
|
-
sr1 = Parser::Source::Range.new(@
|
23
|
-
sr2 = Parser::Source::Range.new(@
|
22
|
+
sr1 = Parser::Source::Range.new(@buf, 1, 2)
|
23
|
+
sr2 = Parser::Source::Range.new(@buf, 5, 8)
|
24
24
|
sr = sr1.join(sr2)
|
25
25
|
|
26
26
|
assert_equal 1, sr.begin_pos
|
@@ -28,24 +28,24 @@ class TestSourceRange < MiniTest::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_line
|
31
|
-
sr = Parser::Source::Range.new(@
|
31
|
+
sr = Parser::Source::Range.new(@buf, 7, 8)
|
32
32
|
assert_equal 2, sr.line
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_source_line
|
36
|
-
sr = Parser::Source::Range.new(@
|
36
|
+
sr = Parser::Source::Range.new(@buf, 7, 8)
|
37
37
|
assert_equal "baz", sr.source_line
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_columns
|
41
|
-
sr = Parser::Source::Range.new(@
|
41
|
+
sr = Parser::Source::Range.new(@buf, 7, 8)
|
42
42
|
assert_equal 0, sr.begin.column
|
43
43
|
assert_equal 1, sr.end.column
|
44
44
|
assert_equal 0...1, sr.column_range
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_begin_end
|
48
|
-
sr = Parser::Source::Range.new(@
|
48
|
+
sr = Parser::Source::Range.new(@buf, 1, 5)
|
49
49
|
|
50
50
|
sr_beg = sr.begin
|
51
51
|
assert_equal 1, sr_beg.begin_pos
|
@@ -56,16 +56,22 @@ class TestSourceRange < MiniTest::Unit::TestCase
|
|
56
56
|
assert_equal 5, sr_end.end_pos
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
60
|
-
sr = Parser::Source::Range.new(@
|
61
|
-
assert_equal "foo", sr.
|
59
|
+
def test_source
|
60
|
+
sr = Parser::Source::Range.new(@buf, 0, 3)
|
61
|
+
assert_equal "foo", sr.source
|
62
62
|
|
63
|
-
sr_multi = Parser::Source::Range.new(@
|
64
|
-
assert_equal "foobar\nbaz", sr_multi.
|
63
|
+
sr_multi = Parser::Source::Range.new(@buf, 0, 10)
|
64
|
+
assert_equal "foobar\nbaz", sr_multi.source
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_is?
|
68
|
+
sr = Parser::Source::Range.new(@buf, 0, 3)
|
69
|
+
assert sr.is?('foo')
|
70
|
+
refute sr.is?('bar')
|
65
71
|
end
|
66
72
|
|
67
73
|
def test_to_s
|
68
|
-
sr = Parser::Source::Range.new(@
|
74
|
+
sr = Parser::Source::Range.new(@buf, 8, 9)
|
69
75
|
assert_equal "(string):2:2", sr.to_s
|
70
76
|
end
|
71
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Zotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -188,9 +188,11 @@ extensions: []
|
|
188
188
|
extra_rdoc_files: []
|
189
189
|
files:
|
190
190
|
- .gitignore
|
191
|
-
- .
|
191
|
+
- .rubocop.yml
|
192
192
|
- .travis.yml
|
193
193
|
- .yardopts
|
194
|
+
- CHANGELOG.md
|
195
|
+
- CONTRIBUTING.md
|
194
196
|
- Gemfile
|
195
197
|
- LICENSE.txt
|
196
198
|
- README.md
|
@@ -226,6 +228,8 @@ files:
|
|
226
228
|
- lib/parser/runner/ruby_parse.rb
|
227
229
|
- lib/parser/runner/ruby_rewrite.rb
|
228
230
|
- lib/parser/source/buffer.rb
|
231
|
+
- lib/parser/source/comment.rb
|
232
|
+
- lib/parser/source/comment/associator.rb
|
229
233
|
- lib/parser/source/map.rb
|
230
234
|
- lib/parser/source/map/block.rb
|
231
235
|
- lib/parser/source/map/collection.rb
|
@@ -258,6 +262,8 @@ files:
|
|
258
262
|
- test/test_parse_helper.rb
|
259
263
|
- test/test_parser.rb
|
260
264
|
- test/test_source_buffer.rb
|
265
|
+
- test/test_source_comment.rb
|
266
|
+
- test/test_source_comment_associator.rb
|
261
267
|
- test/test_source_range.rb
|
262
268
|
- test/test_source_rewriter.rb
|
263
269
|
- test/test_source_rewriter_action.rb
|
@@ -282,9 +288,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
282
288
|
version: '0'
|
283
289
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
284
290
|
requirements:
|
285
|
-
- - '
|
291
|
+
- - '>'
|
286
292
|
- !ruby/object:Gem::Version
|
287
|
-
version:
|
293
|
+
version: 1.3.1
|
288
294
|
requirements: []
|
289
295
|
rubyforge_project:
|
290
296
|
rubygems_version: 2.0.0
|
@@ -304,6 +310,8 @@ test_files:
|
|
304
310
|
- test/test_parse_helper.rb
|
305
311
|
- test/test_parser.rb
|
306
312
|
- test/test_source_buffer.rb
|
313
|
+
- test/test_source_comment.rb
|
314
|
+
- test/test_source_comment_associator.rb
|
307
315
|
- test/test_source_range.rb
|
308
316
|
- test/test_source_rewriter.rb
|
309
317
|
- test/test_source_rewriter_action.rb
|
data/.jrubyrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
-Xcext.enabled=true
|