parser 2.0.0.beta9 → 2.0.0.beta10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +2 -0
- data/lib/parser/base.rb +51 -1
- data/lib/parser/diagnostic.rb +29 -0
- data/lib/parser/lexer.rl +2 -1
- data/lib/parser/runner.rb +0 -1
- data/lib/parser/version.rb +1 -1
- data/test/test_lexer.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a47e42f33d72ab96207e35566f56ad67703e7f5c
|
4
|
+
data.tar.gz: cb0f192cdb11da805eadfdead96876f391b8a061
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a4b9b8609df7899d0925461a44340b661ba412dd0c3faab434f3c2d46b79270cbd6daef4c564b5bbec613ff9fdbb9349390b8f9e5fd350f647a3190b34156a5
|
7
|
+
data.tar.gz: 655fbaa7bfa55cc55675f8be762bd4f1d4923265fbfe7a4fe0fcd9c1b844455646e635babc0713914c486f9e0c23dd0219c07c663a357b2ca7fcddf95f030ae5
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
v2.0.0.beta10 (2013-07-02)
|
5
|
+
--------------------------
|
6
|
+
|
7
|
+
Bugs fixed:
|
8
|
+
* ruby-parse, ruby-rewrite: fix require of removed compatibility shim. (Peter Zotov)
|
9
|
+
* lexer.rl: "def !@; end" unary bang. (Peter Zotov)
|
10
|
+
|
4
11
|
v2.0.0.beta9 (2013-06-28)
|
5
12
|
-------------------------
|
6
13
|
|
data/README.md
CHANGED
@@ -9,6 +9,8 @@ _Parser_ is a production-ready Ruby parser written in pure Ruby. It
|
|
9
9
|
performs on par or better than Ripper, Melbourne, JRubyParser or
|
10
10
|
ruby_parser.
|
11
11
|
|
12
|
+
You can also use [unparser](https://github.com/mbj/unparser) to produce equivalent source code from Parser's ASTs.
|
13
|
+
|
12
14
|
## Installation
|
13
15
|
|
14
16
|
Most recent version of Parser is 2.0; however, per [release schedule](https://github.com/whitequark/parser/issues/51), it stays in the beta status for a while. However, it handles much more input than stable 1.x branch, and for new work it is advisable to use the beta versions.
|
data/lib/parser/base.rb
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
module Parser
|
2
2
|
|
3
|
+
##
|
4
|
+
# @!attribute [r] diagnostics
|
5
|
+
# @return [Parser::Diagnostic::Engine]
|
6
|
+
#
|
7
|
+
# @!attribute [r] static_env
|
8
|
+
# @return [Parser::StaticEnvironment]
|
9
|
+
#
|
3
10
|
class Base < Racc::Parser
|
11
|
+
##
|
12
|
+
# Parses a string of Ruby code and returns the AST.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# Parser::Base.parse('puts "hello"')
|
16
|
+
#
|
17
|
+
# @param [String] string The block of code to parse.
|
18
|
+
# @param [String] file The name of the file the code originated from.
|
19
|
+
# @param [Numeric] line The initial line number.
|
20
|
+
# @return [Parser::AST::Node]
|
21
|
+
#
|
4
22
|
def self.parse(string, file='(string)', line=1)
|
5
23
|
parser = new
|
6
24
|
|
@@ -20,6 +38,12 @@ module Parser
|
|
20
38
|
parser.parse(source_buffer)
|
21
39
|
end
|
22
40
|
|
41
|
+
##
|
42
|
+
# Parses Ruby source code by reading it from a file.
|
43
|
+
#
|
44
|
+
# @param [String] filename Path to the file to parse.
|
45
|
+
# @see #parse
|
46
|
+
#
|
23
47
|
def self.parse_file(filename)
|
24
48
|
parse(File.read(filename), filename)
|
25
49
|
end
|
@@ -30,6 +54,9 @@ module Parser
|
|
30
54
|
# The source file currently being parsed.
|
31
55
|
attr_reader :source_buffer
|
32
56
|
|
57
|
+
##
|
58
|
+
# @param [Parser::Builders::Default] builder The AST builder to use.
|
59
|
+
#
|
33
60
|
def initialize(builder=Parser::Builders::Default.new)
|
34
61
|
@diagnostics = Diagnostic::Engine.new
|
35
62
|
|
@@ -49,6 +76,9 @@ module Parser
|
|
49
76
|
reset
|
50
77
|
end
|
51
78
|
|
79
|
+
##
|
80
|
+
# Resets the state of the parser.
|
81
|
+
#
|
52
82
|
def reset
|
53
83
|
@source_buffer = nil
|
54
84
|
@def_level = 0 # count of nested def's.
|
@@ -59,6 +89,12 @@ module Parser
|
|
59
89
|
self
|
60
90
|
end
|
61
91
|
|
92
|
+
##
|
93
|
+
# Parses a source buffer and returns the AST.
|
94
|
+
#
|
95
|
+
# @param [Parser::Source::Buffer] source_buffer The source buffer to parse.
|
96
|
+
# @return [Parser::AST::Node]
|
97
|
+
#
|
62
98
|
def parse(source_buffer)
|
63
99
|
@lexer.source_buffer = source_buffer
|
64
100
|
@source_buffer = source_buffer
|
@@ -70,6 +106,13 @@ module Parser
|
|
70
106
|
@lexer.source_buffer = nil
|
71
107
|
end
|
72
108
|
|
109
|
+
##
|
110
|
+
# Parses a source buffer and returns the AST along with the comments of the
|
111
|
+
# Ruby source code.
|
112
|
+
#
|
113
|
+
# @see #parse
|
114
|
+
# @return [Array]
|
115
|
+
#
|
73
116
|
def parse_with_comments(source_buffer)
|
74
117
|
@lexer.comments = []
|
75
118
|
|
@@ -78,7 +121,8 @@ module Parser
|
|
78
121
|
@lexer.comments = nil
|
79
122
|
end
|
80
123
|
|
81
|
-
|
124
|
+
##
|
125
|
+
# Currently, token stream format returned by #tokenize is not documented,
|
82
126
|
# but is considered part of a public API and only changed according
|
83
127
|
# to Semantic Versioning.
|
84
128
|
#
|
@@ -87,6 +131,9 @@ module Parser
|
|
87
131
|
# by `:tSTRING_BEG " :tSTRING_CONTENT foo :tSTRING_END "` and
|
88
132
|
# `:tSTRING "foo"`; such details must not be relied upon.
|
89
133
|
#
|
134
|
+
# @param [Parser::Source::Buffer] source_buffer
|
135
|
+
# @return [Array]
|
136
|
+
#
|
90
137
|
def tokenize(source_buffer)
|
91
138
|
@lexer.tokens = []
|
92
139
|
|
@@ -97,7 +144,10 @@ module Parser
|
|
97
144
|
@lexer.tokens = nil
|
98
145
|
end
|
99
146
|
|
147
|
+
##
|
100
148
|
# @api internal
|
149
|
+
# @return [TrueClass|FalseClass]
|
150
|
+
#
|
101
151
|
def in_def?
|
102
152
|
@def_level > 0
|
103
153
|
end
|
data/lib/parser/diagnostic.rb
CHANGED
@@ -1,11 +1,35 @@
|
|
1
1
|
module Parser
|
2
2
|
|
3
|
+
##
|
4
|
+
# @!attribute [r] level
|
5
|
+
# @return [Symbol]
|
6
|
+
#
|
7
|
+
# @!attribute [r] message
|
8
|
+
# @return [String]
|
9
|
+
#
|
10
|
+
# @!attribute [r] location
|
11
|
+
# @return [Parser::Source::Map]
|
12
|
+
#
|
13
|
+
# @!attribute [r] highlights
|
14
|
+
# @return [Array]
|
15
|
+
#
|
3
16
|
class Diagnostic
|
17
|
+
##
|
18
|
+
# Collection of the available diagnostic levels.
|
19
|
+
#
|
20
|
+
# @return [Array]
|
21
|
+
#
|
4
22
|
LEVELS = [:note, :warning, :error, :fatal].freeze
|
5
23
|
|
6
24
|
attr_reader :level, :message
|
7
25
|
attr_reader :location, :highlights
|
8
26
|
|
27
|
+
##
|
28
|
+
# @param [Symbol] level
|
29
|
+
# @param [String] message
|
30
|
+
# @param [Parser::Source::Range] location
|
31
|
+
# @param [Array<Parser::Source::Range>] highlights
|
32
|
+
#
|
9
33
|
def initialize(level, message, location, highlights=[])
|
10
34
|
unless LEVELS.include?(level)
|
11
35
|
raise ArgumentError,
|
@@ -21,6 +45,11 @@ module Parser
|
|
21
45
|
freeze
|
22
46
|
end
|
23
47
|
|
48
|
+
##
|
49
|
+
# Renders the diagnostic message as an array of three lines.
|
50
|
+
#
|
51
|
+
# @return [Array<String>]
|
52
|
+
#
|
24
53
|
def render
|
25
54
|
source_line = @location.source_line
|
26
55
|
highlight_line = ' ' * source_line.length
|
data/lib/parser/lexer.rl
CHANGED
@@ -329,6 +329,7 @@ class Parser::Lexer
|
|
329
329
|
'=>' => :tASSOC, '::' => :tCOLON2, '===' => :tEQQ,
|
330
330
|
'<=>' => :tCMP, '[]' => :tAREF, '[]=' => :tASET,
|
331
331
|
'{' => :tLCURLY, '}' => :tRCURLY, '`' => :tBACK_REF2,
|
332
|
+
'!@' => :tBANG,
|
332
333
|
}
|
333
334
|
|
334
335
|
PUNCTUATION_BEGIN = {
|
@@ -413,7 +414,7 @@ class Parser::Lexer
|
|
413
414
|
|
414
415
|
# A list of operators which are valid in the function name context, but
|
415
416
|
# have different semantics in others.
|
416
|
-
operator_fname = '[]' | '[]=' | '`' | '-@' | '+@' | '~@' ;
|
417
|
+
operator_fname = '[]' | '[]=' | '`' | '-@' | '+@' | '~@' | '!@' ;
|
417
418
|
|
418
419
|
# A list of operators which can occur within an assignment shortcut (+ → +=).
|
419
420
|
operator_arithmetic = '&' | '|' | '&&' | '||' | '^' | '+' | '-' |
|
data/lib/parser/runner.rb
CHANGED
data/lib/parser/version.rb
CHANGED
data/test/test_lexer.rb
CHANGED
@@ -346,6 +346,13 @@ class TestLexer < Minitest::Test
|
|
346
346
|
util_lex_token "!~", :tNMATCH, "!~"
|
347
347
|
end
|
348
348
|
|
349
|
+
def test_def_ubang
|
350
|
+
setup_lexer(20)
|
351
|
+
|
352
|
+
@lex.state = :expr_fname
|
353
|
+
util_lex_token '!@', :tBANG, '!@'
|
354
|
+
end
|
355
|
+
|
349
356
|
def test_carat
|
350
357
|
util_lex_token "^", :tCARET, "^"
|
351
358
|
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.0.0.
|
4
|
+
version: 2.0.0.beta10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Zotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|