parser 2.6.0.0 → 2.7.0.0
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 +11 -11
- data/CHANGELOG.md +88 -0
- data/README.md +7 -0
- data/Rakefile +1 -0
- data/doc/AST_FORMAT.md +410 -3
- data/lib/parser/all.rb +1 -0
- data/lib/parser/ast/processor.rb +39 -1
- data/lib/parser/base.rb +23 -1
- data/lib/parser/builders/default.rb +312 -15
- data/lib/parser/context.rb +12 -0
- data/lib/parser/current.rb +15 -6
- data/lib/parser/current_arg_stack.rb +43 -0
- data/lib/parser/lexer/dedenter.rb +48 -49
- data/lib/parser/lexer.rb +11934 -11278
- data/lib/parser/lexer.rl +207 -58
- data/lib/parser/macruby.rb +1509 -1507
- data/lib/parser/macruby.y +1 -1
- data/lib/parser/max_numparam_stack.rb +48 -0
- data/lib/parser/messages.rb +55 -44
- data/lib/parser/meta.rb +9 -1
- data/lib/parser/ruby18.rb +1255 -1248
- data/lib/parser/ruby18.y +1 -1
- data/lib/parser/ruby19.rb +1645 -1638
- data/lib/parser/ruby19.y +1 -1
- data/lib/parser/ruby20.rb +1766 -1767
- data/lib/parser/ruby20.y +1 -1
- data/lib/parser/ruby21.rb +1654 -1656
- data/lib/parser/ruby21.y +1 -1
- data/lib/parser/ruby22.rb +1772 -1767
- data/lib/parser/ruby22.y +1 -1
- data/lib/parser/ruby23.rb +1088 -1092
- data/lib/parser/ruby23.y +1 -1
- data/lib/parser/ruby24.rb +1837 -1843
- data/lib/parser/ruby24.y +1 -1
- data/lib/parser/ruby25.rb +1750 -1755
- data/lib/parser/ruby25.y +2 -2
- data/lib/parser/ruby26.rb +1748 -1752
- data/lib/parser/ruby26.y +2 -2
- data/lib/parser/ruby27.rb +7749 -0
- data/lib/parser/ruby27.y +2923 -0
- data/lib/parser/rubymotion.rb +1492 -1497
- data/lib/parser/rubymotion.y +1 -1
- data/lib/parser/runner/ruby_parse.rb +2 -2
- data/lib/parser/runner.rb +5 -0
- data/lib/parser/source/tree_rewriter.rb +2 -2
- data/lib/parser/static_environment.rb +10 -0
- data/lib/parser/tree_rewriter.rb +2 -1
- data/lib/parser/variables_stack.rb +32 -0
- data/lib/parser/version.rb +1 -1
- data/lib/parser.rb +3 -0
- data/parser.gemspec +3 -2
- data/test/helper.rb +8 -0
- data/test/parse_helper.rb +2 -1
- data/test/test_current.rb +2 -0
- data/test/test_lexer.rb +72 -7
- data/test/test_parser.rb +2218 -8
- data/test/test_runner_parse.rb +35 -0
- metadata +20 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9c513c025d3466aaa344468699cb2b737a4d85ba3275b8702fe8cd7194e0fe74
|
|
4
|
+
data.tar.gz: 26b706425f418a7dbdb4063f7cd082e22633deb035c4444ca01dfe28c1a5c3d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9743ae26ad02e463e5592cd53f0f6e2ab95ced23f687468fbd58df249971be181b7b69edafc69ca65e7a98048205940c0108aff96ceb7984c9220439e9e6d7f
|
|
7
|
+
data.tar.gz: 17afaecd6b1d3af320d62b570ccce3ebfb109ed845fc78059fd69a8561fe90630d01470f401370913a7ffc5e298f862580f7c302617432059d1afb8dd6ea13bc
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -11,14 +11,14 @@ matrix:
|
|
|
11
11
|
- name: 2.3.8 / Parser tests
|
|
12
12
|
rvm: 2.3.8
|
|
13
13
|
script: bundle exec rake test_cov
|
|
14
|
-
- name: 2.4.
|
|
15
|
-
rvm: 2.4.
|
|
14
|
+
- name: 2.4.9 / Parser tests
|
|
15
|
+
rvm: 2.4.9
|
|
16
16
|
script: bundle exec rake test_cov
|
|
17
|
-
- name: 2.5.
|
|
18
|
-
rvm: 2.5.
|
|
17
|
+
- name: 2.5.7 / Parser tests
|
|
18
|
+
rvm: 2.5.7
|
|
19
19
|
script: bundle exec rake test_cov
|
|
20
|
-
- name: 2.6.
|
|
21
|
-
rvm: 2.6.
|
|
20
|
+
- name: 2.6.5 / Parser tests
|
|
21
|
+
rvm: 2.6.5
|
|
22
22
|
script: bundle exec rake test_cov
|
|
23
23
|
- name: ruby-head / Parser tests
|
|
24
24
|
rvm: ruby-head
|
|
@@ -29,17 +29,17 @@ matrix:
|
|
|
29
29
|
- name: rbx-2 / Parser tests
|
|
30
30
|
rvm: rbx-2
|
|
31
31
|
script: bundle exec rake test_cov
|
|
32
|
-
- name: 2.5.
|
|
33
|
-
rvm: 2.5.
|
|
32
|
+
- name: 2.5.7 / Rubocop tests
|
|
33
|
+
rvm: 2.5.7
|
|
34
34
|
script: ./ci/run_rubocop_specs
|
|
35
|
-
- name: 2.6.
|
|
36
|
-
rvm: 2.6.
|
|
35
|
+
- name: 2.6.5 / Rubocop tests
|
|
36
|
+
rvm: 2.6.5
|
|
37
37
|
script: ./ci/run_rubocop_specs
|
|
38
38
|
allow_failures:
|
|
39
39
|
- rvm: ruby-head
|
|
40
40
|
- rvm: rbx-2
|
|
41
41
|
- script: ./ci/run_rubocop_specs
|
|
42
42
|
before_install:
|
|
43
|
-
- gem install bundler
|
|
43
|
+
- gem install bundler -v '< 2'
|
|
44
44
|
- bundle --version
|
|
45
45
|
- gem --version
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,94 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
Not released (2019-12-26)
|
|
5
|
+
-------------------------
|
|
6
|
+
|
|
7
|
+
API modifications:
|
|
8
|
+
* README.md: documented compatibility issue with EOF chars after… (#637) (Ilya Bylich)
|
|
9
|
+
* ruby27.y: refactor logic around 'circular argument reference'(#628) (Ilya Bylich)
|
|
10
|
+
|
|
11
|
+
Features implemented:
|
|
12
|
+
* ruby27.y: added pattern matching (#574) (Ilya Bylich)
|
|
13
|
+
* lexer.rl: parse embedded ivars/cvars starting with digit as str (#639) (Ilya Bylich)
|
|
14
|
+
* lexer.rl: warn on `...` at EOL. (#636) (Ilya Bylich)
|
|
15
|
+
* ruby27.y: removed opt_block_args_tail: tOROP rule. (#635) (Ilya Bylich)
|
|
16
|
+
* ruby27.y: reverted method reference operator (added in #634) (Ilya Bylich)
|
|
17
|
+
* ruby27.y: treat numparams as locals outside numblock. (#633) (Ilya Bylich)
|
|
18
|
+
|
|
19
|
+
Bugs fixed:
|
|
20
|
+
* dedenter.rb: fixed over-dedenting of squiggly heredocs (#641) (Ilya Bylich)
|
|
21
|
+
* ruby27.y: added "arguments forwarding" (#625) (Ilya Bylich)
|
|
22
|
+
* ruby27.y: reject circular argument reference. (#622) (Ilya Bylich)
|
|
23
|
+
* ruby27.y: changed prefix of numparams to "_" (#620) (Ilya Bylich)
|
|
24
|
+
|
|
25
|
+
v2.6.5.0 (2019-10-03)
|
|
26
|
+
---------------------
|
|
27
|
+
|
|
28
|
+
API modifications:
|
|
29
|
+
* Bump ruby versions to 2.4.9, 2.5.7 and 2.6.5. (#619) (Ilya Bylich)
|
|
30
|
+
|
|
31
|
+
Features implemented:
|
|
32
|
+
* lexer.rl: changed max numparam to `@9` (#617) (Ilya Bylich)
|
|
33
|
+
* lexer.rl: support comments before leading dot in 27 mode. (#613) (Ilya Bylich)
|
|
34
|
+
|
|
35
|
+
Bugs fixed:
|
|
36
|
+
* lexer.rl: emit tMETHREF as tDOT+tCOLON for rubies \< 27. (#614) (Ilya Bylich)
|
|
37
|
+
|
|
38
|
+
v2.6.4.1 (2019-09-12)
|
|
39
|
+
---------------------
|
|
40
|
+
|
|
41
|
+
Bugs fixed:
|
|
42
|
+
* lexer.rl: fix parsing of 'm a + b do end' (#605) (Ilya Bylich)
|
|
43
|
+
|
|
44
|
+
v2.6.4.0 (2019-08-30)
|
|
45
|
+
---------------------
|
|
46
|
+
|
|
47
|
+
API modifications:
|
|
48
|
+
* Added specs for heredocs with mixed encoding. (#581) (Ilya Bylich)
|
|
49
|
+
|
|
50
|
+
Features implemented:
|
|
51
|
+
* ruby27.y: Revert "pipeline operator" (#601) (Koichi ITO)
|
|
52
|
+
* ruby27.y: Fix parsing of mutiple assignment with rescue modifier (#600) (Koichi ITO)
|
|
53
|
+
* ruby27.y: hoisted out f_rest_marg. (#594) (Ilya Bylich)
|
|
54
|
+
* ruby27.y: added pipeline operator. (#592) (Ilya Bylich)
|
|
55
|
+
* ruby27.y: reject safe navigator in LHS of mass-assignment. (#586) (Ilya Bylich)
|
|
56
|
+
* lexer.rl: reject whitespaces in meta and control chars. (#585) (Ilya Bylich)
|
|
57
|
+
* lexer.rl: Reject numparams as symbol literals. (#582) (Ilya Bylich)
|
|
58
|
+
* ruby27.y: Added numbered parameters support. (#565) (Ilya Bylich)
|
|
59
|
+
* lexer.rl: Reject \n and \r in heredoc identifiers starting from 2.7. (#575) (Ilya Bylich)
|
|
60
|
+
|
|
61
|
+
Bugs fixed:
|
|
62
|
+
* ruby-parse: print empty string when --emit-json and empty input are given. (#590) (Ilya Bylich)
|
|
63
|
+
* AST_FORMAT: fixed documentation of the string with interpolation. (#589) (Ilya Bylich)
|
|
64
|
+
* builder.rb, processor.rb: Changed format of the procarg0 node. (#587) (Ilya Bylich)
|
|
65
|
+
|
|
66
|
+
v2.6.3.0 (2019-04-28)
|
|
67
|
+
---------------------
|
|
68
|
+
|
|
69
|
+
Features implemented:
|
|
70
|
+
* ruby27.y: Added beginless ranges support. (#570) (Ilya Bylich)
|
|
71
|
+
|
|
72
|
+
v2.6.2.1 (2019-04-05)
|
|
73
|
+
---------------------
|
|
74
|
+
|
|
75
|
+
API modifications:
|
|
76
|
+
* Bump 2.4 branch to 2.4.6. (#569) (Ilya Bylich)
|
|
77
|
+
* Lexer should know about current parsing context. (#566) (Ilya Bylich)
|
|
78
|
+
|
|
79
|
+
v2.6.2.0 (2019-03-21)
|
|
80
|
+
---------------------
|
|
81
|
+
|
|
82
|
+
API modifications:
|
|
83
|
+
* Bump ruby versions to 2.5.5 and 2.6.2. (#563) (Ilya Bylich)
|
|
84
|
+
* Bump Ruby version to 2.6.1. (#554) (Ilya Bylich)
|
|
85
|
+
|
|
86
|
+
Features implemented:
|
|
87
|
+
* ruby27.y: dsym should be treated as string. (#560) (Ilya Bylich)
|
|
88
|
+
* ruby27.y: Refactored symbol rules. (#557) (Ilya Bylich)
|
|
89
|
+
* ruby27.y: Added method reference operator. (#556) (Ilya Bylich)
|
|
90
|
+
* ruby27.y: branch parser. (#546) (Ilya Bylich)
|
|
91
|
+
|
|
4
92
|
v2.6.0.0 (2019-01-16)
|
|
5
93
|
---------------------
|
|
6
94
|
|
data/README.md
CHANGED
|
@@ -269,6 +269,13 @@ follows 2.1 behavior.
|
|
|
269
269
|
|
|
270
270
|
No known code is affected by this issue.
|
|
271
271
|
|
|
272
|
+
### EOF characters after embedded documents before 2.7
|
|
273
|
+
|
|
274
|
+
Code like `"=begin\n""=end\0"` is invalid for all versions of Ruby before 2.7. Ruby 2.7 and later parses it
|
|
275
|
+
normally. Parser follows 2.7 behavior.
|
|
276
|
+
|
|
277
|
+
It is unknown whether any gems are affected by this issue.
|
|
278
|
+
|
|
272
279
|
## Contributors
|
|
273
280
|
|
|
274
281
|
* [whitequark][]
|
data/Rakefile
CHANGED
data/doc/AST_FORMAT.md
CHANGED
|
@@ -102,10 +102,13 @@ Format:
|
|
|
102
102
|
Format:
|
|
103
103
|
|
|
104
104
|
~~~
|
|
105
|
-
(dstr (str "foo") (lvar bar) (str "baz"))
|
|
105
|
+
(dstr (str "foo") (begin (lvar bar)) (str "baz"))
|
|
106
106
|
'"foo#{bar}baz"'
|
|
107
107
|
^ begin ^ end
|
|
108
108
|
~~~~~~~~~~~~~~ expression
|
|
109
|
+
^^ begin (begin)
|
|
110
|
+
^ end (begin)
|
|
111
|
+
^^^^^^ expression (begin)
|
|
109
112
|
~~~
|
|
110
113
|
|
|
111
114
|
#### Here document
|
|
@@ -339,6 +342,22 @@ Format:
|
|
|
339
342
|
~~~~ expression
|
|
340
343
|
~~~
|
|
341
344
|
|
|
345
|
+
### Beginless (2.7)
|
|
346
|
+
|
|
347
|
+
Format:
|
|
348
|
+
|
|
349
|
+
~~~
|
|
350
|
+
(irange nil (int 1))
|
|
351
|
+
"..1"
|
|
352
|
+
~~ operator
|
|
353
|
+
~~~ expression
|
|
354
|
+
|
|
355
|
+
(erange nil (int 1))
|
|
356
|
+
"...1"
|
|
357
|
+
~~~ operator
|
|
358
|
+
~~~~ expression
|
|
359
|
+
~~~
|
|
360
|
+
|
|
342
361
|
## Access
|
|
343
362
|
|
|
344
363
|
### Self
|
|
@@ -905,10 +924,15 @@ the sole argument (e.g. `|foo,|`).
|
|
|
905
924
|
Format:
|
|
906
925
|
|
|
907
926
|
~~~
|
|
908
|
-
(procarg0 :foo)
|
|
927
|
+
(procarg0 (arg :foo))
|
|
909
928
|
"|foo|"
|
|
910
929
|
~~~ expression
|
|
911
|
-
|
|
930
|
+
|
|
931
|
+
(procarg0 (arg :foo) (arg :bar))
|
|
932
|
+
"|(foo, bar)|"
|
|
933
|
+
~ begin
|
|
934
|
+
~ end
|
|
935
|
+
~~~~~~~~~~ expression
|
|
912
936
|
~~~
|
|
913
937
|
|
|
914
938
|
### Expression arguments
|
|
@@ -996,6 +1020,17 @@ Format:
|
|
|
996
1020
|
~~ expression
|
|
997
1021
|
~~~
|
|
998
1022
|
|
|
1023
|
+
### Keyword nil argument
|
|
1024
|
+
|
|
1025
|
+
Format:
|
|
1026
|
+
|
|
1027
|
+
~~~
|
|
1028
|
+
(kwnilarg)
|
|
1029
|
+
"**nil"
|
|
1030
|
+
~~~ name
|
|
1031
|
+
~~~~~ expression
|
|
1032
|
+
~~~
|
|
1033
|
+
|
|
999
1034
|
### Objective-C arguments
|
|
1000
1035
|
|
|
1001
1036
|
MacRuby includes a few more syntactic "arguments" whose name becomes
|
|
@@ -1055,6 +1090,59 @@ However, the following code results in a parse error:
|
|
|
1055
1090
|
def f(*a: b); end
|
|
1056
1091
|
~~~
|
|
1057
1092
|
|
|
1093
|
+
## Numbered parameters
|
|
1094
|
+
|
|
1095
|
+
### Block with numbered parameters
|
|
1096
|
+
|
|
1097
|
+
Ruby 2.7 introduced a feature called "numbered parameters".
|
|
1098
|
+
Numbered and ordinal parameters are mutually exclusive, so if the block
|
|
1099
|
+
has only numbered parameters it also has a different AST node.
|
|
1100
|
+
|
|
1101
|
+
Note that the second child represents a total number of numbered parameters.
|
|
1102
|
+
|
|
1103
|
+
Format:
|
|
1104
|
+
|
|
1105
|
+
~~~
|
|
1106
|
+
s(:numblock,
|
|
1107
|
+
s(:send, nil, :proc), 3,
|
|
1108
|
+
s(:send,
|
|
1109
|
+
s(:lvar, :_1), :+,
|
|
1110
|
+
s(:lvar, :_3)))
|
|
1111
|
+
"proc { _1 + _3 }"
|
|
1112
|
+
~ begin ~ end
|
|
1113
|
+
~~~~~~~~~~~~~~~~ expression
|
|
1114
|
+
~~~
|
|
1115
|
+
|
|
1116
|
+
## Forward arguments
|
|
1117
|
+
|
|
1118
|
+
### Method definition accepting forwarding arguments
|
|
1119
|
+
|
|
1120
|
+
Ruby 2.7 introduced a feature called "arguments forwarding".
|
|
1121
|
+
When a method takes any arguments for forwarding them in the future
|
|
1122
|
+
the whole `args` node gets replaced with `forward-args` node.
|
|
1123
|
+
|
|
1124
|
+
Format:
|
|
1125
|
+
|
|
1126
|
+
~~~
|
|
1127
|
+
(def :foo
|
|
1128
|
+
(forward-args) nil)
|
|
1129
|
+
"def foo(...); end"
|
|
1130
|
+
~ end
|
|
1131
|
+
~ begin
|
|
1132
|
+
~~~~~ expression
|
|
1133
|
+
~~~
|
|
1134
|
+
|
|
1135
|
+
### Method call taking arguments of the currently forwarding method
|
|
1136
|
+
|
|
1137
|
+
Format:
|
|
1138
|
+
|
|
1139
|
+
~~~
|
|
1140
|
+
(send nil :foo
|
|
1141
|
+
(forwarded-args))
|
|
1142
|
+
"foo(...)"
|
|
1143
|
+
~~~ expression
|
|
1144
|
+
~~~
|
|
1145
|
+
|
|
1058
1146
|
## Send
|
|
1059
1147
|
|
|
1060
1148
|
### To self
|
|
@@ -1733,3 +1821,322 @@ Format:
|
|
|
1733
1821
|
"__ENCODING__"
|
|
1734
1822
|
~~~~~~~~~~~~ expression
|
|
1735
1823
|
~~~
|
|
1824
|
+
|
|
1825
|
+
## Pattern matching
|
|
1826
|
+
|
|
1827
|
+
### Using `in` modifier
|
|
1828
|
+
|
|
1829
|
+
Format:
|
|
1830
|
+
|
|
1831
|
+
~~~
|
|
1832
|
+
(in-match
|
|
1833
|
+
(int 1)
|
|
1834
|
+
(match-var :a))
|
|
1835
|
+
"1 in a"
|
|
1836
|
+
~~ operator
|
|
1837
|
+
~~~~~~ expression
|
|
1838
|
+
~~~
|
|
1839
|
+
|
|
1840
|
+
### Case with pattern matching
|
|
1841
|
+
|
|
1842
|
+
#### Without else
|
|
1843
|
+
|
|
1844
|
+
Format:
|
|
1845
|
+
|
|
1846
|
+
~~~
|
|
1847
|
+
(case-match
|
|
1848
|
+
(str "str")
|
|
1849
|
+
(in-pattern
|
|
1850
|
+
(match-var :foo)
|
|
1851
|
+
(lvar :bar)) nil)
|
|
1852
|
+
"case "str"; in foo; bar; end"
|
|
1853
|
+
~~~~ keyword ~~~ end
|
|
1854
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
|
|
1855
|
+
~~~
|
|
1856
|
+
|
|
1857
|
+
#### With else
|
|
1858
|
+
|
|
1859
|
+
Format:
|
|
1860
|
+
|
|
1861
|
+
~~~
|
|
1862
|
+
(case-match,
|
|
1863
|
+
(str "str")
|
|
1864
|
+
(in-pattern
|
|
1865
|
+
(match-var :foo)
|
|
1866
|
+
(lvar :bar))
|
|
1867
|
+
(lvar :baz))
|
|
1868
|
+
"case "str"; in foo; bar; else; baz; end"
|
|
1869
|
+
~~~~ keyword ~~~~ else ~~~ end
|
|
1870
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
|
|
1871
|
+
~~~
|
|
1872
|
+
|
|
1873
|
+
### In clause
|
|
1874
|
+
|
|
1875
|
+
Format:
|
|
1876
|
+
|
|
1877
|
+
~~~
|
|
1878
|
+
(in-pattern
|
|
1879
|
+
(match-var :foo)
|
|
1880
|
+
(lvar :bar))
|
|
1881
|
+
"in foo then bar"
|
|
1882
|
+
~~ keyword
|
|
1883
|
+
~~~~ begin
|
|
1884
|
+
~~~~~~~~~~~~~~~ expression
|
|
1885
|
+
~~~
|
|
1886
|
+
|
|
1887
|
+
### If guard
|
|
1888
|
+
|
|
1889
|
+
This guard runs after matching, so it's not an `if` modifier.
|
|
1890
|
+
|
|
1891
|
+
Format:
|
|
1892
|
+
|
|
1893
|
+
~~~
|
|
1894
|
+
(in-pattern
|
|
1895
|
+
(match-var :foo)
|
|
1896
|
+
(if-guard
|
|
1897
|
+
(lvar :bar)) nil)
|
|
1898
|
+
"in foo if bar"
|
|
1899
|
+
~~ keyword
|
|
1900
|
+
~~~~~~ expression
|
|
1901
|
+
~~~
|
|
1902
|
+
|
|
1903
|
+
### Unless guard
|
|
1904
|
+
|
|
1905
|
+
This guard runs after matching, so it's not an `unless` modifier.
|
|
1906
|
+
|
|
1907
|
+
Format:
|
|
1908
|
+
|
|
1909
|
+
~~~
|
|
1910
|
+
(in-pattern
|
|
1911
|
+
(match-var :foo)
|
|
1912
|
+
(unless-guard
|
|
1913
|
+
(lvar :bar)) nil)
|
|
1914
|
+
"in foo unless bar"
|
|
1915
|
+
~~~~~~ keyword
|
|
1916
|
+
~~~~~~~~~~ expression
|
|
1917
|
+
~~~
|
|
1918
|
+
|
|
1919
|
+
### Match variable
|
|
1920
|
+
|
|
1921
|
+
Format:
|
|
1922
|
+
|
|
1923
|
+
~~~
|
|
1924
|
+
(match-var :foo)
|
|
1925
|
+
"in foo"
|
|
1926
|
+
~~~ name
|
|
1927
|
+
~~~ expression
|
|
1928
|
+
~~~
|
|
1929
|
+
|
|
1930
|
+
### Match rest
|
|
1931
|
+
|
|
1932
|
+
#### With name
|
|
1933
|
+
|
|
1934
|
+
Format:
|
|
1935
|
+
|
|
1936
|
+
~~~
|
|
1937
|
+
(match-rest
|
|
1938
|
+
(match-var :foo))
|
|
1939
|
+
"in *foo"
|
|
1940
|
+
~ operator
|
|
1941
|
+
~~~~ expression
|
|
1942
|
+
~~~
|
|
1943
|
+
|
|
1944
|
+
#### Without name
|
|
1945
|
+
|
|
1946
|
+
Format:
|
|
1947
|
+
|
|
1948
|
+
~~~
|
|
1949
|
+
(match-rest)
|
|
1950
|
+
"in *"
|
|
1951
|
+
~ operator
|
|
1952
|
+
~ expression
|
|
1953
|
+
~~~
|
|
1954
|
+
|
|
1955
|
+
### Pin operator
|
|
1956
|
+
|
|
1957
|
+
Format:
|
|
1958
|
+
|
|
1959
|
+
~~~
|
|
1960
|
+
(pin
|
|
1961
|
+
(lvar :foo))
|
|
1962
|
+
"in ^foo"
|
|
1963
|
+
~ selector
|
|
1964
|
+
~~~~ expression
|
|
1965
|
+
~~~
|
|
1966
|
+
|
|
1967
|
+
### Match alternative
|
|
1968
|
+
|
|
1969
|
+
Format:
|
|
1970
|
+
|
|
1971
|
+
~~~
|
|
1972
|
+
(match-alt
|
|
1973
|
+
(pin
|
|
1974
|
+
(lvar :foo))
|
|
1975
|
+
(int 1))
|
|
1976
|
+
"in ^foo | 1"
|
|
1977
|
+
~ operator
|
|
1978
|
+
~~~~~~~~ expression
|
|
1979
|
+
~~~
|
|
1980
|
+
|
|
1981
|
+
### Match with alias
|
|
1982
|
+
|
|
1983
|
+
Format:
|
|
1984
|
+
|
|
1985
|
+
~~~
|
|
1986
|
+
(match-as
|
|
1987
|
+
(int 1)
|
|
1988
|
+
(match-var :foo))
|
|
1989
|
+
"in 1 => foo"
|
|
1990
|
+
~~ operator
|
|
1991
|
+
~~~~~~~~ expression
|
|
1992
|
+
~~~
|
|
1993
|
+
|
|
1994
|
+
### Match using array pattern
|
|
1995
|
+
|
|
1996
|
+
#### Explicit
|
|
1997
|
+
|
|
1998
|
+
Format:
|
|
1999
|
+
|
|
2000
|
+
~~~
|
|
2001
|
+
(array-pattern
|
|
2002
|
+
(pin
|
|
2003
|
+
(lvar :foo))
|
|
2004
|
+
(match-var :bar))
|
|
2005
|
+
"in [^foo, bar]"
|
|
2006
|
+
~ begin ~ end
|
|
2007
|
+
~~~~~~~~~~~ expression
|
|
2008
|
+
~~~
|
|
2009
|
+
|
|
2010
|
+
#### Explicit with tail
|
|
2011
|
+
|
|
2012
|
+
Adding a trailing comma in the end works as `, *`
|
|
2013
|
+
|
|
2014
|
+
Format:
|
|
2015
|
+
|
|
2016
|
+
~~~
|
|
2017
|
+
(array-pattern-with-tail
|
|
2018
|
+
(pin
|
|
2019
|
+
(lvar :foo))
|
|
2020
|
+
(match-var :bar))
|
|
2021
|
+
"in [^foo, bar,]"
|
|
2022
|
+
~ begin ~ end
|
|
2023
|
+
~~~~~~~~~~~~ expression
|
|
2024
|
+
~~~
|
|
2025
|
+
|
|
2026
|
+
#### Implicit
|
|
2027
|
+
|
|
2028
|
+
Format:
|
|
2029
|
+
|
|
2030
|
+
~~~
|
|
2031
|
+
(array-pattern
|
|
2032
|
+
(pin
|
|
2033
|
+
(lvar :foo))
|
|
2034
|
+
(match-var :bar))
|
|
2035
|
+
"in ^foo, bar"
|
|
2036
|
+
~~~~~~~~~ expression
|
|
2037
|
+
~~~
|
|
2038
|
+
|
|
2039
|
+
#### Implicit with tail
|
|
2040
|
+
|
|
2041
|
+
Format:
|
|
2042
|
+
|
|
2043
|
+
Adding a trailing comma in the end works as `, *`,
|
|
2044
|
+
so a single item match with comma gets interpreted as an array.
|
|
2045
|
+
|
|
2046
|
+
~~~
|
|
2047
|
+
(array-pattern-with-tail
|
|
2048
|
+
(match-var :foo))
|
|
2049
|
+
"in foo,"
|
|
2050
|
+
~~~ expression
|
|
2051
|
+
~~~
|
|
2052
|
+
|
|
2053
|
+
### Matching using hash pattern
|
|
2054
|
+
|
|
2055
|
+
#### Explicit
|
|
2056
|
+
|
|
2057
|
+
Format:
|
|
2058
|
+
|
|
2059
|
+
~~~
|
|
2060
|
+
(hash-pattern
|
|
2061
|
+
(pair
|
|
2062
|
+
(sym :a)
|
|
2063
|
+
(int 10)))
|
|
2064
|
+
"in { a: 10 }"
|
|
2065
|
+
~ begin ~ end
|
|
2066
|
+
~~~~~~~~~ expression
|
|
2067
|
+
~~~
|
|
2068
|
+
|
|
2069
|
+
#### Implicit
|
|
2070
|
+
|
|
2071
|
+
Format:
|
|
2072
|
+
|
|
2073
|
+
~~~
|
|
2074
|
+
(hash-pattern
|
|
2075
|
+
(pair
|
|
2076
|
+
(sym :a)
|
|
2077
|
+
(int 10)))
|
|
2078
|
+
"in a: 10"
|
|
2079
|
+
~~~~~ expression
|
|
2080
|
+
~~~
|
|
2081
|
+
|
|
2082
|
+
#### Assignment using hash pattern
|
|
2083
|
+
|
|
2084
|
+
Format:
|
|
2085
|
+
|
|
2086
|
+
~~~
|
|
2087
|
+
(hash-pattern
|
|
2088
|
+
(match-var :a))
|
|
2089
|
+
"in a:"
|
|
2090
|
+
~ name (match-var)
|
|
2091
|
+
~~ expression (match-var)
|
|
2092
|
+
~~~
|
|
2093
|
+
|
|
2094
|
+
#### Nil hash pattern
|
|
2095
|
+
|
|
2096
|
+
Format:
|
|
2097
|
+
~~~
|
|
2098
|
+
(hash-pattern
|
|
2099
|
+
(match-nil-pattern))
|
|
2100
|
+
"in **nil"
|
|
2101
|
+
~~~~~ expression (match-nil-pattern)
|
|
2102
|
+
~~~ name (match-nil-pattern)
|
|
2103
|
+
~~~
|
|
2104
|
+
|
|
2105
|
+
### Matching using const pattern
|
|
2106
|
+
|
|
2107
|
+
#### With array pattern
|
|
2108
|
+
|
|
2109
|
+
Format:
|
|
2110
|
+
|
|
2111
|
+
~~~
|
|
2112
|
+
(const-pattern
|
|
2113
|
+
(const nil :X)
|
|
2114
|
+
(array-pattern
|
|
2115
|
+
(pin
|
|
2116
|
+
(lvar :foo))
|
|
2117
|
+
(match-var :bar)))
|
|
2118
|
+
"in X[^foo bar]"
|
|
2119
|
+
~ begin (const-pattern)
|
|
2120
|
+
~ end (const-pattern)
|
|
2121
|
+
~~~~~~~~~~~ expression (const-pattern)
|
|
2122
|
+
~ name (const-pattern.const)
|
|
2123
|
+
~ expression (const-pattern.const)
|
|
2124
|
+
~~~
|
|
2125
|
+
|
|
2126
|
+
#### With hash pattern
|
|
2127
|
+
|
|
2128
|
+
Format:
|
|
2129
|
+
|
|
2130
|
+
~~~
|
|
2131
|
+
(const-pattern
|
|
2132
|
+
(const nil :X)
|
|
2133
|
+
(hash-pattern
|
|
2134
|
+
(match-var :foo)
|
|
2135
|
+
(match-var :bar)))
|
|
2136
|
+
"in X[foo:, bar:]"
|
|
2137
|
+
~ begin (const-pattern)
|
|
2138
|
+
~ end (const-pattern)
|
|
2139
|
+
~~~~~~~~~~~~ expression (const-pattern)
|
|
2140
|
+
~ name (const-pattern.const)
|
|
2141
|
+
~ expression (const-pattern.const)
|
|
2142
|
+
~~~
|
data/lib/parser/all.rb
CHANGED
data/lib/parser/ast/processor.rb
CHANGED
|
@@ -124,7 +124,22 @@ module Parser
|
|
|
124
124
|
alias on_kwarg process_argument_node
|
|
125
125
|
alias on_kwoptarg process_argument_node
|
|
126
126
|
alias on_kwrestarg process_argument_node
|
|
127
|
-
|
|
127
|
+
|
|
128
|
+
def on_procarg0(node)
|
|
129
|
+
if node.children[0].is_a?(Symbol)
|
|
130
|
+
# This branch gets executed when the builder
|
|
131
|
+
# is not configured to emit and 'arg' inside 'procarg0', i.e. when
|
|
132
|
+
# Parser::Builders::Default.emit_arg_inside_procarg0
|
|
133
|
+
# is set to false.
|
|
134
|
+
#
|
|
135
|
+
# If this flag is set to true this branch is unreachable.
|
|
136
|
+
# s(:procarg0, :a)
|
|
137
|
+
on_argument(node)
|
|
138
|
+
else
|
|
139
|
+
# s(:procarg0, s(:arg, :a), s(:arg, :b))
|
|
140
|
+
process_regular_node(node)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
128
143
|
|
|
129
144
|
alias on_arg_expr process_regular_node
|
|
130
145
|
alias on_restarg_expr process_regular_node
|
|
@@ -173,6 +188,14 @@ module Parser
|
|
|
173
188
|
alias on_block process_regular_node
|
|
174
189
|
alias on_lambda process_regular_node
|
|
175
190
|
|
|
191
|
+
def on_numblock(node)
|
|
192
|
+
method_call, max_numparam, body = *node
|
|
193
|
+
|
|
194
|
+
node.updated(nil, [
|
|
195
|
+
process(method_call), max_numparam, process(body)
|
|
196
|
+
])
|
|
197
|
+
end
|
|
198
|
+
|
|
176
199
|
alias on_while process_regular_node
|
|
177
200
|
alias on_while_post process_regular_node
|
|
178
201
|
alias on_until process_regular_node
|
|
@@ -213,6 +236,21 @@ module Parser
|
|
|
213
236
|
alias on_preexe process_regular_node
|
|
214
237
|
alias on_postexe process_regular_node
|
|
215
238
|
|
|
239
|
+
alias on_case_match process_regular_node
|
|
240
|
+
alias on_in_match process_regular_node
|
|
241
|
+
alias on_in_pattern process_regular_node
|
|
242
|
+
alias on_if_guard process_regular_node
|
|
243
|
+
alias on_unless_guard process_regular_node
|
|
244
|
+
alias on_match_var process_variable_node
|
|
245
|
+
alias on_match_rest process_regular_node
|
|
246
|
+
alias on_pin process_regular_node
|
|
247
|
+
alias on_match_alt process_regular_node
|
|
248
|
+
alias on_match_as process_regular_node
|
|
249
|
+
alias on_array_pattern process_regular_node
|
|
250
|
+
alias on_array_pattern_with_tail process_regular_node
|
|
251
|
+
alias on_hash_pattern process_regular_node
|
|
252
|
+
alias on_const_pattern process_regular_node
|
|
253
|
+
|
|
216
254
|
# @private
|
|
217
255
|
def process_variable_node(node)
|
|
218
256
|
warn 'Parser::AST::Processor#process_variable_node is deprecated as a' \
|