parser 2.7.1.1 → 2.7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parser.rb +1 -0
  3. data/lib/parser/all.rb +1 -0
  4. data/lib/parser/ast/processor.rb +2 -0
  5. data/lib/parser/base.rb +6 -5
  6. data/lib/parser/builders/default.rb +146 -19
  7. data/lib/parser/context.rb +1 -0
  8. data/lib/parser/current.rb +10 -1
  9. data/lib/parser/diagnostic.rb +1 -1
  10. data/lib/parser/diagnostic/engine.rb +1 -2
  11. data/lib/parser/lexer.rb +23770 -0
  12. data/lib/parser/macruby.rb +6149 -0
  13. data/lib/parser/max_numparam_stack.rb +1 -1
  14. data/lib/parser/messages.rb +17 -0
  15. data/lib/parser/meta.rb +5 -5
  16. data/lib/parser/ruby18.rb +5663 -0
  17. data/lib/parser/ruby19.rb +6092 -0
  18. data/lib/parser/ruby20.rb +6527 -0
  19. data/lib/parser/ruby21.rb +6578 -0
  20. data/lib/parser/ruby22.rb +6613 -0
  21. data/lib/parser/ruby23.rb +6624 -0
  22. data/lib/parser/ruby24.rb +6694 -0
  23. data/lib/parser/ruby25.rb +6662 -0
  24. data/lib/parser/ruby26.rb +6676 -0
  25. data/lib/parser/ruby27.rb +7803 -0
  26. data/lib/parser/ruby28.rb +8047 -0
  27. data/lib/parser/ruby30.rb +8052 -0
  28. data/lib/parser/rubymotion.rb +6086 -0
  29. data/lib/parser/runner.rb +26 -2
  30. data/lib/parser/runner/ruby_rewrite.rb +2 -2
  31. data/lib/parser/source/buffer.rb +3 -1
  32. data/lib/parser/source/comment.rb +1 -1
  33. data/lib/parser/source/comment/associator.rb +14 -4
  34. data/lib/parser/source/map/method_definition.rb +25 -0
  35. data/lib/parser/source/range.rb +10 -3
  36. data/lib/parser/source/tree_rewriter.rb +73 -10
  37. data/lib/parser/source/tree_rewriter/action.rb +114 -21
  38. data/lib/parser/tree_rewriter.rb +1 -2
  39. data/lib/parser/version.rb +1 -1
  40. data/parser.gemspec +3 -18
  41. metadata +16 -99
  42. data/.gitignore +0 -33
  43. data/.travis.yml +0 -42
  44. data/.yardopts +0 -21
  45. data/CHANGELOG.md +0 -1075
  46. data/CONTRIBUTING.md +0 -17
  47. data/Gemfile +0 -10
  48. data/LICENSE.txt +0 -25
  49. data/README.md +0 -309
  50. data/Rakefile +0 -166
  51. data/ci/run_rubocop_specs +0 -14
  52. data/doc/AST_FORMAT.md +0 -2180
  53. data/doc/CUSTOMIZATION.md +0 -37
  54. data/doc/INTERNALS.md +0 -21
  55. data/doc/css/.gitkeep +0 -0
  56. data/doc/css/common.css +0 -68
  57. data/lib/parser/lexer.rl +0 -2536
  58. data/lib/parser/macruby.y +0 -2198
  59. data/lib/parser/ruby18.y +0 -1934
  60. data/lib/parser/ruby19.y +0 -2175
  61. data/lib/parser/ruby20.y +0 -2353
  62. data/lib/parser/ruby21.y +0 -2357
  63. data/lib/parser/ruby22.y +0 -2364
  64. data/lib/parser/ruby23.y +0 -2370
  65. data/lib/parser/ruby24.y +0 -2408
  66. data/lib/parser/ruby25.y +0 -2405
  67. data/lib/parser/ruby26.y +0 -2413
  68. data/lib/parser/ruby27.y +0 -2941
  69. data/lib/parser/rubymotion.y +0 -2182
  70. data/test/bug_163/fixtures/input.rb +0 -5
  71. data/test/bug_163/fixtures/output.rb +0 -5
  72. data/test/bug_163/rewriter.rb +0 -20
  73. data/test/helper.rb +0 -60
  74. data/test/parse_helper.rb +0 -319
  75. data/test/racc_coverage_helper.rb +0 -133
  76. data/test/test_base.rb +0 -31
  77. data/test/test_current.rb +0 -29
  78. data/test/test_diagnostic.rb +0 -96
  79. data/test/test_diagnostic_engine.rb +0 -62
  80. data/test/test_encoding.rb +0 -99
  81. data/test/test_lexer.rb +0 -3608
  82. data/test/test_lexer_stack_state.rb +0 -78
  83. data/test/test_parse_helper.rb +0 -80
  84. data/test/test_parser.rb +0 -9430
  85. data/test/test_runner_parse.rb +0 -35
  86. data/test/test_runner_rewrite.rb +0 -47
  87. data/test/test_source_buffer.rb +0 -162
  88. data/test/test_source_comment.rb +0 -36
  89. data/test/test_source_comment_associator.rb +0 -367
  90. data/test/test_source_map.rb +0 -15
  91. data/test/test_source_range.rb +0 -187
  92. data/test/test_source_rewriter.rb +0 -541
  93. data/test/test_source_rewriter_action.rb +0 -46
  94. data/test/test_source_tree_rewriter.rb +0 -253
  95. data/test/test_static_environment.rb +0 -45
  96. data/test/using_tree_rewriter/fixtures/input.rb +0 -3
  97. data/test/using_tree_rewriter/fixtures/output.rb +0 -3
  98. data/test/using_tree_rewriter/using_tree_rewriter.rb +0 -9
