parser 2.2.0.1 → 2.2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -10
- data/lib/parser/runner.rb +28 -24
- data/lib/parser/runner/ruby_parse.rb +14 -6
- data/lib/parser/runner/ruby_rewrite.rb +4 -4
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +1 -2
- data/test/test_current.rb +3 -1
- metadata +4 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ee3b62efb93509bd26984f67ccef404ed4436a
|
4
|
+
data.tar.gz: 3997b9e8dfa9ad2acd372d363e4e30094889bda1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faf5d3ced213d86629ab6bc357a97d32e9fda555e8077743abfe9c340d85608362dd2ff2ca61e6ebf6a990d7d64d5130c5f89dd7feb33b9cf1ac85979d76728d
|
7
|
+
data.tar.gz: d36bbe80d4b3d150a408db67765f154eaee25fd44b49b969e2d54a4d0b4bd7b702f8116836f21f6923952ace7539c8ed504e985bfc5dae9c725567882b983b43
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Parser
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/parser.png)](
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/parser.png)](https://badge.fury.io/rb/parser)
|
4
4
|
[![Build Status](https://travis-ci.org/whitequark/parser.png?branch=master)](https://travis-ci.org/whitequark/parser)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/whitequark/parser.png)](https://codeclimate.com/github/whitequark/parser)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/whitequark/parser/badge.png?branch=master)](https://coveralls.io/r/whitequark/parser)
|
@@ -41,7 +41,7 @@ Access the AST's source map:
|
|
41
41
|
p Parser::CurrentRuby.parse("2 + 2").loc.selector.source
|
42
42
|
# "+"
|
43
43
|
|
44
|
-
Traverse the AST: see the documentation for [gem ast](
|
44
|
+
Traverse the AST: see the documentation for [gem ast](https://whitequark.github.io/ast/).
|
45
45
|
|
46
46
|
Parse a chunk of code and display all diagnostics:
|
47
47
|
|
@@ -98,27 +98,26 @@ with Parser:
|
|
98
98
|
* Precise source location reporting.
|
99
99
|
* [Documented](doc/AST_FORMAT.md) AST format which is convenient to work with.
|
100
100
|
* A simple interface and a powerful, tweakable one.
|
101
|
-
* Parses 1.8, 1.9, 2.0, 2.1 and 2.2
|
101
|
+
* Parses 1.8, 1.9, 2.0, 2.1 and 2.2 syntax with backwards-compatible
|
102
102
|
AST formats.
|
103
103
|
* [Rewriting][rewriting] support.
|
104
104
|
* Parsing error recovery.
|
105
105
|
* Improved [clang-like][] diagnostic messages with location information.
|
106
106
|
* Written in pure Ruby, runs on MRI 1.8.7 or >=1.9.2, JRuby and Rubinius in 1.8
|
107
107
|
and 1.9 mode.
|
108
|
-
* Only
|
108
|
+
* Only one runtime dependency: the [ast][] gem.
|
109
109
|
* [Insane][insane-lexer] Ruby lexer rewritten from scratch in Ragel.
|
110
110
|
* 100% test coverage for Bison grammars (except error recovery).
|
111
111
|
* Readable, commented source code.
|
112
112
|
|
113
113
|
[clang-like]: http://clang.llvm.org/diagnostics.html
|
114
|
-
[ast]:
|
115
|
-
[slop]: http://rubygems.org/gems/slop
|
114
|
+
[ast]: https://rubygems.org/gems/ast
|
116
115
|
[insane-lexer]: http://whitequark.org/blog/2013/04/01/ruby-hacking-guide-ch-11-finite-state-lexer/
|
117
116
|
[rewriting]: http://whitequark.org/blog/2013/04/26/lets-play-with-ruby-code/
|
118
117
|
|
119
118
|
## Documentation
|
120
119
|
|
121
|
-
Documentation for parser is available [online](
|
120
|
+
Documentation for parser is available [online](https://whitequark.github.io/parser/).
|
122
121
|
|
123
122
|
### Node names
|
124
123
|
|
@@ -210,7 +209,7 @@ Adding support for the following Ruby MRI features in Parser would needlessly co
|
|
210
209
|
|
211
210
|
Parser has been extensively tested; in particular, it parses almost entire [Rubygems][rg] corpus. For every issue, a breakdown of affected gems is offered.
|
212
211
|
|
213
|
-
[rg]:
|
212
|
+
[rg]: https://rubygems.org
|
214
213
|
|
215
214
|
### Void value expressions
|
216
215
|
|
@@ -264,9 +263,9 @@ No known code is affected by this issue.
|
|
264
263
|
## Acknowledgements
|
265
264
|
|
266
265
|
The lexer testsuite is derived from
|
267
|
-
[ruby\_parser](
|
266
|
+
[ruby\_parser](https://github.com/seattlerb/ruby_parser).
|
268
267
|
|
269
|
-
The Bison parser rules are derived from [Ruby MRI](
|
268
|
+
The Bison parser rules are derived from [Ruby MRI](https://github.com/ruby/ruby)
|
270
269
|
parse.y.
|
271
270
|
|
272
271
|
## Contributing
|
data/lib/parser/runner.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'benchmark'
|
2
2
|
require 'find'
|
3
|
-
require '
|
3
|
+
require 'optparse'
|
4
4
|
|
5
5
|
require 'parser'
|
6
6
|
|
@@ -12,16 +12,16 @@ module Parser
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize
|
15
|
-
@
|
16
|
-
@parser_class
|
17
|
-
@parser
|
18
|
-
@files
|
19
|
-
@fragments
|
15
|
+
@option_parser = OptionParser.new { |opts| setup_option_parsing(opts) }
|
16
|
+
@parser_class = nil
|
17
|
+
@parser = nil
|
18
|
+
@files = []
|
19
|
+
@fragments = []
|
20
|
+
@warnings = false
|
21
|
+
@benchmark = false
|
20
22
|
|
21
23
|
@source_count = 0
|
22
24
|
@source_size = 0
|
23
|
-
|
24
|
-
setup_option_parsing
|
25
25
|
end
|
26
26
|
|
27
27
|
def execute(options)
|
@@ -37,11 +37,11 @@ module Parser
|
|
37
37
|
raise NotImplementedError, "implement #{self.class}##{__callee__}"
|
38
38
|
end
|
39
39
|
|
40
|
-
def setup_option_parsing
|
41
|
-
|
40
|
+
def setup_option_parsing(opts)
|
41
|
+
opts.banner = "Usage: #{runner_name} [options] FILE|DIRECTORY..."
|
42
42
|
|
43
|
-
|
44
|
-
puts
|
43
|
+
opts.on_tail '-h', '--help', 'Display this help message and exit' do
|
44
|
+
puts opts.help
|
45
45
|
puts <<-HELP
|
46
46
|
|
47
47
|
If you specify a DIRECTORY, then all *.rb files are fetched
|
@@ -52,47 +52,51 @@ module Parser
|
|
52
52
|
exit
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
opts.on_tail '-V', '--version', 'Output version information and exit' do
|
56
56
|
puts "#{runner_name} based on parser version #{Parser::VERSION}"
|
57
57
|
exit
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
opts.on '--18', 'Parse as Ruby 1.8.7 would' do
|
61
61
|
require 'parser/ruby18'
|
62
62
|
@parser_class = Parser::Ruby18
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
opts.on '--19', 'Parse as Ruby 1.9.3 would' do
|
66
66
|
require 'parser/ruby19'
|
67
67
|
@parser_class = Parser::Ruby19
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
opts.on '--20', 'Parse as Ruby 2.0 would' do
|
71
71
|
require 'parser/ruby20'
|
72
72
|
@parser_class = Parser::Ruby20
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
opts.on '--21', 'Parse as Ruby 2.1 would' do
|
76
76
|
require 'parser/ruby21'
|
77
77
|
@parser_class = Parser::Ruby21
|
78
78
|
end
|
79
79
|
|
80
|
-
|
80
|
+
opts.on '--22', 'Parse as Ruby 2.2 would' do
|
81
81
|
require 'parser/ruby22'
|
82
82
|
@parser_class = Parser::Ruby22
|
83
83
|
end
|
84
84
|
|
85
|
-
|
85
|
+
opts.on '-w', '--warnings', 'Enable warnings' do |w|
|
86
|
+
@warnings = w
|
87
|
+
end
|
86
88
|
|
87
|
-
|
89
|
+
opts.on '-B', '--benchmark', 'Benchmark the processor' do |b|
|
90
|
+
@benchmark = b
|
91
|
+
end
|
88
92
|
|
89
|
-
|
93
|
+
opts.on '-e fragment', 'Process a fragment of Ruby code' do |fragment|
|
90
94
|
@fragments << fragment
|
91
95
|
end
|
92
96
|
end
|
93
97
|
|
94
98
|
def parse_options(options)
|
95
|
-
@
|
99
|
+
@option_parser.parse!(options)
|
96
100
|
|
97
101
|
# Slop has just removed recognized options from `options`.
|
98
102
|
options.each do |file_or_dir|
|
@@ -120,7 +124,7 @@ module Parser
|
|
120
124
|
@parser = @parser_class.new
|
121
125
|
|
122
126
|
@parser.diagnostics.all_errors_are_fatal = true
|
123
|
-
@parser.diagnostics.ignore_warnings = !@
|
127
|
+
@parser.diagnostics.ignore_warnings = !@warnings
|
124
128
|
|
125
129
|
@parser.diagnostics.consumer = lambda do |diagnostic|
|
126
130
|
puts(diagnostic.render)
|
@@ -138,7 +142,7 @@ module Parser
|
|
138
142
|
process_files
|
139
143
|
end
|
140
144
|
|
141
|
-
if @
|
145
|
+
if @benchmark
|
142
146
|
report_with_time(parsing_time)
|
143
147
|
end
|
144
148
|
end
|
@@ -89,18 +89,26 @@ module Parser
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
def initialize
|
93
|
+
super
|
94
|
+
|
95
|
+
@locate = false
|
96
|
+
end
|
97
|
+
|
92
98
|
private
|
93
99
|
|
94
100
|
def runner_name
|
95
101
|
'ruby-parse'
|
96
102
|
end
|
97
103
|
|
98
|
-
def setup_option_parsing
|
99
|
-
super
|
104
|
+
def setup_option_parsing(opts)
|
105
|
+
super(opts)
|
100
106
|
|
101
|
-
|
107
|
+
opts.on '-L', '--locate', 'Explain how source maps for AST nodes are laid out' do |v|
|
108
|
+
@locate = v
|
109
|
+
end
|
102
110
|
|
103
|
-
|
111
|
+
opts.on '-E', '--explain', 'Explain how the source is tokenized' do
|
104
112
|
ENV['RACC_DEBUG'] = '1'
|
105
113
|
|
106
114
|
Lexer.send :include, Lexer::Explanation
|
@@ -118,9 +126,9 @@ module Parser
|
|
118
126
|
def process(buffer)
|
119
127
|
ast = @parser.parse(buffer)
|
120
128
|
|
121
|
-
if @
|
129
|
+
if @locate
|
122
130
|
LocationProcessor.new.process(ast)
|
123
|
-
elsif !@
|
131
|
+
elsif !@benchmark
|
124
132
|
p ast
|
125
133
|
end
|
126
134
|
end
|
@@ -17,14 +17,14 @@ module Parser
|
|
17
17
|
'ruby-rewrite'
|
18
18
|
end
|
19
19
|
|
20
|
-
def setup_option_parsing
|
21
|
-
super
|
20
|
+
def setup_option_parsing(opts)
|
21
|
+
super(opts)
|
22
22
|
|
23
|
-
|
23
|
+
opts.on '-l file', '--load', 'Load a rewriter' do |file|
|
24
24
|
load_and_discover(file)
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
opts.on '-m', '--modify', 'Assume rewriters normally modify AST' do
|
28
28
|
@modify = true
|
29
29
|
end
|
30
30
|
end
|
data/lib/parser/version.rb
CHANGED
data/parser.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ['whitequark@whitequark.org']
|
10
10
|
spec.description = 'A Ruby parser written in pure Ruby.'
|
11
11
|
spec.summary = spec.description
|
12
|
-
spec.homepage = '
|
12
|
+
spec.homepage = 'https://github.com/whitequark/parser'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
spec.has_rdoc = 'yard'
|
15
15
|
|
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
28
|
spec.add_dependency 'ast', ['>= 1.1', '< 3.0']
|
29
|
-
spec.add_dependency 'slop', ['~> 3.4', '>= 3.4.5']
|
30
29
|
|
31
30
|
spec.add_development_dependency 'bundler', '~> 1.2'
|
32
31
|
spec.add_development_dependency 'rake', '~> 10.0'
|
data/test/test_current.rb
CHANGED
@@ -14,8 +14,10 @@ class TestCurrent < Minitest::Test
|
|
14
14
|
assert_equal Parser::Ruby21, Parser::CurrentRuby
|
15
15
|
when /^2\.2\.\d+/
|
16
16
|
assert_equal Parser::Ruby22, Parser::CurrentRuby
|
17
|
+
when /^2\.3\.\d+/
|
18
|
+
assert_equal Parser::Ruby22, Parser::CurrentRuby
|
17
19
|
else
|
18
|
-
flunk "Update
|
20
|
+
flunk "Update test_current for #{RUBY_VERSION}"
|
19
21
|
end
|
20
22
|
end
|
21
23
|
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: 2.2.0.
|
4
|
+
version: 2.2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Zotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -30,26 +30,6 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3.0'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: slop
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '3.4'
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 3.4.5
|
43
|
-
type: :runtime
|
44
|
-
prerelease: false
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '3.4'
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 3.4.5
|
53
33
|
- !ruby/object:Gem::Dependency
|
54
34
|
name: bundler
|
55
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -351,7 +331,7 @@ files:
|
|
351
331
|
- test/test_source_rewriter.rb
|
352
332
|
- test/test_source_rewriter_action.rb
|
353
333
|
- test/test_static_environment.rb
|
354
|
-
homepage:
|
334
|
+
homepage: https://github.com/whitequark/parser
|
355
335
|
licenses:
|
356
336
|
- MIT
|
357
337
|
metadata: {}
|
@@ -371,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
371
351
|
version: '0'
|
372
352
|
requirements: []
|
373
353
|
rubyforge_project:
|
374
|
-
rubygems_version: 2.4.
|
354
|
+
rubygems_version: 2.4.1
|
375
355
|
signing_key:
|
376
356
|
specification_version: 4
|
377
357
|
summary: A Ruby parser written in pure Ruby.
|