parser 2.5.0.3 → 2.5.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +8 -2
- data/lib/parser/ast/processor.rb +4 -0
- data/lib/parser/base.rb +6 -1
- data/lib/parser/color.rb +32 -0
- data/lib/parser/lexer.rl +1 -5
- data/lib/parser/lexer/explanation.rb +6 -6
- data/lib/parser/ruby24.y +5 -5
- data/lib/parser/ruby25.y +5 -5
- data/lib/parser/runner/ruby_parse.rb +4 -3
- data/lib/parser/version.rb +1 -1
- data/test/test_parser.rb +28 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eae6cafd7a3fce8e37c8659d938ebaf9c07809373b09e67aadfce5812e270798
|
4
|
+
data.tar.gz: f5c5cbe528398b002fd7663fcd87083a4a6674a9c506b2d57c0c94015a3a006a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8721c4dd25927f9913423c7a5a1076b40d9652b2e327b6d74d02f9994e45a4bb53a69c1889d0fa271f1fb4756600a809cf11876add173fd4c65e64c4316c4225
|
7
|
+
data.tar.gz: 6b356ff3f6889594738f9b5c2ded84bc0abf20cf506caaaa627ff2ce5759edc68f0b73f6e4a9c0cab4dbf377df821979cd2fb179bf24ee3939868ec871fe3396
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
v2.5.0.4 (2018-03-13)
|
5
|
+
---------------------
|
6
|
+
|
7
|
+
Bugs fixed:
|
8
|
+
* AST::Processor: handle on_index, on_indexasgn, on_lambda. (Ilya Bylich)
|
9
|
+
|
10
|
+
v2.5.0.3 (2018-03-06)
|
11
|
+
---------------------
|
6
12
|
|
7
13
|
Bugs fixed:
|
8
14
|
* Accept `BEGIN` and `END` as correct method name (#463) (Masataka Pocke Kuwabara)
|
data/lib/parser/ast/processor.rb
CHANGED
@@ -166,7 +166,11 @@ module Parser
|
|
166
166
|
|
167
167
|
alias on_csend on_send
|
168
168
|
|
169
|
+
alias on_index process_regular_node
|
170
|
+
alias on_indexasgn process_regular_node
|
171
|
+
|
169
172
|
alias on_block process_regular_node
|
173
|
+
alias on_lambda process_regular_node
|
170
174
|
|
171
175
|
alias on_while process_regular_node
|
172
176
|
alias on_while_post process_regular_node
|
data/lib/parser/base.rb
CHANGED
@@ -131,6 +131,9 @@ module Parser
|
|
131
131
|
@builder.parser = self
|
132
132
|
@context = Context.new
|
133
133
|
|
134
|
+
# Last emitted token
|
135
|
+
@last_token = nil
|
136
|
+
|
134
137
|
if self.class::Racc_debug_parser && ENV['RACC_DEBUG']
|
135
138
|
@yydebug = true
|
136
139
|
end
|
@@ -222,7 +225,9 @@ module Parser
|
|
222
225
|
private
|
223
226
|
|
224
227
|
def next_token
|
225
|
-
@lexer.advance
|
228
|
+
token = @lexer.advance
|
229
|
+
@last_token = token
|
230
|
+
token
|
226
231
|
end
|
227
232
|
|
228
233
|
def check_kwarg_name(name_t)
|
data/lib/parser/color.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Parser
|
4
|
+
module Color
|
5
|
+
def self.color(str, code, bold: false)
|
6
|
+
return str unless STDOUT.tty?
|
7
|
+
code = Array(code)
|
8
|
+
code.unshift(1) if bold
|
9
|
+
"\e[#{code.join(';')}m#{str}\e[0m"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.red(str, bold: false)
|
13
|
+
color(str, 31, bold: bold)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.green(str, bold: false)
|
17
|
+
color(str, 32, bold: bold)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.yellow(str, bold: false)
|
21
|
+
color(str, 33, bold: bold)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.magenta(str, bold: false)
|
25
|
+
color(str, 35, bold: bold)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.underline(str)
|
29
|
+
color(str, 4)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/parser/lexer.rl
CHANGED
@@ -89,7 +89,7 @@ class Parser::Lexer
|
|
89
89
|
|
90
90
|
REGEXP_META_CHARACTERS = Regexp.union(*"\\$()*+.<>?[]^{|}".chars).freeze
|
91
91
|
|
92
|
-
attr_reader :source_buffer
|
92
|
+
attr_reader :source_buffer
|
93
93
|
|
94
94
|
attr_accessor :diagnostics
|
95
95
|
attr_accessor :static_env
|
@@ -175,9 +175,6 @@ class Parser::Lexer
|
|
175
175
|
|
176
176
|
# State before =begin / =end block comment
|
177
177
|
@cs_before_block_comment = self.class.lex_en_line_begin
|
178
|
-
|
179
|
-
# Last emitted token
|
180
|
-
@last_token = nil
|
181
178
|
end
|
182
179
|
|
183
180
|
def source_buffer=(source_buffer)
|
@@ -328,7 +325,6 @@ class Parser::Lexer
|
|
328
325
|
token = [ type, [ value, range(s, e) ] ]
|
329
326
|
|
330
327
|
@token_queue.push(token)
|
331
|
-
@last_token = token
|
332
328
|
|
333
329
|
@tokens.push(token) if @tokens
|
334
330
|
|
@@ -21,14 +21,14 @@ module Parser
|
|
21
21
|
more = "(in-kwarg)" if @in_kwarg
|
22
22
|
|
23
23
|
puts decorate(range,
|
24
|
-
"
|
25
|
-
"#{state.to_s.ljust(12)} #{@cond} #{@cmdarg} #{more}
|
24
|
+
Color.green("#{type} #{val.inspect}"),
|
25
|
+
"#{state.to_s.ljust(12)} #{@cond} #{@cmdarg} #{more}")
|
26
26
|
|
27
27
|
[ type, [val, range] ]
|
28
28
|
end
|
29
29
|
|
30
30
|
def state=(new_state)
|
31
|
-
puts "
|
31
|
+
puts " #{Color.yellow(">>> STATE SET <<<", bold: true)} " +
|
32
32
|
"#{new_state.to_s.ljust(12)} #{@cond} #{@cmdarg}".rjust(66)
|
33
33
|
|
34
34
|
self.state_before_explanation = new_state
|
@@ -40,12 +40,12 @@ module Parser
|
|
40
40
|
from, to = range.begin.column, range.end.column
|
41
41
|
|
42
42
|
line = range.source_line + ' '
|
43
|
-
line[from...to] =
|
43
|
+
line[from...to] = Color.underline(line[from...to])
|
44
44
|
|
45
45
|
tail_len = to - from - 1
|
46
46
|
tail = '~' * (tail_len >= 0 ? tail_len : 0)
|
47
|
-
decoration = "#{" " * from}
|
48
|
-
ljust(
|
47
|
+
decoration = "#{" " * from}#{Color.red("^#{tail}", bold: true)} #{token} ".
|
48
|
+
ljust(68) + info
|
49
49
|
|
50
50
|
[ line, decoration ]
|
51
51
|
end
|
data/lib/parser/ruby24.y
CHANGED
@@ -862,7 +862,7 @@ rule
|
|
862
862
|
#
|
863
863
|
# For all other cases (like `m n` or `m n, []`) we simply put 1 to the stack
|
864
864
|
# and later lexer pushes corresponding bits on top of it.
|
865
|
-
last_token = @
|
865
|
+
last_token = @last_token[0]
|
866
866
|
lookahead = last_token == :tLBRACK || last_token == :tLPAREN_ARG
|
867
867
|
|
868
868
|
if lookahead
|
@@ -1845,13 +1845,13 @@ regexp_contents: # nothing
|
|
1845
1845
|
}
|
1846
1846
|
| tSTRING_DBEG
|
1847
1847
|
{
|
1848
|
-
@lexer.
|
1849
|
-
@lexer.
|
1848
|
+
@lexer.push_cmdarg
|
1849
|
+
@lexer.push_cond
|
1850
1850
|
}
|
1851
1851
|
compstmt tSTRING_DEND
|
1852
1852
|
{
|
1853
|
-
@lexer.
|
1854
|
-
@lexer.
|
1853
|
+
@lexer.pop_cmdarg
|
1854
|
+
@lexer.pop_cond
|
1855
1855
|
|
1856
1856
|
result = @builder.begin(val[0], val[2], val[3])
|
1857
1857
|
}
|
data/lib/parser/ruby25.y
CHANGED
@@ -872,7 +872,7 @@ rule
|
|
872
872
|
#
|
873
873
|
# For all other cases (like `m n` or `m n, []`) we simply put 1 to the stack
|
874
874
|
# and later lexer pushes corresponding bits on top of it.
|
875
|
-
last_token = @
|
875
|
+
last_token = @last_token[0]
|
876
876
|
lookahead = last_token == :tLBRACK || last_token == :tLPAREN_ARG
|
877
877
|
|
878
878
|
if lookahead
|
@@ -1842,13 +1842,13 @@ regexp_contents: # nothing
|
|
1842
1842
|
}
|
1843
1843
|
| tSTRING_DBEG
|
1844
1844
|
{
|
1845
|
-
@lexer.
|
1846
|
-
@lexer.
|
1845
|
+
@lexer.push_cmdarg
|
1846
|
+
@lexer.push_cond
|
1847
1847
|
}
|
1848
1848
|
compstmt tSTRING_DEND
|
1849
1849
|
{
|
1850
|
-
@lexer.
|
1851
|
-
@lexer.
|
1850
|
+
@lexer.pop_cmdarg
|
1851
|
+
@lexer.pop_cond
|
1852
1852
|
|
1853
1853
|
result = @builder.begin(val[0], val[2], val[3])
|
1854
1854
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'parser/runner'
|
4
|
+
require 'parser/color'
|
4
5
|
require 'parser/lexer/explanation'
|
5
6
|
require 'json'
|
6
7
|
|
@@ -20,15 +21,15 @@ module Parser
|
|
20
21
|
print_line = lambda do
|
21
22
|
unless hilight_line.empty?
|
22
23
|
puts hilight_line.
|
23
|
-
gsub(/[a-z_]+/) { |m|
|
24
|
-
gsub(/[~.]+/) { |m|
|
24
|
+
gsub(/[a-z_]+/) { |m| Color.yellow(m, bold: true) }.
|
25
|
+
gsub(/[~.]+/) { |m| Color.magenta(m, bold: true) }
|
25
26
|
hilight_line = ''
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
print_source = lambda do |range|
|
30
31
|
source_line = range.source_line
|
31
|
-
puts
|
32
|
+
puts Color.green(source_line)
|
32
33
|
source_line
|
33
34
|
end
|
34
35
|
|
data/lib/parser/version.rb
CHANGED
data/test/test_parser.rb
CHANGED
@@ -6814,4 +6814,32 @@ class TestParser < Minitest::Test
|
|
6814
6814
|
%q{},
|
6815
6815
|
ALL_VERSIONS)
|
6816
6816
|
end
|
6817
|
+
|
6818
|
+
def test_bug_466
|
6819
|
+
assert_parses(
|
6820
|
+
s(:block,
|
6821
|
+
s(:send, nil, :foo,
|
6822
|
+
s(:dstr,
|
6823
|
+
s(:begin,
|
6824
|
+
s(:send,
|
6825
|
+
s(:begin,
|
6826
|
+
s(:send,
|
6827
|
+
s(:int, 1), :+,
|
6828
|
+
s(:int, 1))), :to_i)))),
|
6829
|
+
s(:args), nil),
|
6830
|
+
%q{foo "#{(1+1).to_i}" do; end},
|
6831
|
+
%q{},
|
6832
|
+
ALL_VERSIONS)
|
6833
|
+
end
|
6834
|
+
|
6835
|
+
def test_bug_473
|
6836
|
+
assert_parses(
|
6837
|
+
s(:send, nil, :m,
|
6838
|
+
s(:dstr,
|
6839
|
+
s(:begin,
|
6840
|
+
s(:array)))),
|
6841
|
+
%q{m "#{[]}"},
|
6842
|
+
%q{},
|
6843
|
+
ALL_VERSIONS)
|
6844
|
+
end
|
6817
6845
|
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.5.0.
|
4
|
+
version: 2.5.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- whitequark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- lib/parser/base.rb
|
184
184
|
- lib/parser/builders/default.rb
|
185
185
|
- lib/parser/clobbering_error.rb
|
186
|
+
- lib/parser/color.rb
|
186
187
|
- lib/parser/context.rb
|
187
188
|
- lib/parser/current.rb
|
188
189
|
- lib/parser/deprecation.rb
|
@@ -296,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
296
297
|
version: '0'
|
297
298
|
requirements: []
|
298
299
|
rubyforge_project:
|
299
|
-
rubygems_version: 2.
|
300
|
+
rubygems_version: 2.7.6
|
300
301
|
signing_key:
|
301
302
|
specification_version: 4
|
302
303
|
summary: A Ruby parser written in pure Ruby.
|