@@ -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'
@@ -1,25 +0,0 @@
1
- Copyright (c) 2013-2016 whitequark <whitequark@whitequark.org>
2
-
3
- Parts of the source are derived from ruby_parser:
4
- Copyright (c) Ryan Davis, seattle.rb
5
-
6
- MIT License
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining
9
- a copy of this software and associated documentation files (the
10
- "Software"), to deal in the Software without restriction, including
11
- without limitation the rights to use, copy, modify, merge, publish,
12
- distribute, sublicense, and/or sell copies of the Software, and to
13
- permit persons to whom the Software is furnished to do so, subject to
14
- the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be
17
- included in all copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,309 +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)')
63
- buffer.source = "foo *bar"
64
-
65
- p parser.parse(buffer)
66
- # (string):1:5: warning: `*' interpreted as argument prefix
67
- # foo *bar
68
- # ^
69
- # (send nil :foo
70
- # (splat
71
- # (send nil :bar)))
72
-
73
- If you reuse the same parser object for multiple `#parse` runs, you need to
74
- `#reset` it.
75
-
76
- You can also use the `ruby-parse` utility (it's bundled with the gem) to play
77
- with Parser:
78
-
79
- $ ruby-parse -L -e "2+2"
80
- (send
81
- (int 2) :+
82
- (int 2))
83
- 2+2
84
- ~ selector
85
- ~~~ expression
86
- (int 2)
87
- 2+2
88
- ~ expression
89
- (int 2)
90
- 2+2
91
-
92
- $ ruby-parse -E -e "2+2"
93
- 2+2
94
- ^ tINTEGER 2 expr_end [0 <= cond] [0 <= cmdarg]
95
- 2+2
96
- ^ tPLUS "+" expr_beg [0 <= cond] [0 <= cmdarg]
97
- 2+2
98
- ^ tINTEGER 2 expr_end [0 <= cond] [0 <= cmdarg]
99
- 2+2
100
- ^ false "$eof" expr_end [0 <= cond] [0 <= cmdarg]
101
- (send
102
- (int 2) :+
103
- (int 2))
104
-
105
- ## Features
106
-
107
- * Precise source location reporting.
108
- * [Documented](doc/AST_FORMAT.md) AST format which is convenient to work with.
109
- * A simple interface and a powerful, tweakable one.
110
- * Parses 1.8, 1.9, 2.0, 2.1, 2.2 and 2.3 syntax with backwards-compatible
111
- AST formats.
112
- * Parses MacRuby and RubyMotion syntax extensions.
113
- * [Rewriting][rewriting] support.
114
- * Parsing error recovery.
115
- * Improved [clang-like][] diagnostic messages with location information.
116
- * Written in pure Ruby, runs on MRI >=2.0.0, JRuby and Rubinius (and historically, all versions of Ruby since 1.8)
117
- * Only one runtime dependency: the [ast][] gem.
118
- * [Insane][insane-lexer] Ruby lexer rewritten from scratch in Ragel.
119
- * 100% test coverage for Bison grammars (except error recovery).
120
- * Readable, commented source code.
121
-
122
- [clang-like]: http://clang.llvm.org/diagnostics.html
123
- [ast]: https://rubygems.org/gems/ast
124
- [insane-lexer]: http://whitequark.org/blog/2013/04/01/ruby-hacking-guide-ch-11-finite-state-lexer/
125
- [rewriting]: http://whitequark.org/blog/2013/04/26/lets-play-with-ruby-code/
126
-
127
- ## Documentation
128
-
129
- Documentation for Parser is available [online](https://whitequark.github.io/parser/).
130
-
131
- ### Node names
132
-
133
- Several Parser nodes seem to be confusing enough to warrant a dedicated README section.
134
-
135
- #### (block)
136
-
137
- 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:
138
-
139
- ```
140
- $ ruby-parse -e 'foo { |x| x + 2 }'
141
- (block
142
- (send nil :foo)
143
- (args
144
- (arg :x))
145
- (send
146
- (lvar :x) :+
147
- (int 2)))
148
- ```
149
-
150
- #### (begin) and (kwbegin)
151
-
152
- **TL;DR: Unless you perform rewriting, treat `(begin)` and `(kwbegin)` as the same node type.**
153
-
154
- 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:
155
-
156
- * `foo; bar`: without delimiters
157
- * `(foo; bar)`: parenthesized
158
- * `begin foo; bar; end`: grouped with `begin` keyword
159
- * `def x; foo; bar; end`: grouped inside a method definition
160
-
161
- and so on.
162
-
163
- ```
164
- $ ruby-parse -e '(foo; bar)'
165
- (begin
166
- (send nil :foo)
167
- (send nil :bar))
168
- $ ruby-parse -e 'def x; foo; bar end'
169
- (def :x
170
- (args)
171
- (begin
172
- (send nil :foo)
173
- (send nil :bar)))
174
- ```
175
-
176
- 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:
177
-
178
- ```
179
- begin
180
- body
181
- end while condition
182
- ```
183
-
184
- 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.
185
-
186
- [postloop]: http://rosettacode.org/wiki/Loops/Do-while#Ruby
187
-
188
- ```
189
- $ ruby-parse -e 'begin foo end while cond'
190
- (while-post
191
- (send nil :cond)
192
- (kwbegin
193
- (send nil :foo)))
194
- $ ruby-parse -e 'foo while cond'
195
- (while
196
- (send nil :cond)
197
- (send nil :foo))
198
- $ ruby-parse -e '(foo) while cond'
199
- (while
200
- (send nil :cond)
201
- (begin
202
- (send nil :foo)))
203
- ```
204
-
205
- (Parser also needs the `(kwbegin)` node type internally, and it is highly problematic to map it back to `(begin)`.)
206
-
207
- ## Backwards compatibility
208
-
209
- Parser does _not_ use semantic versioning. Parser versions are structured as `x.y.z.t`,
210
- where `x.y.z` indicates the most recent supported Ruby release (support for every
211
- Ruby release that is chronologically earlier is implied), and `t` is a monotonically
212
- increasing number.
213
-
214
- The public API of Parser as well as the AST format (as listed in the documentation)
215
- are considered stable forever, although support for old Ruby versions may be removed
216
- at some point.
217
-
218
- Sometimes it is necessary to modify the format of AST nodes that are already being emitted
219
- in a way that would break existing applications. To avoid such breakage, applications
220
- must opt-in to these modifications; without explicit opt-in, Parser will continue to emit
221
- the old AST node format. The most recent set of opt-ins is specified in
222
- the [usage section](#usage) of this README.
223
-
224
- ## Compatibility with Ruby MRI
225
-
226
- 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.
227
-
228
- 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.
229
-
230
- 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.
231
-
232
- ## Compatibility with MacRuby and RubyMotion
233
-
234
- 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.
235
-
236
- ## Known issues
237
-
238
- 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.
239
-
240
- Parser has been extensively tested; in particular, it parses almost entire [Rubygems][rg] corpus. For every issue, a breakdown of affected gems is offered.
241
-
242
- [rg]: https://rubygems.org
243
-
244
- ### Void value expressions
245
-
246
- Ruby MRI prohibits so-called "void value expressions". For a description
247
- of what a void value expression is, see [this
248
- gist](https://gist.github.com/JoshCheek/5625007) and [this Parser
249
- issue](https://github.com/whitequark/parser/issues/72).
250
-
251
- It is unknown whether any gems are affected by this issue.
252
-
253
- ### Invalid characters inside comments and literals
254
-
255
- 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.
256
-
257
- As of 2013-07-25, there are about 180 affected gems.
258
-
259
- ### \u escape in 1.8 mode
260
-
261
- 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.
262
-
263
- As of 2013-07-25, affected gems are: activerdf, activerdf_net7, fastreader, gkellog-reddy.
264
-
265
- ### Dollar-dash
266
-
267
- (This one is so obscure I couldn't even think of a saner name for this issue.) Pre-2.1 Ruby allows
268
- to specify a global variable named `$-`. Ruby 2.1 and later treat it as a syntax error. Parser
269
- follows 2.1 behavior.
270
-
271
- No known code is affected by this issue.
272
-
273
- ### EOF characters after embedded documents before 2.7
274
-
275
- Code like `"=begin\n""=end\0"` is invalid for all versions of Ruby before 2.7. Ruby 2.7 and later parses it
276
- normally. Parser follows 2.7 behavior.
277
-
278
- It is unknown whether any gems are affected by this issue.
279
-
280
- ## Contributors
281
-
282
- * [whitequark][]
283
- * Markus Schirp ([mbj][])
284
- * Yorick Peterse ([yorickpeterse][])
285
- * Magnus Holm ([judofyr][])
286
- * Bozhidar Batsov ([bbatsov][])
287
-
288
- [whitequark]: https://github.com/whitequark
289
- [mbj]: https://github.com/mbj
290
- [yorickpeterse]: https://github.com/yorickpeterse
291
- [judofyr]: https://github.com/judofyr
292
- [bbatsov]: https://github.com/bbatsov
293
-
294
- ## Acknowledgements
295
-
296
- The lexer testsuite is derived from
297
- [ruby\_parser](https://github.com/seattlerb/ruby_parser).
298
-
299
- The Bison parser rules are derived from [Ruby MRI](https://github.com/ruby/ruby)
300
- parse.y.
301
-
302
- ## Contributing
303
-
304
- 1. Make sure you have [Ragel ~> 6.7](http://www.complang.org/ragel/) installed
305
- 2. Fork it
306
- 3. Create your feature branch (`git checkout -b my-new-feature`)
307
- 4. Commit your changes (`git commit -am 'Add some feature'`)
308
- 5. Push to the branch (`git push origin my-new-feature`)
309
- 6. Create new Pull Request
data/Rakefile DELETED
@@ -1,166 +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 = false
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/macruby.rb
36
- lib/parser/rubymotion.rb)
37
-
38
- CLEAN.include(GENERATED_FILES)
39
-
40
- ENCODING_COMMENT = "# -*- encoding:utf-8; warn-indent:false; frozen_string_literal: true -*-\n"
41
-
42
- desc 'Generate the Ragel lexer and Racc parser.'
43
- task :generate => GENERATED_FILES do
44
- Rake::Task[:ragel_check].invoke
45
- GENERATED_FILES.each do |filename|
46
- content = File.read(filename)
47
- content = ENCODING_COMMENT + content unless content.start_with?(ENCODING_COMMENT)
48
-
49
- File.open(filename, 'w') do |io|
50
- io.write content
51
- end
52
- end
53
- end
54
-
55
- task :regenerate => [:clean, :generate]
56
-
57
- desc 'Generate the Ragel lexer and Racc parser in release mode.'
58
- task :generate_release => [:clean_env, :regenerate]
59
-
60
- task :clean_env do
61
- ENV.delete 'RACC_DEBUG'
62
- end
63
-
64
- task :ragel_check do
65
- require 'cliver'
66
- Cliver.assert('ragel', '~> 6.7')
67
- end
68
-
69
- desc 'Generate YARD documentation'
70
- task :yard => :generate do
71
- sh('yard doc')
72
- end
73
-
74
- PAGES_REPO = 'git@github.com:whitequark/parser'
75
-
76
- desc "Build and deploy documentation to GitHub pages"
77
- task :pages do
78
- system "git clone #{PAGES_REPO} gh-temp/ -b gh-pages; rm gh-temp/* -rf; touch gh-temp/.nojekyll" or abort
79
- system "yardoc -o gh-temp/;" or abort
80
- system "cd gh-temp/; git add -A; git commit -m 'Updated pages.'; git push -f origin gh-pages" or abort
81
- FileUtils.rm_rf 'gh-temp'
82
- end
83
-
84
- desc 'Generate Changelog'
85
- task :changelog do
86
- fs = "\u{fffd}"
87
- format = "%d#{fs}%s#{fs}%an#{fs}%ai"
88
-
89
- # Format: version => { commit-class => changes }
90
- changelog = Hash.new do |hash, version|
91
- hash[version] = Hash.new do |hash, klass|
92
- hash[klass] = []
93
- end
94
- end
95
-
96
- branch = `git describe HEAD --all`.strip.gsub(/.+\/([^\/]+)$/, '\1')
97
-
98
- IO.popen("git log --pretty='#{format}' " \
99
- "remotes/origin/2.0 remotes/origin/2.1 remotes/origin/2.2 #{branch}", 'r') do |io|
100
- current_version = nil
101
-
102
- io.each_line do |line|
103
- version, message, author, date = line.
104
- match(/^(?: \((.*)\))?#{fs}(.*)#{fs}(.*)#{fs}(.*)$/o).captures
105
- date = Date.parse(date)
106
-
107
- current_version = "#{$1} (#{date})" if version =~ /(v[\d\w.]+)/
108
- current_version = "Not released (#{date})" \
109
- if version =~ /(^| |\/)#{Regexp.escape branch}$/ && !branch.start_with?('v')
110
-
111
- next if current_version.nil?
112
- changelog[current_version] # add a hash
113
-
114
- next if message !~ /^[+*-]/
115
- changelog[current_version][message[0]] << "#{message[1..-1]} (#{author})"
116
- end
117
- end
118
-
119
- commit_classes = {
120
- '*' => 'API modifications:',
121
- '+' => 'Features implemented:',
122
- '-' => 'Bugs fixed:',
123
- }
124
-
125
- File.open('CHANGELOG.md', 'w') do |io|
126
- io.puts 'Changelog'
127
- io.puts '========='
128
- io.puts
129
-
130
- changelog.each do |version, commits|
131
- next if commits.empty?
132
- io.puts version
133
- io.puts '-' * version.length
134
- io.puts
135
-
136
- commit_classes.each do |sigil, description|
137
- next unless commits[sigil].any?
138
-
139
- io.puts description
140
- commits[sigil].uniq.each do |commit|
141
- io.puts " * #{commit.gsub('<', '\<').lstrip}"
142
- end
143
- io.puts
144
- end
145
- end
146
- end
147
-
148
- sh('git commit CHANGELOG.md -m "Update changelog." || true')
149
- end
150
-
151
- rule '.rb' => '.rl' do |t|
152
- sh "ragel -F1 -R #{t.source} -o #{t.name}"
153
- end
154
-
155
- rule '.rb' => '.y' do |t|
156
- opts = [ "--superclass=Parser::Base",
157
- t.source,
158
- "-o", t.name
159
- ]
160
- opts << "--no-line-convert" unless ENV['RACC_DEBUG']
161
- opts << "--debug" if ENV['RACC_DEBUG']
162
-
163
- sh "racc", *opts
164
- end
165
-
166
- task :test => [:generate]