parser 2.7.1.3 → 3.0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parser.rb +1 -1
- data/lib/parser/all.rb +1 -1
- data/lib/parser/ast/processor.rb +5 -7
- data/lib/parser/base.rb +7 -5
- data/lib/parser/builders/default.rb +225 -29
- data/lib/parser/context.rb +5 -0
- data/lib/parser/current.rb +11 -11
- data/lib/parser/current_arg_stack.rb +5 -2
- data/lib/parser/lexer.rb +23780 -0
- data/lib/parser/macruby.rb +6149 -0
- data/lib/parser/max_numparam_stack.rb +13 -5
- data/lib/parser/messages.rb +3 -0
- data/lib/parser/meta.rb +8 -7
- data/lib/parser/ruby18.rb +5667 -0
- data/lib/parser/ruby19.rb +6092 -0
- data/lib/parser/ruby20.rb +6527 -0
- data/lib/parser/ruby21.rb +6578 -0
- data/lib/parser/ruby22.rb +6613 -0
- data/lib/parser/ruby23.rb +6624 -0
- data/lib/parser/ruby24.rb +6694 -0
- data/lib/parser/ruby25.rb +6662 -0
- data/lib/parser/ruby26.rb +6676 -0
- data/lib/parser/ruby27.rb +7862 -0
- data/lib/parser/ruby28.rb +8047 -0
- data/lib/parser/ruby30.rb +8060 -0
- data/lib/parser/rubymotion.rb +6086 -0
- data/lib/parser/runner.rb +4 -4
- data/lib/parser/source/buffer.rb +50 -27
- data/lib/parser/source/comment.rb +1 -1
- data/lib/parser/source/comment/associator.rb +1 -1
- data/lib/parser/source/map/{endless_definition.rb → method_definition.rb} +5 -3
- data/lib/parser/source/range.rb +3 -3
- data/lib/parser/source/tree_rewriter.rb +94 -1
- data/lib/parser/source/tree_rewriter/action.rb +39 -0
- data/lib/parser/static_environment.rb +4 -0
- data/lib/parser/variables_stack.rb +4 -0
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +2 -18
- metadata +13 -102
- data/.gitignore +0 -34
- data/.travis.yml +0 -40
- data/.yardopts +0 -21
- data/CHANGELOG.md +0 -1101
- data/CONTRIBUTING.md +0 -17
- data/Gemfile +0 -10
- data/README.md +0 -308
- data/Rakefile +0 -167
- data/ci/run_rubocop_specs +0 -14
- data/doc/AST_FORMAT.md +0 -2229
- data/doc/CUSTOMIZATION.md +0 -37
- data/doc/INTERNALS.md +0 -21
- data/doc/css/.gitkeep +0 -0
- data/doc/css/common.css +0 -68
- data/lib/parser/lexer.rl +0 -2543
- data/lib/parser/macruby.y +0 -2198
- data/lib/parser/ruby18.y +0 -1934
- data/lib/parser/ruby19.y +0 -2175
- data/lib/parser/ruby20.y +0 -2353
- data/lib/parser/ruby21.y +0 -2357
- data/lib/parser/ruby22.y +0 -2364
- data/lib/parser/ruby23.y +0 -2370
- data/lib/parser/ruby24.y +0 -2408
- data/lib/parser/ruby25.y +0 -2405
- data/lib/parser/ruby26.y +0 -2413
- data/lib/parser/ruby27.y +0 -2941
- data/lib/parser/ruby28.y +0 -3016
- data/lib/parser/rubymotion.y +0 -2182
- data/test/bug_163/fixtures/input.rb +0 -5
- data/test/bug_163/fixtures/output.rb +0 -5
- data/test/bug_163/rewriter.rb +0 -20
- data/test/helper.rb +0 -79
- data/test/parse_helper.rb +0 -313
- data/test/racc_coverage_helper.rb +0 -133
- data/test/test_ast_processor.rb +0 -32
- data/test/test_base.rb +0 -31
- data/test/test_current.rb +0 -31
- data/test/test_diagnostic.rb +0 -95
- data/test/test_diagnostic_engine.rb +0 -59
- data/test/test_encoding.rb +0 -99
- data/test/test_lexer.rb +0 -3617
- data/test/test_lexer_stack_state.rb +0 -78
- data/test/test_meta.rb +0 -12
- data/test/test_parse_helper.rb +0 -80
- data/test/test_parser.rb +0 -9596
- data/test/test_runner_parse.rb +0 -56
- data/test/test_runner_rewrite.rb +0 -47
- data/test/test_source_buffer.rb +0 -165
- data/test/test_source_comment.rb +0 -36
- data/test/test_source_comment_associator.rb +0 -399
- data/test/test_source_map.rb +0 -14
- data/test/test_source_range.rb +0 -192
- data/test/test_source_rewriter.rb +0 -541
- data/test/test_source_rewriter_action.rb +0 -46
- data/test/test_source_tree_rewriter.rb +0 -263
- data/test/test_static_environment.rb +0 -45
- data/test/using_tree_rewriter/fixtures/input.rb +0 -3
- data/test/using_tree_rewriter/fixtures/output.rb +0 -3
- data/test/using_tree_rewriter/using_tree_rewriter.rb +0 -9
data/CONTRIBUTING.md
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
Contributing to Parser
|
2
|
-
----------------------
|
3
|
-
|
4
|
-
Parser employs a script to extract information from VCS (git) log and form a Changelog file. Thus, each commit which affects the public API in any way must be marked with one of the following sigils, or characters at the beginning of line:
|
5
|
-
|
6
|
-
* `-` for bugfixes. For example: `- lexer.rl: fixed lexing of "alias $foo $bar".`
|
7
|
-
* `+` for features. For example: `+ Implemented Parser::Rewriter, a module for non-intrusive rewriting of source code.`
|
8
|
-
* `*` for miscellaneous changes. For example: `* Converted measurement units from metric to imperial.`
|
9
|
-
|
10
|
-
Versioning
|
11
|
-
----------
|
12
|
-
|
13
|
-
Parser is versioned as follows:
|
14
|
-
* The version starts with the most recent Ruby version that Parser supports (which should be also the most recent released Ruby version).
|
15
|
-
* After that, a `.x` is appended, where `x` is incremented for every change.
|
16
|
-
|
17
|
-
No breaking changes to API will be ever made, except for changes that correct behavior which did not match documentation or Ruby MRI behavior.
|
data/Gemfile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in parser.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
# Workaround for bug in Bundler on JRuby
|
9
|
-
# See https://github.com/bundler/bundler/issues/4157
|
10
|
-
gem 'ast', '>= 1.1', '< 3.0'
|
data/README.md
DELETED
@@ -1,308 +0,0 @@
|
|
1
|
-
# Parser
|
2
|
-
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/parser.svg)](https://badge.fury.io/rb/parser)
|
4
|
-
[![Build Status](https://travis-ci.org/whitequark/parser.svg?branch=master)](https://travis-ci.org/whitequark/parser)
|
5
|
-
|
6
|
-
_Parser_ is a production-ready Ruby parser written in pure Ruby. It recognizes as
|
7
|
-
much or more code than Ripper, Melbourne, JRubyParser or ruby\_parser, and
|
8
|
-
is vastly more convenient to use.
|
9
|
-
|
10
|
-
You can also use [unparser](https://github.com/mbj/unparser) to produce
|
11
|
-
equivalent source code from Parser's ASTs.
|
12
|
-
|
13
|
-
Sponsored by [Evil Martians](http://evilmartians.com).
|
14
|
-
MacRuby and RubyMotion support sponsored by [CodeClimate](http://codeclimate.com).
|
15
|
-
|
16
|
-
## Installation
|
17
|
-
|
18
|
-
$ gem install parser
|
19
|
-
|
20
|
-
## Usage
|
21
|
-
|
22
|
-
Load Parser (see the [backwards compatibility](#backwards-compatibility) section
|
23
|
-
below for explanation of `emit_*` calls):
|
24
|
-
|
25
|
-
require 'parser/current'
|
26
|
-
# opt-in to most recent AST format:
|
27
|
-
Parser::Builders::Default.emit_lambda = true
|
28
|
-
Parser::Builders::Default.emit_procarg0 = true
|
29
|
-
Parser::Builders::Default.emit_encoding = true
|
30
|
-
Parser::Builders::Default.emit_index = true
|
31
|
-
Parser::Builders::Default.emit_arg_inside_procarg0 = true
|
32
|
-
|
33
|
-
Parse a chunk of code:
|
34
|
-
|
35
|
-
p Parser::CurrentRuby.parse("2 + 2")
|
36
|
-
# (send
|
37
|
-
# (int 2) :+
|
38
|
-
# (int 2))
|
39
|
-
|
40
|
-
Access the AST's source map:
|
41
|
-
|
42
|
-
p Parser::CurrentRuby.parse("2 + 2").loc
|
43
|
-
# #<Parser::Source::Map::Send:0x007fe5a1ac2388
|
44
|
-
# @dot=nil,
|
45
|
-
# @begin=nil,
|
46
|
-
# @end=nil,
|
47
|
-
# @selector=#<Source::Range (string) 2...3>,
|
48
|
-
# @expression=#<Source::Range (string) 0...5>>
|
49
|
-
|
50
|
-
p Parser::CurrentRuby.parse("2 + 2").loc.selector.source
|
51
|
-
# "+"
|
52
|
-
|
53
|
-
Traverse the AST: see the documentation for [gem ast](https://whitequark.github.io/ast/).
|
54
|
-
|
55
|
-
Parse a chunk of code and display all diagnostics:
|
56
|
-
|
57
|
-
parser = Parser::CurrentRuby.new
|
58
|
-
parser.diagnostics.consumer = lambda do |diag|
|
59
|
-
puts diag.render
|
60
|
-
end
|
61
|
-
|
62
|
-
buffer = Parser::Source::Buffer.new('(string)', source: "foo *bar")
|
63
|
-
|
64
|
-
p parser.parse(buffer)
|
65
|
-
# (string):1:5: warning: `*' interpreted as argument prefix
|
66
|
-
# foo *bar
|
67
|
-
# ^
|
68
|
-
# (send nil :foo
|
69
|
-
# (splat
|
70
|
-
# (send nil :bar)))
|
71
|
-
|
72
|
-
If you reuse the same parser object for multiple `#parse` runs, you need to
|
73
|
-
`#reset` it.
|
74
|
-
|
75
|
-
You can also use the `ruby-parse` utility (it's bundled with the gem) to play
|
76
|
-
with Parser:
|
77
|
-
|
78
|
-
$ ruby-parse -L -e "2+2"
|
79
|
-
(send
|
80
|
-
(int 2) :+
|
81
|
-
(int 2))
|
82
|
-
2+2
|
83
|
-
~ selector
|
84
|
-
~~~ expression
|
85
|
-
(int 2)
|
86
|
-
2+2
|
87
|
-
~ expression
|
88
|
-
(int 2)
|
89
|
-
2+2
|
90
|
-
|
91
|
-
$ ruby-parse -E -e "2+2"
|
92
|
-
2+2
|
93
|
-
^ tINTEGER 2 expr_end [0 <= cond] [0 <= cmdarg]
|
94
|
-
2+2
|
95
|
-
^ tPLUS "+" expr_beg [0 <= cond] [0 <= cmdarg]
|
96
|
-
2+2
|
97
|
-
^ tINTEGER 2 expr_end [0 <= cond] [0 <= cmdarg]
|
98
|
-
2+2
|
99
|
-
^ false "$eof" expr_end [0 <= cond] [0 <= cmdarg]
|
100
|
-
(send
|
101
|
-
(int 2) :+
|
102
|
-
(int 2))
|
103
|
-
|
104
|
-
## Features
|
105
|
-
|
106
|
-
* Precise source location reporting.
|
107
|
-
* [Documented](doc/AST_FORMAT.md) AST format which is convenient to work with.
|
108
|
-
* A simple interface and a powerful, tweakable one.
|
109
|
-
* Parses 1.8, 1.9, 2.0, 2.1, 2.2 and 2.3 syntax with backwards-compatible
|
110
|
-
AST formats.
|
111
|
-
* Parses MacRuby and RubyMotion syntax extensions.
|
112
|
-
* [Rewriting][rewriting] support.
|
113
|
-
* Parsing error recovery.
|
114
|
-
* Improved [clang-like][] diagnostic messages with location information.
|
115
|
-
* Written in pure Ruby, runs on MRI >=2.0.0, JRuby and Rubinius (and historically, all versions of Ruby since 1.8)
|
116
|
-
* Only one runtime dependency: the [ast][] gem.
|
117
|
-
* [Insane][insane-lexer] Ruby lexer rewritten from scratch in Ragel.
|
118
|
-
* 100% test coverage for Bison grammars (except error recovery).
|
119
|
-
* Readable, commented source code.
|
120
|
-
|
121
|
-
[clang-like]: http://clang.llvm.org/diagnostics.html
|
122
|
-
[ast]: https://rubygems.org/gems/ast
|
123
|
-
[insane-lexer]: http://whitequark.org/blog/2013/04/01/ruby-hacking-guide-ch-11-finite-state-lexer/
|
124
|
-
[rewriting]: http://whitequark.org/blog/2013/04/26/lets-play-with-ruby-code/
|
125
|
-
|
126
|
-
## Documentation
|
127
|
-
|
128
|
-
Documentation for Parser is available [online](https://whitequark.github.io/parser/).
|
129
|
-
|
130
|
-
### Node names
|
131
|
-
|
132
|
-
Several Parser nodes seem to be confusing enough to warrant a dedicated README section.
|
133
|
-
|
134
|
-
#### (block)
|
135
|
-
|
136
|
-
The `(block)` node passes a Ruby block, that is, a closure, to a method call represented by its first child, a `(send)`, `(super)` or `(zsuper)` node. To demonstrate:
|
137
|
-
|
138
|
-
```
|
139
|
-
$ ruby-parse -e 'foo { |x| x + 2 }'
|
140
|
-
(block
|
141
|
-
(send nil :foo)
|
142
|
-
(args
|
143
|
-
(arg :x))
|
144
|
-
(send
|
145
|
-
(lvar :x) :+
|
146
|
-
(int 2)))
|
147
|
-
```
|
148
|
-
|
149
|
-
#### (begin) and (kwbegin)
|
150
|
-
|
151
|
-
**TL;DR: Unless you perform rewriting, treat `(begin)` and `(kwbegin)` as the same node type.**
|
152
|
-
|
153
|
-
Both `(begin)` and `(kwbegin)` nodes represent compound statements, that is, several expressions which are executed sequentally and the value of the last one is the value of entire compound statement. They may take several forms in the source code:
|
154
|
-
|
155
|
-
* `foo; bar`: without delimiters
|
156
|
-
* `(foo; bar)`: parenthesized
|
157
|
-
* `begin foo; bar; end`: grouped with `begin` keyword
|
158
|
-
* `def x; foo; bar; end`: grouped inside a method definition
|
159
|
-
|
160
|
-
and so on.
|
161
|
-
|
162
|
-
```
|
163
|
-
$ ruby-parse -e '(foo; bar)'
|
164
|
-
(begin
|
165
|
-
(send nil :foo)
|
166
|
-
(send nil :bar))
|
167
|
-
$ ruby-parse -e 'def x; foo; bar end'
|
168
|
-
(def :x
|
169
|
-
(args)
|
170
|
-
(begin
|
171
|
-
(send nil :foo)
|
172
|
-
(send nil :bar)))
|
173
|
-
```
|
174
|
-
|
175
|
-
Note that, despite its name, `kwbegin` node only has tangential relation to the `begin` keyword. Normally, Parser AST is semantic, that is, if two constructs look differently but behave identically, they get parsed to the same node. However, there exists a peculiar construct called post-loop in Ruby:
|
176
|
-
|
177
|
-
```
|
178
|
-
begin
|
179
|
-
body
|
180
|
-
end while condition
|
181
|
-
```
|
182
|
-
|
183
|
-
This specific syntactic construct, that is, keyword `begin..end` block followed by a postfix `while`, [behaves][postloop] very unlike other similar constructs, e.g. `(body) while condition`. While the body itself is wrapped into a `while-post` node, Parser also supports rewriting, and in that context it is important to not accidentally convert one kind of loop into another.
|
184
|
-
|
185
|
-
[postloop]: http://rosettacode.org/wiki/Loops/Do-while#Ruby
|
186
|
-
|
187
|
-
```
|
188
|
-
$ ruby-parse -e 'begin foo end while cond'
|
189
|
-
(while-post
|
190
|
-
(send nil :cond)
|
191
|
-
(kwbegin
|
192
|
-
(send nil :foo)))
|
193
|
-
$ ruby-parse -e 'foo while cond'
|
194
|
-
(while
|
195
|
-
(send nil :cond)
|
196
|
-
(send nil :foo))
|
197
|
-
$ ruby-parse -e '(foo) while cond'
|
198
|
-
(while
|
199
|
-
(send nil :cond)
|
200
|
-
(begin
|
201
|
-
(send nil :foo)))
|
202
|
-
```
|
203
|
-
|
204
|
-
(Parser also needs the `(kwbegin)` node type internally, and it is highly problematic to map it back to `(begin)`.)
|
205
|
-
|
206
|
-
## Backwards compatibility
|
207
|
-
|
208
|
-
Parser does _not_ use semantic versioning. Parser versions are structured as `x.y.z.t`,
|
209
|
-
where `x.y.z` indicates the most recent supported Ruby release (support for every
|
210
|
-
Ruby release that is chronologically earlier is implied), and `t` is a monotonically
|
211
|
-
increasing number.
|
212
|
-
|
213
|
-
The public API of Parser as well as the AST format (as listed in the documentation)
|
214
|
-
are considered stable forever, although support for old Ruby versions may be removed
|
215
|
-
at some point.
|
216
|
-
|
217
|
-
Sometimes it is necessary to modify the format of AST nodes that are already being emitted
|
218
|
-
in a way that would break existing applications. To avoid such breakage, applications
|
219
|
-
must opt-in to these modifications; without explicit opt-in, Parser will continue to emit
|
220
|
-
the old AST node format. The most recent set of opt-ins is specified in
|
221
|
-
the [usage section](#usage) of this README.
|
222
|
-
|
223
|
-
## Compatibility with Ruby MRI
|
224
|
-
|
225
|
-
Unfortunately, Ruby MRI often changes syntax in patchlevel versions. This has happened, at least, for every release since 1.9; for example, commits [c5013452](https://github.com/ruby/ruby/commit/c501345218dc5fb0fae90d56a0c6fd19d38df5bb) and [04bb9d6b](https://github.com/ruby/ruby/commit/04bb9d6b75a55d4000700769eead5a5cb942c25b) were backported all the way from HEAD to 1.9. Moreover, there is no simple way to track these changes.
|
226
|
-
|
227
|
-
This policy makes it all but impossible to make Parser precisely compatible with the Ruby MRI parser. Indeed, at September 2014, it would be necessary to maintain and update ten different parsers together with their lexer quirks in order to be able to emulate any given released Ruby MRI version.
|
228
|
-
|
229
|
-
As a result, Parser chooses a different path: the `parser/rubyXY` parsers recognize the syntax of the latest minor version of Ruby MRI X.Y at the time of the gem release.
|
230
|
-
|
231
|
-
## Compatibility with MacRuby and RubyMotion
|
232
|
-
|
233
|
-
Parser implements the MacRuby 0.12 and RubyMotion mid-2015 parsers precisely. However, the lexers of these have been forked off Ruby MRI and independently maintained for some time, and because of that, Parser may accept some code that these upstream implementations are unable to parse.
|
234
|
-
|
235
|
-
## Known issues
|
236
|
-
|
237
|
-
Adding support for the following Ruby MRI features in Parser would needlessly complicate it, and as they all are very specific and rarely occurring corner cases, this is not done.
|
238
|
-
|
239
|
-
Parser has been extensively tested; in particular, it parses almost entire [Rubygems][rg] corpus. For every issue, a breakdown of affected gems is offered.
|
240
|
-
|
241
|
-
[rg]: https://rubygems.org
|
242
|
-
|
243
|
-
### Void value expressions
|
244
|
-
|
245
|
-
Ruby MRI prohibits so-called "void value expressions". For a description
|
246
|
-
of what a void value expression is, see [this
|
247
|
-
gist](https://gist.github.com/JoshCheek/5625007) and [this Parser
|
248
|
-
issue](https://github.com/whitequark/parser/issues/72).
|
249
|
-
|
250
|
-
It is unknown whether any gems are affected by this issue.
|
251
|
-
|
252
|
-
### Invalid characters inside comments and literals
|
253
|
-
|
254
|
-
Ruby MRI permits arbitrary non-7-bit byte sequences to appear in comments, as well as in string or symbol literals in form of escape sequences, regardless of source encoding. Parser requires all source code, including the expanded escape sequences, to consist of valid byte sequences in the source encoding that are convertible to UTF-8.
|
255
|
-
|
256
|
-
As of 2013-07-25, there are about 180 affected gems.
|
257
|
-
|
258
|
-
### \u escape in 1.8 mode
|
259
|
-
|
260
|
-
Ruby MRI 1.8 permits to specify a bare `\u` escape sequence in a string; it treats it like `u`. Ruby MRI 1.9 and later treat `\u` as a prefix for Unicode escape sequence and do not allow it to appear bare. Parser follows 1.9+ behavior.
|
261
|
-
|
262
|
-
As of 2013-07-25, affected gems are: activerdf, activerdf_net7, fastreader, gkellog-reddy.
|
263
|
-
|
264
|
-
### Dollar-dash
|
265
|
-
|
266
|
-
(This one is so obscure I couldn't even think of a saner name for this issue.) Pre-2.1 Ruby allows
|
267
|
-
to specify a global variable named `$-`. Ruby 2.1 and later treat it as a syntax error. Parser
|
268
|
-
follows 2.1 behavior.
|
269
|
-
|
270
|
-
No known code is affected by this issue.
|
271
|
-
|
272
|
-
### EOF characters after embedded documents before 2.7
|
273
|
-
|
274
|
-
Code like `"=begin\n""=end\0"` is invalid for all versions of Ruby before 2.7. Ruby 2.7 and later parses it
|
275
|
-
normally. Parser follows 2.7 behavior.
|
276
|
-
|
277
|
-
It is unknown whether any gems are affected by this issue.
|
278
|
-
|
279
|
-
## Contributors
|
280
|
-
|
281
|
-
* [whitequark][]
|
282
|
-
* Markus Schirp ([mbj][])
|
283
|
-
* Yorick Peterse ([yorickpeterse][])
|
284
|
-
* Magnus Holm ([judofyr][])
|
285
|
-
* Bozhidar Batsov ([bbatsov][])
|
286
|
-
|
287
|
-
[whitequark]: https://github.com/whitequark
|
288
|
-
[mbj]: https://github.com/mbj
|
289
|
-
[yorickpeterse]: https://github.com/yorickpeterse
|
290
|
-
[judofyr]: https://github.com/judofyr
|
291
|
-
[bbatsov]: https://github.com/bbatsov
|
292
|
-
|
293
|
-
## Acknowledgements
|
294
|
-
|
295
|
-
The lexer testsuite is derived from
|
296
|
-
[ruby\_parser](https://github.com/seattlerb/ruby_parser).
|
297
|
-
|
298
|
-
The Bison parser rules are derived from [Ruby MRI](https://github.com/ruby/ruby)
|
299
|
-
parse.y.
|
300
|
-
|
301
|
-
## Contributing
|
302
|
-
|
303
|
-
1. Make sure you have [Ragel ~> 6.7](http://www.complang.org/ragel/) installed
|
304
|
-
2. Fork it
|
305
|
-
3. Create your feature branch (`git checkout -b my-new-feature`)
|
306
|
-
4. Commit your changes (`git commit -am 'Add some feature'`)
|
307
|
-
5. Push to the branch (`git push origin my-new-feature`)
|
308
|
-
6. Create new Pull Request
|
data/Rakefile
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/gem_tasks'
|
5
|
-
require 'rake/testtask'
|
6
|
-
require 'rake/clean'
|
7
|
-
require 'date'
|
8
|
-
|
9
|
-
task :default => [:test]
|
10
|
-
|
11
|
-
Rake::TestTask.new do |t|
|
12
|
-
t.libs = %w(test/ lib/)
|
13
|
-
t.test_files = FileList["test/**/test_*.rb"]
|
14
|
-
t.warning = true
|
15
|
-
end
|
16
|
-
|
17
|
-
task :test_cov do
|
18
|
-
ENV['COVERAGE'] = '1'
|
19
|
-
Rake::Task['test'].invoke
|
20
|
-
end
|
21
|
-
|
22
|
-
task :build => [:generate_release, :changelog]
|
23
|
-
|
24
|
-
GENERATED_FILES = %w(lib/parser/lexer.rb
|
25
|
-
lib/parser/ruby18.rb
|
26
|
-
lib/parser/ruby19.rb
|
27
|
-
lib/parser/ruby20.rb
|
28
|
-
lib/parser/ruby21.rb
|
29
|
-
lib/parser/ruby22.rb
|
30
|
-
lib/parser/ruby23.rb
|
31
|
-
lib/parser/ruby24.rb
|
32
|
-
lib/parser/ruby25.rb
|
33
|
-
lib/parser/ruby26.rb
|
34
|
-
lib/parser/ruby27.rb
|
35
|
-
lib/parser/ruby28.rb
|
36
|
-
lib/parser/macruby.rb
|
37
|
-
lib/parser/rubymotion.rb)
|
38
|
-
|
39
|
-
CLEAN.include(GENERATED_FILES)
|
40
|
-
|
41
|
-
ENCODING_COMMENT = "# -*- encoding:utf-8; warn-indent:false; frozen_string_literal: true -*-\n"
|
42
|
-
|
43
|
-
desc 'Generate the Ragel lexer and Racc parser.'
|
44
|
-
task :generate => GENERATED_FILES do
|
45
|
-
Rake::Task[:ragel_check].invoke
|
46
|
-
GENERATED_FILES.each do |filename|
|
47
|
-
content = File.read(filename)
|
48
|
-
content = ENCODING_COMMENT + content unless content.start_with?(ENCODING_COMMENT)
|
49
|
-
|
50
|
-
File.open(filename, 'w') do |io|
|
51
|
-
io.write content
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
task :regenerate => [:clean, :generate]
|
57
|
-
|
58
|
-
desc 'Generate the Ragel lexer and Racc parser in release mode.'
|
59
|
-
task :generate_release => [:clean_env, :regenerate]
|
60
|
-
|
61
|
-
task :clean_env do
|
62
|
-
ENV.delete 'RACC_DEBUG'
|
63
|
-
end
|
64
|
-
|
65
|
-
task :ragel_check do
|
66
|
-
require 'cliver'
|
67
|
-
Cliver.assert('ragel', '~> 6.7')
|
68
|
-
end
|
69
|
-
|
70
|
-
desc 'Generate YARD documentation'
|
71
|
-
task :yard => :generate do
|
72
|
-
sh('yard doc')
|
73
|
-
end
|
74
|
-
|
75
|
-
PAGES_REPO = 'git@github.com:whitequark/parser'
|
76
|
-
|
77
|
-
desc "Build and deploy documentation to GitHub pages"
|
78
|
-
task :pages do
|
79
|
-
system "git clone #{PAGES_REPO} gh-temp/ -b gh-pages; rm gh-temp/* -rf; touch gh-temp/.nojekyll" or abort
|
80
|
-
system "yardoc -o gh-temp/;" or abort
|
81
|
-
system "cd gh-temp/; git add -A; git commit -m 'Updated pages.'; git push -f origin gh-pages" or abort
|
82
|
-
FileUtils.rm_rf 'gh-temp'
|
83
|
-
end
|
84
|
-
|
85
|
-
desc 'Generate Changelog'
|
86
|
-
task :changelog do
|
87
|
-
fs = "\u{fffd}"
|
88
|
-
format = "%d#{fs}%s#{fs}%an#{fs}%ai"
|
89
|
-
|
90
|
-
# Format: version => { commit-class => changes }
|
91
|
-
changelog = Hash.new do |hash, version|
|
92
|
-
hash[version] = Hash.new do |hash, klass|
|
93
|
-
hash[klass] = []
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
branch = `git describe HEAD --all`.strip.gsub(/.+\/([^\/]+)$/, '\1')
|
98
|
-
|
99
|
-
IO.popen("git log --pretty='#{format}' " \
|
100
|
-
"remotes/origin/2.0 remotes/origin/2.1 remotes/origin/2.2 #{branch}", 'r') do |io|
|
101
|
-
current_version = nil
|
102
|
-
|
103
|
-
io.each_line do |line|
|
104
|
-
version, message, author, date = line.
|
105
|
-
match(/^(?: \((.*)\))?#{fs}(.*)#{fs}(.*)#{fs}(.*)$/o).captures
|
106
|
-
date = Date.parse(date)
|
107
|
-
|
108
|
-
current_version = "#{$1} (#{date})" if version =~ /(v[\d\w.]+)/
|
109
|
-
current_version = "Not released (#{date})" \
|
110
|
-
if version =~ /(^| |\/)#{Regexp.escape branch}$/ && !branch.start_with?('v')
|
111
|
-
|
112
|
-
next if current_version.nil?
|
113
|
-
changelog[current_version] # add a hash
|
114
|
-
|
115
|
-
next if message !~ /^[+*-]/
|
116
|
-
changelog[current_version][message[0]] << "#{message[1..-1]} (#{author})"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
commit_classes = {
|
121
|
-
'*' => 'API modifications:',
|
122
|
-
'+' => 'Features implemented:',
|
123
|
-
'-' => 'Bugs fixed:',
|
124
|
-
}
|
125
|
-
|
126
|
-
File.open('CHANGELOG.md', 'w') do |io|
|
127
|
-
io.puts 'Changelog'
|
128
|
-
io.puts '========='
|
129
|
-
io.puts
|
130
|
-
|
131
|
-
changelog.each do |version, commits|
|
132
|
-
next if commits.empty?
|
133
|
-
io.puts version
|
134
|
-
io.puts '-' * version.length
|
135
|
-
io.puts
|
136
|
-
|
137
|
-
commit_classes.each do |sigil, description|
|
138
|
-
next unless commits[sigil].any?
|
139
|
-
|
140
|
-
io.puts description
|
141
|
-
commits[sigil].uniq.each do |commit|
|
142
|
-
io.puts " * #{commit.gsub('<', '\<').lstrip}"
|
143
|
-
end
|
144
|
-
io.puts
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
sh('git commit CHANGELOG.md -m "Update changelog." || true')
|
150
|
-
end
|
151
|
-
|
152
|
-
rule '.rb' => '.rl' do |t|
|
153
|
-
sh "ragel -F1 -R #{t.source} -o #{t.name}"
|
154
|
-
end
|
155
|
-
|
156
|
-
rule '.rb' => '.y' do |t|
|
157
|
-
opts = [ "--superclass=Parser::Base",
|
158
|
-
t.source,
|
159
|
-
"-o", t.name
|
160
|
-
]
|
161
|
-
opts << "--no-line-convert" unless ENV['RACC_DEBUG']
|
162
|
-
opts << "--debug" if ENV['RACC_DEBUG']
|
163
|
-
|
164
|
-
sh "racc", *opts
|
165
|
-
end
|
166
|
-
|
167
|
-
task :test => [:generate]
|