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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d62cbf813cac258da20e47d807e808d4a5d86d98
4
- data.tar.gz: e708512bed38b4f38419882d82847f2272c11604
3
+ metadata.gz: 461f75016915d79b41bf1d98c2ffd979b85b92a8
4
+ data.tar.gz: e4e95ba6d0d7a54da4d29f10d103f9a9541a1102
5
5
  SHA512:
6
- metadata.gz: 250e93427ef7b9907fe8157f1ec494bb8a2e0d589760c137ffb553a81a1056ed079237d3cbe7d9ded2e15ff95a4e27d4bc6e74f19fede3050def8b06b37a9da3
7
- data.tar.gz: 05778b96f9bbe5d31ec2e5a071e09b4a9e6336ea06f447b80eb04dd8ed1ae53d45638f0653f3e594abdb35a9bc22d07e68de770e94c0ab190ea5af25022343ef
6
+ metadata.gz: af23698e24fc19b7c12cb521d21657be6a1aa5b7771562b3643e8be35082765fe02e3e81a8801f8667f28adb0114f3353b512ac9121eb673b68836c05286bfde
7
+ data.tar.gz: 82bc2d8abbf80d1c46860ae02ebea4dfe284799b88e3a9163b1121993158952eeff5a7c969b27d9d3e2281441eefd056c60c4f55eb66dd199d0324c73dbf6b8c
@@ -0,0 +1,10 @@
1
+ AllCops:
2
+ Excludes:
3
+ - lib/parser/lexer.rb
4
+ - lib/parser/ruby18.rb
5
+ - lib/parser/ruby19.rb
6
+ - lib/parser/ruby20.rb
7
+ - lib/parser/ruby21.rb
8
+
9
+ HashSyntax:
10
+ Enabled: false
@@ -0,0 +1,167 @@
1
+ Changelog
2
+ =========
3
+
4
+ 2.0.0.beta1 (2013-05-25)
5
+ ------------------------
6
+
7
+ API modifications:
8
+ * Completely rewrite whitespace handling in lexer (fixes #36). (Peter Zotov)
9
+ * Rename Parser::AST::Node#source_map to #location, #src to #loc (closes #40). (Peter Zotov)
10
+ * Rename Parser::Source::Range#to_source to #source (refs #40). (Peter Zotov)
11
+ * Rename (cdecl) node to (casgn), remove (cvdecl) nodes (fixes #26). (Peter Zotov)
12
+
13
+ Features implemented:
14
+ * Add Source::Comment.associate for mapping comments back to nodes (fixes #31). (Peter Zotov)
15
+ * Return AST and comments from Parser::Base#parse_with_comments. (Peter Zotov)
16
+ * Return comments from Parser::Base#tokenize (fixes #46). (Peter Zotov)
17
+ * Add tokenizer, Parser::Base#tokenize (refs #46). (Peter Zotov)
18
+ * lexer.rl: better location reporting for invalid unicode codepoints (fixes #38). (Peter Zotov)
19
+ * lexer.rl: better location reporting for unterminated =begin (fixes #37). (Peter Zotov)
20
+ * Better location reporting for hashes with labels. (Peter Zotov)
21
+ * Add `dot' source map to (send) nodes (fixes #34). (Peter Zotov)
22
+ * Significantly improve performance of Source::Buffer (fixes #28). (Peter Zotov)
23
+
24
+ Bugs fixed:
25
+ * lexer.rl: fix lexing label at line_begin "foo:bar" (fixes #48). (Peter Zotov)
26
+ * lexer.rl: "Option /^I/" is a method call (fixes #32). (Peter Zotov)
27
+ * Don't allow destructive mutation of line cache in Source::Buffer. (Peter Zotov)
28
+ * Fix quantifier in magic encoding parser (refs #33). (Peter Zotov)
29
+ * Better handling of magic encoding comment edge cases (fixes #33). (Peter Zotov)
30
+
31
+ v1.3.2 (2013-05-13)
32
+ -------------------
33
+
34
+ Features implemented:
35
+ * lexer.rl: disallow "$-" (dollar, dash, no character) special. (Peter Zotov)
36
+
37
+ Bugs fixed:
38
+ * Source::Range: fix #to_source for multiline ranges. (Peter Zotov)
39
+ * builders/default: source map for class/module name (fixes #24). (Peter Zotov)
40
+
41
+ v1.3.1 (2013-05-09)
42
+ -------------------
43
+
44
+ Bugs fixed:
45
+ * ruby{19,20,21}.y: "def foo\n=begin\n=end\nend" (fixes #22). (Peter Zotov)
46
+ * lexer.rl: "rescue::Exception" (fixes #23). (Peter Zotov)
47
+
48
+ v1.3.0 (2013-04-26)
49
+ -------------------
50
+
51
+ Bugs fixed:
52
+ * lexer.rl: "alias foo bar \n alias bar baz". (Peter Zotov)
53
+
54
+ v1.2.0 (2013-04-25)
55
+ -------------------
56
+
57
+ Bugs fixed:
58
+ * lexer.rl: lex "def String.foo; end" correctly (fixes #16). (Peter Zotov)
59
+ * lexer.rl: reject "1end", "1.1end". (Peter Zotov)
60
+
61
+ v1.1.0 (2013-04-18)
62
+ -------------------
63
+
64
+ API modifications:
65
+ * ruby19.y, ruby20.y, ruby21.y: check for Encoding support (fixes #9). (Peter Zotov)
66
+
67
+ Features implemented:
68
+ * builders/default: ignore duplicate _ args (>=1.9), _.* args (>1.9) (fixes #5). (Peter Zotov)
69
+ * builders/default: detect duplicate argument names (refs #5). (Peter Zotov)
70
+ * lexer.rl: "def foo bar: 1; end" (for ruby 2.1) (fixes #15). (Peter Zotov)
71
+ * ruby21.y: required keyword arguments. (Peter Zotov)
72
+
73
+ Bugs fixed:
74
+ * ruby20.y, ruby21.y: "foo::A += 1" and friends (scoped constant op-asgn). (Peter Zotov)
75
+
76
+ v1.0.1 (2013-04-18)
77
+ -------------------
78
+
79
+ Bugs fixed:
80
+ * builders/default: %Q{#{1}} and friends (fixes #14). (Peter Zotov)
81
+
82
+ v1.0.0 (2013-04-17)
83
+ -------------------
84
+
85
+ Features implemented:
86
+ * ruby20.y: "meth 1 do end.fun(bar) {}" and friends. (Peter Zotov)
87
+ * ruby20.y: keyword arguments. (Peter Zotov)
88
+ * ruby20.y: { **kwsplat }. (Peter Zotov)
89
+
90
+ v0.9.2 (2013-04-16)
91
+ -------------------
92
+
93
+ Features implemented:
94
+ * lexer.rl: "-> (a) {}". (Peter Zotov)
95
+ * builders/default: treat &&/|| lhs/rhs as conditional context. (Peter Zotov)
96
+ * ruby20.y: "class Foo \< a:b; end". (Peter Zotov)
97
+ * lexer.rl: "class \<\< a:b". (Peter Zotov)
98
+ * ruby19.y, ruby20.y: "f { || a:b }". (Peter Zotov)
99
+ * ruby19.y, ruby20.y: "def foo() a:b end", "def foo\n a:b end". (Peter Zotov)
100
+ * lexer.rl: %i/%I. (Peter Zotov)
101
+ * lexer.rl: warn at "foo **bar". (Peter Zotov)
102
+ * lexer.rl: ** at expr_beg is tDSTAR. (Peter Zotov)
103
+ * ruby20.y: "f {|;\nvar\n|}". (Peter Zotov)
104
+ * ruby20.y: "p () {}". (Peter Zotov)
105
+ * ruby20.y: "p begin 1.times do 1 end end". (Peter Zotov)
106
+ * ruby20.y: better error message for BEGIN{} in a method body. (Peter Zotov)
107
+
108
+ Bugs fixed:
109
+ * lexer.rl, ruby18.y, ruby19.y, ruby20.y: "%W[#{a}#@b foo #{c}]". (Peter Zotov)
110
+ * lexer.rl: parse "foo=1; foo / bar #/" as method call on 1.8, division on 1.9. (Peter Zotov)
111
+ * ruby18.y, ruby19.y: BEGIN{} does not introduce a scope. (Peter Zotov)
112
+ * lexer.rl: improve whitespace handling. (Peter Zotov)
113
+
114
+ v0.9.0 (2013-04-15)
115
+ -------------------
116
+
117
+ API modifications:
118
+ * runtime compatibility with 1.8.7. (Peter Zotov)
119
+
120
+ Features implemented:
121
+ * builders/default: check for multiple assignment in conditions (fixes #4). (Peter Zotov)
122
+ * builders/default: check if actual block and blockarg are passed (fixes #6). (Peter Zotov)
123
+ * ruby19.y: "foo::A += m foo". (Peter Zotov)
124
+ * ruby18.y, ruby19.y: "rescue without else is useless" warning. (Peter Zotov)
125
+ * ruby19.y: 99.16% coverage, 100% sans error recovery. (Peter Zotov)
126
+ * ruby19.y: mlhs arguments "def foo((a, *, p)) end". (Peter Zotov)
127
+ * ruby19.y: "fun (1) {}" and friends. (Peter Zotov)
128
+ * ruby19.y: mlhs post variables "a, *b, c = ...". (Peter Zotov)
129
+ * builders/default: @@a |= 1; def f; @@a |= 1; end. (Peter Zotov)
130
+ * ruby18.y: fun (&foo). (Peter Zotov)
131
+ * ruby18.y: block formal arguments. 99.33% coverage. (Peter Zotov)
132
+ * ruby18.y: fun(meth 1 do end); fun(1, meth 1 do end). (Peter Zotov)
133
+ * ruby18.y: "meth 1 do end.fun(bar)" and friends. (Peter Zotov)
134
+ * ruby18.y: foo () {}; a.foo () {}; a::foo () {}. (Peter Zotov)
135
+ * ruby18.y: various call argument combinations. (Peter Zotov)
136
+ * ruby18.y: foo (1, 2); foo (). (Peter Zotov)
137
+ * ruby18.y: foo (1).to_i. (Peter Zotov)
138
+ * ruby18.y: fun{}; fun(){}; fun(1){}; fun do end. (Peter Zotov)
139
+ * ruby18.y: foo.fun bar. (Peter Zotov)
140
+ * lexer.rl, ruby18.y: add support for cond/cmdarg stack states. (Peter Zotov)
141
+ * ruby18.y: rescue. (Peter Zotov)
142
+ * ruby18.y: begin end while|until (tests only). (Peter Zotov)
143
+ * ruby18.y: case. (Peter Zotov)
144
+ * ruby18.y: foo[m bar]. (Peter Zotov)
145
+ * ruby18.y: for..in. (Peter Zotov)
146
+
147
+ Bugs fixed:
148
+ * lexer.rl: handle : at expr_beg as a symbol, at expr_end as tCOLON. (Peter Zotov)
149
+ * lexer.rl: handle "rescue #foo\nbar". (Peter Zotov)
150
+ * lexer.rl: handle "foo.#bar\nbaz". (Peter Zotov)
151
+ * lexer.rl: fix location info for symbols. (Peter Zotov)
152
+ * lexer.rl: handle \<backslash>\<nl> at expr_beg. (Peter Zotov)
153
+ * lexer.rl: emit tCONSTANT/tIDENTIFIER/tFID in expr_dot. (Peter Zotov)
154
+ * lexer.rl: correctly disambiguate "x ::Foo" as tIDENT, tCOLON3, ... (Peter Zotov)
155
+ * lexer.rl: correctly disambiguate ident!= as tIDENTIFIER, tNEQ. (Peter Zotov)
156
+ * lexer.rl: correctly report the %r%% tREGEXP_BEG value as %r%. (Peter Zotov)
157
+ * ruby19.y: emit correct error on "nil = 1" and friends. (Peter Zotov)
158
+ * ruby19.y: 1.9 permits empty symbol literals. (Peter Zotov)
159
+ * ruby18.y: foo(&bar). (Peter Zotov)
160
+ * lexer.rl: don't lookahead two tokens on "func %{str} do". (Peter Zotov)
161
+ * lexer.rl: fix lexing of non-interp heredoc with trailing backslash. (Peter Zotov)
162
+ * lexer.rl: fix erroneous number and =begin lookahead in expr_beg. (Peter Zotov)
163
+ * lexer.rl: fix stack corruption. (Peter Zotov)
164
+ * lexer.rl: /= at expr_beg. (Peter Zotov)
165
+ * lexer.rl: class\<\<self. (Peter Zotov)
166
+ * fix lexing comments at expr_beg "{#1\n}". (Peter Zotov)
167
+
@@ -0,0 +1,10 @@
1
+ Contributing to Parser
2
+ ----------------------
3
+
4
+ Parser uses [Semantic Versioning](http://semver.org). Additionally, 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
+ These categories map nicely to semantic versioning: `-` bugfixes increment patchlevel, `+` features increment minor version, `*` API changes increment major version.
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in parser.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'rubocop', :platform => [:ruby_19, :ruby_20]
8
+ end
data/README.md CHANGED
@@ -1,32 +1,51 @@
1
1
  # Parser
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/parser.png)](http://badge.fury.io/rb/parser)
3
4
  [![Build Status](https://travis-ci.org/whitequark/parser.png?branch=master)](https://travis-ci.org/whitequark/parser)
4
5
  [![Code Climate](https://codeclimate.com/github/whitequark/parser.png)](https://codeclimate.com/github/whitequark/parser)
5
6
  [![Coverage Status](https://coveralls.io/repos/whitequark/parser/badge.png?branch=master)](https://coveralls.io/r/whitequark/parser)
6
7
 
7
- _Parser_ is a production-ready Ruby parser written in pure Ruby. It performs on par or better than Ripper, Melbourne, JRubyParser or ruby_parser.
8
+ _Parser_ is a production-ready Ruby parser written in pure Ruby. It
9
+ performs on par or better than Ripper, Melbourne, JRubyParser or
10
+ ruby_parser.
8
11
 
9
12
  ## Installation
10
13
 
11
- $ gem install parser
14
+ ~~~
15
+ $ gem install parser
16
+ ~~~
12
17
 
13
18
  ## Usage
14
19
 
15
20
  Parse a chunk of code:
16
21
 
17
22
  ~~~ ruby
18
- require 'parser/ruby20'
23
+ require 'parser/current'
19
24
 
20
- p Parser::Ruby20.parse("2 + 2")
25
+ p Parser::CurrentRuby.parse("2 + 2")
21
26
  # (send
22
27
  # (int 2) :+
23
28
  # (int 2))
24
29
  ~~~
25
30
 
31
+ Access the AST's source map:
32
+
33
+ ~~~ ruby
34
+ p Parser::CurrentRuby.parse("2 + 2").src
35
+ # #<Parser::Source::Map::Send:0x007fe0ca8a69b8
36
+ # @begin=nil,
37
+ # @end=nil,
38
+ # @expression=#<Source::Range (string) 0...5>,
39
+ # @selector=#<Source::Range (string) 2...3>>
40
+
41
+ p Parser::CurrentRuby.parse("2 + 2").src.selector.to_source
42
+ # "+"
43
+ ~~~
44
+
26
45
  Parse a chunk of code and display all diagnostics:
27
46
 
28
47
  ~~~ ruby
29
- parser = Parser::Ruby20.new
48
+ parser = Parser::CurrentRuby.new
30
49
  parser.diagnostics.consumer = lambda do |diag|
31
50
  puts diag.render
32
51
  end
@@ -45,6 +64,36 @@ p parser.parse(buffer)
45
64
 
46
65
  If you reuse the same parser object for multiple `#parse` runs, you need to `#reset` it.
47
66
 
67
+ You can also use the `ruby-parse` utility (it's bundled with the gem) to play with Parser:
68
+
69
+ ~~~
70
+ $ ruby-parse -L -e "2+2"
71
+ (send
72
+ (int 2) :+
73
+ (int 2))
74
+ 2+2
75
+ ~ selector
76
+ ~~~ expression
77
+ (int 2)
78
+ 2+2
79
+ ~ expression
80
+ (int 2)
81
+ 2+2
82
+
83
+ $ ruby-parse -E -e "2+2"
84
+ 2+2
85
+ ^ tINTEGER 2 expr_end [0 <= cond] [0 <= cmdarg]
86
+ 2+2
87
+ ^ tPLUS "+" expr_beg [0 <= cond] [0 <= cmdarg]
88
+ 2+2
89
+ ^ tINTEGER 2 expr_end [0 <= cond] [0 <= cmdarg]
90
+ 2+2
91
+ ^ false "$eof" expr_end [0 <= cond] [0 <= cmdarg]
92
+ (send
93
+ (int 2) :+
94
+ (int 2))
95
+ ~~~
96
+
48
97
  ## Features
49
98
 
50
99
  * Precise source location reporting.
@@ -54,7 +103,7 @@ If you reuse the same parser object for multiple `#parse` runs, you need to `#re
54
103
  * Parsing error recovery.
55
104
  * Improved [clang-like][] diagnostic messages with location information.
56
105
  * Written in pure Ruby, runs on MRI 1.8.7 or >=1.9.2, JRuby and Rubinius in 1.8 and 1.9 mode.
57
- * Single runtime dependency: the [ast][] gem.
106
+ * Only two runtime dependencies: the gems [ast][] and [slop][].
58
107
  * RubyParser compatibility (WIP, no, not really yet).
59
108
  * [Insane][insane-lexer] Ruby lexer rewritten from scratch in Ragel.
60
109
  * 100% test coverage for Bison grammars (except error recovery).
@@ -62,6 +111,7 @@ If you reuse the same parser object for multiple `#parse` runs, you need to `#re
62
111
 
63
112
  [clang-like]: http://clang.llvm.org/diagnostics.html
64
113
  [ast]: http://rubygems.org/gems/ast
114
+ [slop]: http://rubygems.org/gems/slop
65
115
  [insane-lexer]: http://whitequark.org/blog/2013/04/01/ruby-hacking-guide-ch-11-finite-state-lexer/
66
116
 
67
117
  ## Contributors
data/Rakefile CHANGED
@@ -1,15 +1,17 @@
1
+ # encoding:utf-8
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
  require 'rake/clean'
4
6
 
5
- task :default => [:generate, :test]
7
+ task :default => [:test]
6
8
 
7
9
  Rake::TestTask.new do |t|
8
10
  t.libs = %w(test/ lib/)
9
11
  t.test_files = FileList["test/**/test_*.rb"]
10
12
  end
11
13
 
12
- task :build => :generate_release
14
+ task :build => [:generate_release, :changelog]
13
15
 
14
16
  GENERATED_FILES = %w(lib/parser/lexer.rb
15
17
  lib/parser/ruby18.rb
@@ -40,11 +42,71 @@ task :clean_env do
40
42
  ENV.delete 'RACC_DEBUG'
41
43
  end
42
44
 
43
- desc 'Generates YARD documentation'
45
+ desc 'Generate YARD documentation'
44
46
  task :yard => :generate do
45
47
  sh('yard doc')
46
48
  end
47
49
 
50
+ desc 'Generate Changelog'
51
+ task :changelog do
52
+ fs = "\u{fffd}"
53
+ format = "%d#{fs}%s#{fs}%an#{fs}%ai"
54
+
55
+ # Format: version => { commit-class => changes }
56
+ changelog = Hash.new do |hash, version|
57
+ hash[version] = Hash.new do |hash, klass|
58
+ hash[klass] = []
59
+ end
60
+ end
61
+
62
+ IO.popen("git log --pretty='#{format}' HEAD", 'r') do |io|
63
+ current_version = nil
64
+
65
+ io.each_line do |line|
66
+ version, message, author, date = line.
67
+ match(/^(?: \((.*)\))?#{fs}(.*)#{fs}(.*)#{fs}(.*)$/o).captures
68
+ date = Date.parse(date)
69
+
70
+ current_version = "#{$1} (#{date})" if version =~ /(v\d+.\d+.\d+)/
71
+ current_version = "#{Parser::VERSION} (#{date})" if version =~ /HEAD/
72
+
73
+ next if current_version.nil? || message !~ /^[+*-]/
74
+
75
+ changelog[current_version][message[0]] << "#{message[1..-1]} (#{author})"
76
+ end
77
+ end
78
+
79
+ commit_classes = {
80
+ '*' => 'API modifications:',
81
+ '+' => 'Features implemented:',
82
+ '-' => 'Bugs fixed:',
83
+ }
84
+
85
+ File.open('CHANGELOG.md', 'w') do |io|
86
+ io.puts 'Changelog'
87
+ io.puts '========='
88
+ io.puts
89
+
90
+ changelog.each do |version, commits|
91
+ io.puts version
92
+ io.puts '-' * version.length
93
+ io.puts
94
+
95
+ commit_classes.each do |sigil, description|
96
+ next unless commits[sigil].any?
97
+
98
+ io.puts description
99
+ commits[sigil].each do |commit|
100
+ io.puts " * #{commit.gsub('<', '\<').lstrip}"
101
+ end
102
+ io.puts
103
+ end
104
+ end
105
+ end
106
+
107
+ sh('git commit CHANGELOG.md -m "Update changelog."')
108
+ end
109
+
48
110
  rule '.rb' => '.rl' do |t|
49
111
  sh "ragel -R #{t.source} -o #{t.name}"
50
112
  end
@@ -59,3 +121,4 @@ rule '.rb' => '.y' do |t|
59
121
  sh "racc", *opts
60
122
  end
61
123
 
124
+ task :test => [:generate]
@@ -392,19 +392,6 @@ Format:
392
392
 
393
393
  ### To class variable
394
394
 
395
- #### Inside a class scope
396
-
397
- Format:
398
-
399
- ~~~
400
- (cvdecl :@@foo (lvar :bar))
401
- "@@foo = bar"
402
- ^ operator
403
- ~~~~~~~~~~~ expression
404
- ~~~
405
-
406
- #### Inside a method scope
407
-
408
395
  Format:
409
396
 
410
397
  ~~~
@@ -432,7 +419,7 @@ Format:
432
419
  Format:
433
420
 
434
421
  ~~~
435
- (cdecl (cbase) :Foo (int 1))
422
+ (casgn (cbase) :Foo (int 1))
436
423
  "::Foo = 1"
437
424
  ~~~ name
438
425
  ~ operator
@@ -444,7 +431,7 @@ Format:
444
431
  Format:
445
432
 
446
433
  ~~~
447
- (cdecl (lvar :a) :Foo (int 1))
434
+ (casgn (lvar :a) :Foo (int 1))
448
435
  "a::Foo = 1"
449
436
  ~~~ name
450
437
  ~ operator
@@ -456,7 +443,7 @@ Format:
456
443
  Format:
457
444
 
458
445
  ~~~
459
- (cdecl nil :Foo (int 1))
446
+ (casgn nil :Foo (int 1))
460
447
  "Foo = 1"
461
448
  ~~~ name
462
449
  ~ operator