parser 2.6.5.0 → 2.7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parser.rb +4 -1
  3. data/lib/parser/all.rb +1 -0
  4. data/lib/parser/ast/processor.rb +21 -0
  5. data/lib/parser/base.rb +25 -5
  6. data/lib/parser/builders/default.rb +394 -24
  7. data/lib/parser/context.rb +5 -0
  8. data/lib/parser/current.rb +16 -7
  9. data/lib/parser/current_arg_stack.rb +43 -0
  10. data/lib/parser/diagnostic.rb +1 -1
  11. data/lib/parser/diagnostic/engine.rb +1 -2
  12. data/lib/parser/lexer.rb +23770 -0
  13. data/lib/parser/lexer/dedenter.rb +52 -49
  14. data/lib/parser/macruby.rb +6149 -0
  15. data/lib/parser/{lexer/max_numparam_stack.rb → max_numparam_stack.rb} +10 -4
  16. data/lib/parser/messages.rb +52 -29
  17. data/lib/parser/meta.rb +10 -5
  18. data/lib/parser/ruby18.rb +5663 -0
  19. data/lib/parser/ruby19.rb +6092 -0
  20. data/lib/parser/ruby20.rb +6527 -0
  21. data/lib/parser/ruby21.rb +6578 -0
  22. data/lib/parser/ruby22.rb +6613 -0
  23. data/lib/parser/ruby23.rb +6624 -0
  24. data/lib/parser/ruby24.rb +6694 -0
  25. data/lib/parser/ruby25.rb +6662 -0
  26. data/lib/parser/ruby26.rb +6676 -0
  27. data/lib/parser/ruby27.rb +7803 -0
  28. data/lib/parser/ruby28.rb +8047 -0
  29. data/lib/parser/ruby30.rb +8052 -0
  30. data/lib/parser/rubymotion.rb +6086 -0
  31. data/lib/parser/runner.rb +26 -2
  32. data/lib/parser/runner/ruby_rewrite.rb +2 -2
  33. data/lib/parser/source/buffer.rb +3 -1
  34. data/lib/parser/source/comment.rb +1 -1
  35. data/lib/parser/source/comment/associator.rb +14 -4
  36. data/lib/parser/source/map/method_definition.rb +25 -0
  37. data/lib/parser/source/range.rb +19 -3
  38. data/lib/parser/source/tree_rewriter.rb +115 -12
  39. data/lib/parser/source/tree_rewriter/action.rb +137 -28
  40. data/lib/parser/static_environment.rb +10 -0
  41. data/lib/parser/tree_rewriter.rb +1 -2
  42. data/lib/parser/variables_stack.rb +32 -0
  43. data/lib/parser/version.rb +1 -1
  44. data/parser.gemspec +10 -18
  45. metadata +22 -99
  46. data/.gitignore +0 -33
  47. data/.travis.yml +0 -45
  48. data/.yardopts +0 -21
  49. data/CHANGELOG.md +0 -997
  50. data/CONTRIBUTING.md +0 -17
  51. data/Gemfile +0 -10
  52. data/LICENSE.txt +0 -25
  53. data/README.md +0 -301
  54. data/Rakefile +0 -166
  55. data/ci/run_rubocop_specs +0 -14
  56. data/doc/AST_FORMAT.md +0 -1816
  57. data/doc/CUSTOMIZATION.md +0 -37
  58. data/doc/INTERNALS.md +0 -21
  59. data/doc/css/.gitkeep +0 -0
  60. data/doc/css/common.css +0 -68
  61. data/lib/parser/lexer.rl +0 -2533
  62. data/lib/parser/macruby.y +0 -2198
  63. data/lib/parser/ruby18.y +0 -1934
  64. data/lib/parser/ruby19.y +0 -2175
  65. data/lib/parser/ruby20.y +0 -2353
  66. data/lib/parser/ruby21.y +0 -2357
  67. data/lib/parser/ruby22.y +0 -2364
  68. data/lib/parser/ruby23.y +0 -2370
  69. data/lib/parser/ruby24.y +0 -2408
  70. data/lib/parser/ruby25.y +0 -2405
  71. data/lib/parser/ruby26.y +0 -2413
  72. data/lib/parser/ruby27.y +0 -2470
  73. data/lib/parser/rubymotion.y +0 -2182
  74. data/test/bug_163/fixtures/input.rb +0 -5
  75. data/test/bug_163/fixtures/output.rb +0 -5
  76. data/test/bug_163/rewriter.rb +0 -20
  77. data/test/helper.rb +0 -59
  78. data/test/parse_helper.rb +0 -316
  79. data/test/racc_coverage_helper.rb +0 -133
  80. data/test/test_base.rb +0 -31
  81. data/test/test_current.rb +0 -29
  82. data/test/test_diagnostic.rb +0 -96
  83. data/test/test_diagnostic_engine.rb +0 -62
  84. data/test/test_encoding.rb +0 -99
  85. data/test/test_lexer.rb +0 -3667
  86. data/test/test_lexer_stack_state.rb +0 -78
  87. data/test/test_parse_helper.rb +0 -80
  88. data/test/test_parser.rb +0 -7644
  89. data/test/test_runner_parse.rb +0 -35
  90. data/test/test_runner_rewrite.rb +0 -47
  91. data/test/test_source_buffer.rb +0 -162
  92. data/test/test_source_comment.rb +0 -36
  93. data/test/test_source_comment_associator.rb +0 -367
  94. data/test/test_source_map.rb +0 -15
  95. data/test/test_source_range.rb +0 -172
  96. data/test/test_source_rewriter.rb +0 -541
  97. data/test/test_source_rewriter_action.rb +0 -46
  98. data/test/test_source_tree_rewriter.rb +0 -173
  99. data/test/test_static_environment.rb +0 -45
  100. data/test/using_tree_rewriter/fixtures/input.rb +0 -3
  101. data/test/using_tree_rewriter/fixtures/output.rb +0 -3
  102. 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,301 +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
