parser 2.7.0.3 → 2.7.1.2
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/.gitignore +1 -0
- data/.travis.yml +14 -23
- data/CHANGELOG.md +42 -0
- data/README.md +5 -4
- data/Rakefile +1 -0
- data/doc/AST_FORMAT.md +32 -5
- data/lib/parser.rb +1 -0
- data/lib/parser/all.rb +1 -0
- data/lib/parser/ast/processor.rb +4 -0
- data/lib/parser/builders/default.rb +54 -14
- data/lib/parser/current.rb +13 -4
- data/lib/parser/lexer.rl +1 -1
- data/lib/parser/meta.rb +1 -1
- data/lib/parser/ruby27.y +16 -5
- data/lib/parser/ruby28.y +2974 -0
- data/lib/parser/runner.rb +5 -0
- data/lib/parser/source/map/endless_definition.rb +23 -0
- data/lib/parser/source/range.rb +9 -0
- data/lib/parser/source/tree_rewriter.rb +50 -13
- data/lib/parser/source/tree_rewriter/action.rb +96 -26
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +1 -0
- data/test/helper.rb +1 -0
- data/test/parse_helper.rb +2 -1
- data/test/test_current.rb +2 -0
- data/test/test_lexer.rb +12 -0
- data/test/test_parser.rb +190 -8
- data/test/test_source_range.rb +15 -0
- data/test/test_source_tree_rewriter.rb +93 -3
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e95a182ac672d1917e517628161ab896f34d4518df71430e0b349998817308e0
|
4
|
+
data.tar.gz: 24175a8fa5f50956127930f697ba4f09ae0561c359d9fea4ea19883c8c7c072a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e17dd645e2240c9b3f6d7972a03d2c0df0305548920643c9d930ed3fa8b6aee8da77211b11d80a4d3f651aa75c1c2d43e51daa46aca163bd292ba91e9bcc0e
|
7
|
+
data.tar.gz: e9b989147352537fb1460a71585ace1165f5bca6d3baa01fde8f83a5b951c305bb37bab9ac93b019c70b728e6152ecd178f07935c335aab5e0f3a8ee4caf83a8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -2,26 +2,17 @@ dist: trusty
|
|
2
2
|
language: ruby
|
3
3
|
matrix:
|
4
4
|
include:
|
5
|
-
- name: 2.
|
6
|
-
rvm: 2.
|
5
|
+
- name: 2.4.10 / Parser tests
|
6
|
+
rvm: 2.4.10
|
7
7
|
script: bundle exec rake test_cov
|
8
|
-
- name: 2.
|
9
|
-
rvm: 2.
|
8
|
+
- name: 2.5.8 / Parser tests
|
9
|
+
rvm: 2.5.8
|
10
10
|
script: bundle exec rake test_cov
|
11
|
-
- name: 2.
|
12
|
-
rvm: 2.
|
11
|
+
- name: 2.6.6 / Parser tests
|
12
|
+
rvm: 2.6.6
|
13
13
|
script: bundle exec rake test_cov
|
14
|
-
- name: 2.
|
15
|
-
rvm: 2.
|
16
|
-
script: bundle exec rake test_cov
|
17
|
-
- name: 2.5.7 / Parser tests
|
18
|
-
rvm: 2.5.7
|
19
|
-
script: bundle exec rake test_cov
|
20
|
-
- name: 2.6.5 / Parser tests
|
21
|
-
rvm: 2.6.5
|
22
|
-
script: bundle exec rake test_cov
|
23
|
-
- name: 2.7.0 / Parser tests
|
24
|
-
rvm: 2.7.0
|
14
|
+
- name: 2.7.1 / Parser tests
|
15
|
+
rvm: 2.7.1
|
25
16
|
script: bundle exec rake test_cov
|
26
17
|
- name: ruby-head / Parser tests
|
27
18
|
rvm: ruby-head
|
@@ -32,14 +23,14 @@ matrix:
|
|
32
23
|
- name: rbx-2 / Parser tests
|
33
24
|
rvm: rbx-2
|
34
25
|
script: bundle exec rake test_cov
|
35
|
-
- name: 2.5.
|
36
|
-
rvm: 2.5.
|
26
|
+
- name: 2.5.8 / Rubocop tests
|
27
|
+
rvm: 2.5.8
|
37
28
|
script: ./ci/run_rubocop_specs
|
38
|
-
- name: 2.6.
|
39
|
-
rvm: 2.6.
|
29
|
+
- name: 2.6.6 / Rubocop tests
|
30
|
+
rvm: 2.6.6
|
40
31
|
script: ./ci/run_rubocop_specs
|
41
|
-
- name: 2.7.
|
42
|
-
rvm: 2.7.
|
32
|
+
- name: 2.7.1 / Rubocop tests
|
33
|
+
rvm: 2.7.1
|
43
34
|
script: ./ci/run_rubocop_specs
|
44
35
|
allow_failures:
|
45
36
|
- rvm: ruby-head
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,48 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
Not released (2020-04-30)
|
5
|
+
-------------------------
|
6
|
+
|
7
|
+
Features implemented:
|
8
|
+
* ruby28.y: endless method definition (#676) (Vladimir Dementyev)
|
9
|
+
* ruby28.y: branch parser (#677) (Vladimir Dementyev)
|
10
|
+
|
11
|
+
Bugs fixed:
|
12
|
+
* ruby27.y: reject invalid lvar in pattern matching (#680) (Vladimir Dementyev)
|
13
|
+
|
14
|
+
v2.7.1.1 (2020-04-15)
|
15
|
+
---------------------
|
16
|
+
|
17
|
+
Features implemented:
|
18
|
+
* Add Source::Range#eql? and hash (#675) (Marc-André Lafortune)
|
19
|
+
* Source::TreeRewriter: Add #merge, #merge! and #empty? (#674) (Marc-André Lafortune)
|
20
|
+
|
21
|
+
v2.7.1.0 (2020-04-03)
|
22
|
+
---------------------
|
23
|
+
|
24
|
+
API modifications:
|
25
|
+
* Bump ruby versions to 2.4.10, 2.5.8, 2.6.6, 2.7.1. (#665) (Ilya Bylich)
|
26
|
+
|
27
|
+
Features implemented:
|
28
|
+
* ruby27.y: allow newlines inside braced pattern. (#664) (Ilya Bylich)
|
29
|
+
* ruby27.y: Allow trailing comma in hash pattern (#661) (Koichi ITO)
|
30
|
+
|
31
|
+
v2.7.0.5 (2020-03-20)
|
32
|
+
---------------------
|
33
|
+
|
34
|
+
Features implemented:
|
35
|
+
* ruby27.y: fix array pattern with tail source map (#659) (Vladimir Dementyev)
|
36
|
+
|
37
|
+
Bugs fixed:
|
38
|
+
* builder.rb: fix constant_pattern source map (#660) (Vladimir Dementyev)
|
39
|
+
|
40
|
+
v2.7.0.4 (2020-03-02)
|
41
|
+
---------------------
|
42
|
+
|
43
|
+
Bugs fixed:
|
44
|
+
* lexer.rl: allow spaces before comments-before-leading-dot. (#654) (Ilya Bylich)
|
45
|
+
|
4
46
|
v2.7.0.2 (2020-01-08)
|
5
47
|
---------------------
|
6
48
|
|
data/README.md
CHANGED
@@ -24,10 +24,11 @@ below for explanation of `emit_*` calls):
|
|
24
24
|
|
25
25
|
require 'parser/current'
|
26
26
|
# opt-in to most recent AST format:
|
27
|
-
Parser::Builders::Default.emit_lambda
|
28
|
-
Parser::Builders::Default.emit_procarg0
|
29
|
-
Parser::Builders::Default.emit_encoding
|
30
|
-
Parser::Builders::Default.emit_index
|
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
|
31
32
|
|
32
33
|
Parse a chunk of code:
|
33
34
|
|
data/Rakefile
CHANGED
data/doc/AST_FORMAT.md
CHANGED
@@ -637,7 +637,7 @@ Format:
|
|
637
637
|
(masgn (mlhs (ivasgn :@a) (cvasgn :@@b)) (array (splat (lvar :c))))
|
638
638
|
"@a, @@b = *c"
|
639
639
|
|
640
|
-
(masgn (mlhs (
|
640
|
+
(masgn (mlhs (lvasgn :a) (mlhs (lvasgn :b)) (lvasgn :c)) (lvar :d))
|
641
641
|
"a, (b, c) = d"
|
642
642
|
|
643
643
|
(masgn (mlhs (send (self) :a=) (send (self) :[]= (int 1))) (lvar :a))
|
@@ -802,6 +802,33 @@ Format:
|
|
802
802
|
~~~~~~~~~~~~~~~~~ expression
|
803
803
|
~~~
|
804
804
|
|
805
|
+
### "Endless" method
|
806
|
+
|
807
|
+
Format:
|
808
|
+
|
809
|
+
~~~
|
810
|
+
(def_e :foo (args) (int 42))
|
811
|
+
"def foo() = 42"
|
812
|
+
~~~ keyword
|
813
|
+
~~~ name
|
814
|
+
^ assignment
|
815
|
+
~~~~~~~~~~~~~~ expression
|
816
|
+
~~~
|
817
|
+
|
818
|
+
|
819
|
+
### "Endless" singleton method
|
820
|
+
|
821
|
+
Format:
|
822
|
+
|
823
|
+
~~~
|
824
|
+
(defs_e (self) :foo (args) (int 42))
|
825
|
+
"def self.foo() = 42"
|
826
|
+
~~~ keyword
|
827
|
+
~~~ name
|
828
|
+
^ assignment
|
829
|
+
~~~~~~~~~~~~~~~~~~~ expression
|
830
|
+
~~~
|
831
|
+
|
805
832
|
### Undefinition
|
806
833
|
|
807
834
|
Format:
|
@@ -2068,7 +2095,7 @@ so a single item match with comma gets interpreted as an array.
|
|
2068
2095
|
(array-pattern-with-tail
|
2069
2096
|
(match-var :foo))
|
2070
2097
|
"in foo,"
|
2071
|
-
|
2098
|
+
~~~~ expression
|
2072
2099
|
~~~
|
2073
2100
|
|
2074
2101
|
### Matching using hash pattern
|
@@ -2139,7 +2166,7 @@ Format:
|
|
2139
2166
|
"in X[^foo bar]"
|
2140
2167
|
~ begin (const-pattern)
|
2141
2168
|
~ end (const-pattern)
|
2142
|
-
|
2169
|
+
~~~~~~~~~~~~ expression (const-pattern)
|
2143
2170
|
~ name (const-pattern.const)
|
2144
2171
|
~ expression (const-pattern.const)
|
2145
2172
|
~~~
|
@@ -2157,7 +2184,7 @@ Format:
|
|
2157
2184
|
"in X[foo:, bar:]"
|
2158
2185
|
~ begin (const-pattern)
|
2159
2186
|
~ end (const-pattern)
|
2160
|
-
|
2187
|
+
~~~~~~~~~~~~~ expression (const-pattern)
|
2161
2188
|
~ name (const-pattern.const)
|
2162
2189
|
~ expression (const-pattern.const)
|
2163
2190
|
~~~
|
@@ -2173,7 +2200,7 @@ Format:
|
|
2173
2200
|
"in X[]"
|
2174
2201
|
~ begin (const-pattern)
|
2175
2202
|
~ end (const-pattern)
|
2176
|
-
|
2203
|
+
~~~ expression (const-pattern)
|
2177
2204
|
~ name (const-pattern.const)
|
2178
2205
|
~ expression (const-pattern.const)
|
2179
2206
|
~~ expression (const-pattern.array_pattern)
|
data/lib/parser.rb
CHANGED
@@ -46,6 +46,7 @@ module Parser
|
|
46
46
|
require 'parser/source/map/variable'
|
47
47
|
require 'parser/source/map/keyword'
|
48
48
|
require 'parser/source/map/definition'
|
49
|
+
require 'parser/source/map/endless_definition'
|
49
50
|
require 'parser/source/map/send'
|
50
51
|
require 'parser/source/map/index'
|
51
52
|
require 'parser/source/map/condition'
|
data/lib/parser/all.rb
CHANGED
data/lib/parser/ast/processor.rb
CHANGED
@@ -159,6 +159,8 @@ module Parser
|
|
159
159
|
])
|
160
160
|
end
|
161
161
|
|
162
|
+
alias on_def_e on_def
|
163
|
+
|
162
164
|
def on_defs(node)
|
163
165
|
definee_node, name, args_node, body_node = *node
|
164
166
|
|
@@ -168,6 +170,8 @@ module Parser
|
|
168
170
|
])
|
169
171
|
end
|
170
172
|
|
173
|
+
alias on_defs_e on_defs
|
174
|
+
|
171
175
|
alias on_undef process_regular_node
|
172
176
|
alias on_alias process_regular_node
|
173
177
|
|
@@ -652,19 +652,28 @@ module Parser
|
|
652
652
|
definition_map(def_t, nil, name_t, end_t))
|
653
653
|
end
|
654
654
|
|
655
|
+
def def_endless_method(def_t, name_t, args,
|
656
|
+
assignment_t, body)
|
657
|
+
n(:def_e, [ value(name_t).to_sym, args, body ],
|
658
|
+
endless_definition_map(def_t, nil, name_t, assignment_t, body))
|
659
|
+
end
|
660
|
+
|
655
661
|
def def_singleton(def_t, definee, dot_t,
|
656
662
|
name_t, args,
|
657
663
|
body, end_t)
|
658
|
-
|
659
|
-
when :int, :str, :dstr, :sym, :dsym,
|
660
|
-
:regexp, :array, :hash
|
664
|
+
return unless validate_definee(definee)
|
661
665
|
|
662
|
-
|
666
|
+
n(:defs, [ definee, value(name_t).to_sym, args, body ],
|
667
|
+
definition_map(def_t, dot_t, name_t, end_t))
|
668
|
+
end
|
663
669
|
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
670
|
+
def def_endless_singleton(def_t, definee, dot_t,
|
671
|
+
name_t, args,
|
672
|
+
assignment_t, body)
|
673
|
+
return unless validate_definee(definee)
|
674
|
+
|
675
|
+
n(:defs_e, [ definee, value(name_t).to_sym, args, body ],
|
676
|
+
endless_definition_map(def_t, dot_t, name_t, assignment_t, body))
|
668
677
|
end
|
669
678
|
|
670
679
|
def undef_method(undef_t, names)
|
@@ -1239,8 +1248,10 @@ module Parser
|
|
1239
1248
|
|
1240
1249
|
def match_var(name_t)
|
1241
1250
|
name = value(name_t).to_sym
|
1251
|
+
name_l = loc(name_t)
|
1242
1252
|
|
1243
|
-
|
1253
|
+
check_lvar_name(name, name_l)
|
1254
|
+
check_duplicate_pattern_variable(name, name_l)
|
1244
1255
|
@parser.static_env.declare(name)
|
1245
1256
|
|
1246
1257
|
n(:match_var, [ name ],
|
@@ -1253,6 +1264,7 @@ module Parser
|
|
1253
1264
|
expr_l = loc(name_t)
|
1254
1265
|
name_l = expr_l.adjust(end_pos: -1)
|
1255
1266
|
|
1267
|
+
check_lvar_name(name, name_l)
|
1256
1268
|
check_duplicate_pattern_variable(name, name_l)
|
1257
1269
|
@parser.static_env.declare(name)
|
1258
1270
|
|
@@ -1293,6 +1305,9 @@ module Parser
|
|
1293
1305
|
Source::Map::Variable.new(name_l, expr_l))
|
1294
1306
|
when :begin
|
1295
1307
|
match_hash_var_from_str(begin_t, string.children, end_t)
|
1308
|
+
else
|
1309
|
+
# we only can get here if there is an interpolation, e.g., ``in "#{ a }":`
|
1310
|
+
diagnostic :error, :pm_interp_in_var_name, nil, loc(begin_t).join(loc(end_t))
|
1296
1311
|
end
|
1297
1312
|
end
|
1298
1313
|
|
@@ -1318,7 +1333,7 @@ module Parser
|
|
1318
1333
|
|
1319
1334
|
trailing_comma = false
|
1320
1335
|
|
1321
|
-
|
1336
|
+
node_elements = elements.map do |element|
|
1322
1337
|
if element.type == :match_with_trailing_comma
|
1323
1338
|
trailing_comma = true
|
1324
1339
|
element.children.first
|
@@ -1329,17 +1344,22 @@ module Parser
|
|
1329
1344
|
end
|
1330
1345
|
|
1331
1346
|
node_type = trailing_comma ? :array_pattern_with_tail : :array_pattern
|
1332
|
-
|
1347
|
+
|
1348
|
+
n(node_type, node_elements,
|
1333
1349
|
collection_map(lbrack_t, elements, rbrack_t))
|
1334
1350
|
end
|
1335
1351
|
|
1336
|
-
def match_with_trailing_comma(match)
|
1337
|
-
n(:match_with_trailing_comma, [ match ],
|
1352
|
+
def match_with_trailing_comma(match, comma_t)
|
1353
|
+
n(:match_with_trailing_comma, [ match ], expr_map(match.loc.expression.join(loc(comma_t))))
|
1338
1354
|
end
|
1339
1355
|
|
1340
1356
|
def const_pattern(const, ldelim_t, pattern, rdelim_t)
|
1341
1357
|
n(:const_pattern, [const, pattern],
|
1342
|
-
|
1358
|
+
Source::Map::Collection.new(
|
1359
|
+
loc(ldelim_t), loc(rdelim_t),
|
1360
|
+
const.loc.expression.join(loc(rdelim_t))
|
1361
|
+
)
|
1362
|
+
)
|
1343
1363
|
end
|
1344
1364
|
|
1345
1365
|
def pin(pin_t, var)
|
@@ -1732,6 +1752,14 @@ module Parser
|
|
1732
1752
|
loc(end_t))
|
1733
1753
|
end
|
1734
1754
|
|
1755
|
+
def endless_definition_map(keyword_t, operator_t, name_t, assignment_t, body_e)
|
1756
|
+
body_l = body_e.loc.expression
|
1757
|
+
|
1758
|
+
Source::Map::EndlessDefinition.new(loc(keyword_t),
|
1759
|
+
loc(operator_t), loc(name_t),
|
1760
|
+
loc(assignment_t), body_l)
|
1761
|
+
end
|
1762
|
+
|
1735
1763
|
def send_map(receiver_e, dot_t, selector_t, begin_t=nil, args=[], end_t=nil)
|
1736
1764
|
if receiver_e
|
1737
1765
|
begin_l = receiver_e.loc.expression
|
@@ -1974,6 +2002,18 @@ module Parser
|
|
1974
2002
|
@parser.send :yyerror
|
1975
2003
|
end
|
1976
2004
|
end
|
2005
|
+
|
2006
|
+
def validate_definee(definee)
|
2007
|
+
case definee.type
|
2008
|
+
when :int, :str, :dstr, :sym, :dsym,
|
2009
|
+
:regexp, :array, :hash
|
2010
|
+
|
2011
|
+
diagnostic :error, :singleton_literal, nil, definee.loc.expression
|
2012
|
+
false
|
2013
|
+
else
|
2014
|
+
true
|
2015
|
+
end
|
2016
|
+
end
|
1977
2017
|
end
|
1978
2018
|
|
1979
2019
|
end
|
data/lib/parser/current.rb
CHANGED
@@ -48,7 +48,7 @@ module Parser
|
|
48
48
|
CurrentRuby = Ruby23
|
49
49
|
|
50
50
|
when /^2\.4\./
|
51
|
-
current_version = '2.4.
|
51
|
+
current_version = '2.4.10'
|
52
52
|
if RUBY_VERSION != current_version
|
53
53
|
warn_syntax_deviation 'parser/ruby24', current_version
|
54
54
|
end
|
@@ -57,7 +57,7 @@ module Parser
|
|
57
57
|
CurrentRuby = Ruby24
|
58
58
|
|
59
59
|
when /^2\.5\./
|
60
|
-
current_version = '2.5.
|
60
|
+
current_version = '2.5.8'
|
61
61
|
if RUBY_VERSION != current_version
|
62
62
|
warn_syntax_deviation 'parser/ruby25', current_version
|
63
63
|
end
|
@@ -66,7 +66,7 @@ module Parser
|
|
66
66
|
CurrentRuby = Ruby25
|
67
67
|
|
68
68
|
when /^2\.6\./
|
69
|
-
current_version = '2.6.
|
69
|
+
current_version = '2.6.6'
|
70
70
|
if RUBY_VERSION != current_version
|
71
71
|
warn_syntax_deviation 'parser/ruby26', current_version
|
72
72
|
end
|
@@ -75,7 +75,7 @@ module Parser
|
|
75
75
|
CurrentRuby = Ruby26
|
76
76
|
|
77
77
|
when /^2\.7\./
|
78
|
-
current_version = '2.7.
|
78
|
+
current_version = '2.7.1'
|
79
79
|
if RUBY_VERSION != current_version
|
80
80
|
warn_syntax_deviation 'parser/ruby27', current_version
|
81
81
|
end
|
@@ -83,6 +83,15 @@ module Parser
|
|
83
83
|
require 'parser/ruby27'
|
84
84
|
CurrentRuby = Ruby27
|
85
85
|
|
86
|
+
when /^2\.8\./
|
87
|
+
current_version = '2.8.0-dev'
|
88
|
+
if RUBY_VERSION != current_version
|
89
|
+
warn_syntax_deviation 'parser/ruby28', current_version
|
90
|
+
end
|
91
|
+
|
92
|
+
require 'parser/ruby28'
|
93
|
+
CurrentRuby = Ruby28
|
94
|
+
|
86
95
|
else # :nocov:
|
87
96
|
# Keep this in sync with released Ruby.
|
88
97
|
warn_syntax_deviation 'parser/ruby27', '2.7.x'
|
data/lib/parser/lexer.rl
CHANGED
@@ -2473,7 +2473,7 @@ class Parser::Lexer
|
|
2473
2473
|
|
2474
2474
|
# Here we use '\n' instead of w_newline to not modify @newline_s
|
2475
2475
|
# and eventually properly emit tNL
|
2476
|
-
(w_space_comment '\n')+
|
2476
|
+
(c_space* w_space_comment '\n')+
|
2477
2477
|
=> {
|
2478
2478
|
if @version < 27
|
2479
2479
|
# Ruby before 2.7 doesn't support comments before leading dot.
|