-
32
- Parse a chunk of code:
33
-
34
- p Parser::CurrentRuby.parse("2 + 2")
35
- # (send
36
- # (int 2) :+
37
- # (int 2))
38
-
39
- Access the AST's source map:
40
-
41
- p Parser::CurrentRuby.parse("2 + 2").loc
42
- # #<Parser::Source::Map::Send:0x007fe5a1ac2388
43
- # @dot=nil,
44
- # @begin=nil,
45
- # @end=nil,
46
- # @selector=#<Source::Range (string) 2...3>,
47
- # @expression=#<Source::Range (string) 0...5>>
48
-
49
- p Parser::CurrentRuby.parse("2 + 2").loc.selector.source
50
- # "+"
51
-
52
- Traverse the AST: see the documentation for [gem ast](https://whitequark.github.io/ast/).
53
-
54
- Parse a chunk of code and display all diagnostics:
55
-
56
- parser = Parser::CurrentRuby.new
57
- parser.diagnostics.consumer = lambda do |diag|
58
- puts diag.render
59
- end
60
-
61
- buffer = Parser::Source::Buffer.new('(string)')
62
- buffer.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 occuring 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
- ## Contributors
273
-
274
- * [whitequark][]
275
- * Markus Schirp ([mbj][])
276
- * Yorick Peterse ([yorickpeterse][])
277
- * Magnus Holm ([judofyr][])
278
- * Bozhidar Batsov ([bbatsov][])
279
-
280
- [whitequark]: https://github.com/whitequark
281
- [mbj]: https://github.com/mbj
282
- [yorickpeterse]: https://github.com/yorickpeterse
283
- [judofyr]: https://github.com/judofyr
284
- [bbatsov]: https://github.com/bbatsov
285
-
286
- ## Acknowledgements
287
-
288
- The lexer testsuite is derived from
289
- [ruby\_parser](https://github.com/seattlerb/ruby_parser).
290
-
291
- The Bison parser rules are derived from [Ruby MRI](https://github.com/ruby/ruby)
292
- parse.y.
293
-
294
- ## Contributing
295
-
296
- 1. Make sure you have [Ragel ~> 6.7](http://www.complang.org/ragel/) installed
297
- 2. Fork it
298
- 3. Create your feature branch (`git checkout -b my-new-feature`)
299
- 4. Commit your changes (`git commit -am 'Add some feature'`)
300
- 5. Push to the branch (`git push origin my-new-feature`)
301
- 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]