parser 1.1.0 → 1.2.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 +7 -7
- data/.gitignore +0 -1
- data/README.md +4 -2
- data/bin/{parse → ruby-parse} +2 -2
- data/bin/ruby-rewrite +6 -0
- data/{AST_FORMAT.md → doc/AST_FORMAT.md} +45 -29
- data/doc/CUSTOMIZATION.md +37 -0
- data/doc/INTERNALS.md +21 -0
- data/lib/parser.rb +14 -3
- data/lib/parser/ast/node.rb +6 -0
- data/lib/parser/ast/processor.rb +216 -0
- data/lib/parser/builders/default.rb +613 -215
- data/lib/parser/compatibility/slop.rb +12 -0
- data/lib/parser/lexer.rl +30 -10
- data/lib/parser/lexer/explanation.rb +1 -1
- data/lib/parser/lexer/literal.rb +5 -6
- data/lib/parser/ruby18.y +31 -24
- data/lib/parser/ruby19.y +26 -19
- data/lib/parser/ruby20.y +27 -20
- data/lib/parser/ruby21.y +27 -20
- data/lib/parser/runner.rb +198 -0
- data/lib/parser/runner/ruby_parse.rb +87 -0
- data/lib/parser/runner/ruby_rewrite.rb +13 -0
- data/lib/parser/source/buffer.rb +1 -0
- data/lib/parser/source/map.rb +20 -0
- data/lib/parser/source/map/block.rb +16 -0
- data/lib/parser/source/map/collection.rb +16 -0
- data/lib/parser/source/map/condition.rb +19 -0
- data/lib/parser/source/map/constant.rb +27 -0
- data/lib/parser/source/map/definition.rb +21 -0
- data/lib/parser/source/map/for.rb +17 -0
- data/lib/parser/source/map/keyword.rb +18 -0
- data/lib/parser/source/map/rescue_body.rb +19 -0
- data/lib/parser/source/map/send.rb +29 -0
- data/lib/parser/source/map/ternary.rb +16 -0
- data/lib/parser/source/map/variable.rb +26 -0
- data/lib/parser/source/range.rb +25 -24
- data/lib/parser/version.rb +3 -0
- data/parser.gemspec +4 -2
- data/test/parse_helper.rb +13 -10
- data/test/test_lexer.rb +32 -11
- data/test/test_parse_helper.rb +1 -0
- data/test/test_parser.rb +176 -128
- data/test/test_source_range.rb +18 -6
- metadata +161 -91
- data/bin/benchmark +0 -47
- data/bin/explain-parse +0 -14
- data/lib/parser/source/map/variable_assignment.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16e6e6480aa89b565b60ceca67280519331836c0
|
4
|
+
data.tar.gz: 023823bcfbdf9f66858ed4de49d738cd94587891
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 999557fa55073dbd6077d224409d740b6ec68b9f0198906db4e5bd20276adfb3eab75aa9e2823369f5db8bcf474c7e37d709354c9bf8ffdd1200ffe7ddcdaa45
|
7
|
+
data.tar.gz: af1727c35cd4bdb1aea2735c9613c517ad363e9f3511a78d5287802b80fcfdbcf81bf6ce875d61e5f4e0fe8ff793adfde7692e882ac877519f51c7c53a177bf1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -41,10 +41,12 @@ p parser.parse(buffer)
|
|
41
41
|
# (send nil :bar)))
|
42
42
|
```
|
43
43
|
|
44
|
+
If you reuse the same parser object for multiple `#parse` runs, you need to `#reset` it.
|
45
|
+
|
44
46
|
## Features
|
45
47
|
|
46
|
-
* Precise source location reporting
|
47
|
-
* [Documented](AST_FORMAT.md) AST format which is convenient to work with.
|
48
|
+
* Precise source location reporting.
|
49
|
+
* [Documented](doc/AST_FORMAT.md) AST format which is convenient to work with.
|
48
50
|
* A simple interface and a powerful, tweakable one.
|
49
51
|
* Parses 1.8, 1.9, 2.0 and 2.1 (preliminary) syntax with backwards-compatible AST formats.
|
50
52
|
* Parsing error recovery.
|
data/bin/{parse → ruby-parse}
RENAMED
data/bin/ruby-rewrite
ADDED
@@ -296,6 +296,7 @@ Format:
|
|
296
296
|
(const (cbase) :Foo)
|
297
297
|
"::Foo"
|
298
298
|
~~~ name
|
299
|
+
~~ double_colon
|
299
300
|
~~~~~ expression
|
300
301
|
```
|
301
302
|
|
@@ -306,6 +307,7 @@ Format:
|
|
306
307
|
(const (lvar :a) :Foo)
|
307
308
|
"a::Foo"
|
308
309
|
~~~ name
|
310
|
+
~~ double_colon
|
309
311
|
~~~~~~ expression
|
310
312
|
```
|
311
313
|
|
@@ -590,7 +592,7 @@ s(:op_asgn1, s(:ivar, :@foo), s(:arglist, s(:int, 0)), :"||", s(:int, 1))
|
|
590
592
|
|
591
593
|
Format:
|
592
594
|
```
|
593
|
-
(module (const nil :Foo) (
|
595
|
+
(module (const nil :Foo) (nil))
|
594
596
|
"module Foo; end"
|
595
597
|
~~~~~~ keyword
|
596
598
|
~~~ end
|
@@ -600,25 +602,29 @@ Format:
|
|
600
602
|
|
601
603
|
Format:
|
602
604
|
```
|
603
|
-
(class (const nil :Foo) (const nil :Bar) (
|
605
|
+
(class (const nil :Foo) (const nil :Bar) (nil))
|
604
606
|
"class Foo < Bar; end"
|
605
607
|
~~~~~ keyword ~~~ end
|
608
|
+
~ operator
|
609
|
+
~~~~~~~~~~~~~~~~~~~~ expression
|
606
610
|
|
607
|
-
(class (const nil :Foo) nil (
|
611
|
+
(class (const nil :Foo) nil (nil))
|
608
612
|
"class Foo; end"
|
609
613
|
~~~~~ keyword
|
610
614
|
~~~ end
|
615
|
+
~~~~~~~~~~~~~~ expression
|
611
616
|
```
|
612
617
|
|
613
618
|
### Singleton class
|
614
619
|
|
615
620
|
Format:
|
616
621
|
```
|
617
|
-
(sclass (lvar :a) (
|
622
|
+
(sclass (lvar :a) (nil))
|
618
623
|
"class << a; end"
|
619
624
|
~~~~~ keyword
|
620
625
|
~~ operator
|
621
626
|
~~~ end
|
627
|
+
~~~~~~~~~~~~~~~ expression
|
622
628
|
```
|
623
629
|
|
624
630
|
## Method (un)definition
|
@@ -834,6 +840,8 @@ Format:
|
|
834
840
|
(send nil :foo (lvar :bar))
|
835
841
|
"foo(bar)"
|
836
842
|
~~~ selector
|
843
|
+
^ begin
|
844
|
+
^ end
|
837
845
|
~~~~~~~~ expression
|
838
846
|
```
|
839
847
|
|
@@ -844,6 +852,8 @@ Format:
|
|
844
852
|
(send (lvar :foo) :bar (int 1))
|
845
853
|
"foo.bar(1)"
|
846
854
|
~~~ selector
|
855
|
+
^ begin
|
856
|
+
^ end
|
847
857
|
~~~~~~~~~~ expression
|
848
858
|
|
849
859
|
(send (lvar :foo) :+ (int 1))
|
@@ -858,22 +868,18 @@ Format:
|
|
858
868
|
|
859
869
|
(send (lvar :foo) :a= (int 1))
|
860
870
|
"foo.a = 1"
|
861
|
-
|
871
|
+
~ selector
|
862
872
|
^ operator
|
863
873
|
~~~~~~~~~ expression
|
864
874
|
|
865
875
|
(send (lvar :foo) :[] (int 1))
|
866
876
|
"foo[i]"
|
867
877
|
~~~ selector
|
868
|
-
^ begin
|
869
|
-
^ end
|
870
878
|
~~~~~~ expression
|
871
879
|
|
872
880
|
(send (lvar :bar) :[]= (int 1) (int 2) (lvar :baz))
|
873
881
|
"bar[1, 2] = baz"
|
874
|
-
|
875
|
-
^ begin
|
876
|
-
^ end
|
882
|
+
~~~~~~ selector
|
877
883
|
^ operator
|
878
884
|
~~~~~~~~~~~~~~~ expression
|
879
885
|
|
@@ -1066,9 +1072,10 @@ Format:
|
|
1066
1072
|
Format:
|
1067
1073
|
```
|
1068
1074
|
(when (regexp "foo" (regopt)) (begin (lvar :bar)))
|
1069
|
-
"when /foo
|
1075
|
+
"when /foo/ then bar"
|
1070
1076
|
~~~~ keyword
|
1071
|
-
|
1077
|
+
~~~~ begin
|
1078
|
+
~~~~~~~~~~~~~~~~~~~ expression
|
1072
1079
|
|
1073
1080
|
(when (int 1) (int 2) (send nil :meth))
|
1074
1081
|
"when 1, 2; meth"
|
@@ -1242,8 +1249,6 @@ Format:
|
|
1242
1249
|
(return (lvar :foo))
|
1243
1250
|
"return(foo)"
|
1244
1251
|
~~~~~~ keyword
|
1245
|
-
^ begin
|
1246
|
-
^ end
|
1247
1252
|
~~~~~~~~~~~ expression
|
1248
1253
|
```
|
1249
1254
|
|
@@ -1255,20 +1260,21 @@ Format:
|
|
1255
1260
|
```
|
1256
1261
|
(resbody (array (const nil :Exception) (const nil :A)) (lvasgn :bar) (int 1))
|
1257
1262
|
"rescue Exception, A => bar; 1"
|
1258
|
-
~~~~~~ keyword ~~
|
1263
|
+
~~~~~~ keyword ~~ assoc
|
1264
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
|
1259
1265
|
|
1260
1266
|
"rescue Exception, A => bar then 1"
|
1261
|
-
~~~~~~ keyword ~~
|
1267
|
+
~~~~~~ keyword ~~ assoc
|
1262
1268
|
~~~~ begin
|
1263
1269
|
|
1264
1270
|
(resbody (array (const nil :Exception)) (ivasgn :bar) (int 1))
|
1265
1271
|
"rescue Exception => @bar; 1"
|
1266
|
-
~~~~~~ keyword ~~
|
1272
|
+
~~~~~~ keyword ~~ assoc
|
1267
1273
|
|
1268
1274
|
(resbody nil (lvasgn :bar) (int 1))
|
1269
1275
|
"rescue => bar; 1"
|
1270
1276
|
~~~~~~ keyword
|
1271
|
-
~~
|
1277
|
+
~~ assoc
|
1272
1278
|
|
1273
1279
|
(resbody nil nil (int 1))
|
1274
1280
|
"rescue; 1"
|
@@ -1281,27 +1287,34 @@ Format:
|
|
1281
1287
|
|
1282
1288
|
Format:
|
1283
1289
|
```
|
1284
|
-
(
|
1290
|
+
(begin
|
1291
|
+
(rescue (send nil :foo) (resbody ...) (resbody ...) nil))
|
1285
1292
|
"begin; foo; rescue Exception; rescue; end"
|
1286
1293
|
~~~~~ begin ~~~ end
|
1294
|
+
~~~~~~~~~~~~~~~~~ expression (rescue.resbody/1)
|
1295
|
+
~~~~~~~ expression (rescue.resbody/2)
|
1296
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (rescue)
|
1287
1297
|
```
|
1288
1298
|
|
1289
1299
|
##### With else
|
1290
1300
|
|
1291
1301
|
Format:
|
1292
1302
|
```
|
1293
|
-
(
|
1303
|
+
(begin
|
1304
|
+
(rescue (send nil :foo) (resbody ...) (resbody ...) (true)))
|
1294
1305
|
"begin; foo; rescue Exception; rescue; else true end"
|
1295
|
-
~~~~~ begin ~~~~ else
|
1306
|
+
~~~~~ begin ~~~~ else (rescue)
|
1307
|
+
~~~ end
|
1296
1308
|
```
|
1297
1309
|
|
1298
1310
|
#### Ensure statement
|
1299
1311
|
|
1300
1312
|
Format:
|
1301
1313
|
```
|
1302
|
-
(
|
1314
|
+
(begin
|
1315
|
+
(ensure (send nil :foo) (send nil :bar))
|
1303
1316
|
"begin; foo; ensure; bar; end"
|
1304
|
-
~~~~~ begin ~~~~~~ keyword
|
1317
|
+
~~~~~ begin ~~~~~~ keyword (ensure)
|
1305
1318
|
~~~ end
|
1306
1319
|
```
|
1307
1320
|
|
@@ -1309,14 +1322,17 @@ Format:
|
|
1309
1322
|
|
1310
1323
|
Format:
|
1311
1324
|
```
|
1312
|
-
(
|
1325
|
+
(begin
|
1326
|
+
(ensure
|
1327
|
+
(rescue (send nil :foo) (resbody ...) (int 1))
|
1328
|
+
(send nil :bar))
|
1313
1329
|
"begin; foo; rescue; nil; else; 1; ensure; bar; end"
|
1314
|
-
~~~~~ begin
|
1315
|
-
|
1316
|
-
|
1330
|
+
~~~~~ begin
|
1331
|
+
~~~~ else (ensure.rescue)
|
1332
|
+
~~~~~~~~~~~~~~~~~~~~~ expression (rescue)
|
1317
1333
|
~~~~~~ keyword (ensure)
|
1318
|
-
|
1319
|
-
~~~ end
|
1334
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (ensure)
|
1335
|
+
~~~ end
|
1320
1336
|
```
|
1321
1337
|
|
1322
1338
|
#### Retry
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Customizing Parsers
|
2
|
+
|
3
|
+
While the default setup of the parsers provided by this Gem should be suitable
|
4
|
+
for most some developers might want to change parts of it. An example would be
|
5
|
+
the use of a custom class for nodes instead of `Parser::AST::Node`.
|
6
|
+
|
7
|
+
Customizing the AST is done by creating a custom builder class and passing it
|
8
|
+
to the constructor method of a parser. The default setup comes down to the
|
9
|
+
following:
|
10
|
+
|
11
|
+
builder = Parser::Builders::Default.new
|
12
|
+
parser = Parser::Ruby19.new(builder)
|
13
|
+
|
14
|
+
When creating your own builder class it's best to subclass the default one so
|
15
|
+
that you don't have to redefine every used method again:
|
16
|
+
|
17
|
+
class MyBuilder < Parser::Builders::Default
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
builder = MyBuilder.new
|
22
|
+
parser = Parser::Ruby19.new(builder)
|
23
|
+
|
24
|
+
## Custom Node Classes
|
25
|
+
|
26
|
+
To use a custom node class you have to override the method
|
27
|
+
`Parser::Builders::Default#n`:
|
28
|
+
|
29
|
+
class MyBuilder < Parser::Builders::Default
|
30
|
+
def n(type, children, source_map)
|
31
|
+
return MyNodeClass.new(type, children, :source_map => source_map)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Note that the used class (and corresponding instance) must be compatible with
|
36
|
+
`Parser::AST::Node` so it's best to subclass it and override/add code where
|
37
|
+
needed.
|
data/doc/INTERNALS.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Entry points
|
2
|
+
------------
|
3
|
+
|
4
|
+
Parser should be kept as slim as possible. This includes not loading
|
5
|
+
any potentially large files when they are likely to be unused in practice.
|
6
|
+
|
7
|
+
Parser has five main (classes of) `require` entry points:
|
8
|
+
|
9
|
+
* `require 'parser'`. Main entry point, requires all classes which
|
10
|
+
are used across the entire library.
|
11
|
+
* `require 'parser/rubyXX'`. Version-specific entry point. Can raise
|
12
|
+
a NotImplementedError if current Ruby runtime is unable to parse the
|
13
|
+
requested Ruby version.
|
14
|
+
* `require 'parser/all'`. Requires all available parsers for released
|
15
|
+
versions of Ruby. Can raise NotImplementedError.
|
16
|
+
* `require 'parser/runner'`. Requires all the stuff which is useful for
|
17
|
+
command-line tools but not otherwise.
|
18
|
+
* `require 'parser/runner/X'`. Runner-specific entry point.
|
19
|
+
|
20
|
+
All non-main entry points internally `require 'parser'`. Additionally, all
|
21
|
+
runner-specific entry points internally `requre 'parser/runner'`.
|
data/lib/parser.rb
CHANGED
@@ -9,6 +9,8 @@ end
|
|
9
9
|
|
10
10
|
# Library namespace
|
11
11
|
module Parser
|
12
|
+
require 'parser/version'
|
13
|
+
|
12
14
|
require 'parser/ast/node'
|
13
15
|
require 'parser/ast/processor'
|
14
16
|
|
@@ -17,7 +19,17 @@ module Parser
|
|
17
19
|
|
18
20
|
require 'parser/source/map'
|
19
21
|
require 'parser/source/map/operator'
|
20
|
-
require 'parser/source/map/
|
22
|
+
require 'parser/source/map/collection'
|
23
|
+
require 'parser/source/map/constant'
|
24
|
+
require 'parser/source/map/variable'
|
25
|
+
require 'parser/source/map/keyword'
|
26
|
+
require 'parser/source/map/definition'
|
27
|
+
require 'parser/source/map/send'
|
28
|
+
require 'parser/source/map/block'
|
29
|
+
require 'parser/source/map/condition'
|
30
|
+
require 'parser/source/map/ternary'
|
31
|
+
require 'parser/source/map/for'
|
32
|
+
require 'parser/source/map/rescue_body'
|
21
33
|
|
22
34
|
require 'parser/syntax_error'
|
23
35
|
require 'parser/diagnostic'
|
@@ -28,7 +40,6 @@ module Parser
|
|
28
40
|
require 'parser/lexer'
|
29
41
|
require 'parser/lexer/literal'
|
30
42
|
require 'parser/lexer/stack_state'
|
31
|
-
require 'parser/lexer/explanation'
|
32
43
|
|
33
44
|
module Builders
|
34
45
|
require 'parser/builders/default'
|
@@ -55,7 +66,7 @@ module Parser
|
|
55
66
|
:invalid_octal => "invalid octal digit",
|
56
67
|
:no_dot_digit_literal => "no .<digit> floating literal anymore; put 0 before dot",
|
57
68
|
:bare_backslash => "bare backslash only allowed before newline",
|
58
|
-
:unexpected => "unexpected
|
69
|
+
:unexpected => "unexpected `%{character}'",
|
59
70
|
:embedded_document => "embedded document meats end of file (and they embark on a romantic journey)",
|
60
71
|
|
61
72
|
# Lexer warnings
|
data/lib/parser/ast/node.rb
CHANGED
data/lib/parser/ast/processor.rb
CHANGED
@@ -2,6 +2,222 @@ module Parser
|
|
2
2
|
module AST
|
3
3
|
|
4
4
|
class Processor < ::AST::Processor
|
5
|
+
def process_regular_node(node)
|
6
|
+
node.updated(nil, process_all(node))
|
7
|
+
end
|
8
|
+
|
9
|
+
alias on_dstr process_regular_node
|
10
|
+
alias on_dsym process_regular_node
|
11
|
+
alias on_regexp process_regular_node
|
12
|
+
alias on_xstr process_regular_node
|
13
|
+
alias on_splat process_regular_node
|
14
|
+
alias on_array process_regular_node
|
15
|
+
alias on_pair process_regular_node
|
16
|
+
alias on_hash process_regular_node
|
17
|
+
alias on_irange process_regular_node
|
18
|
+
alias on_erange process_regular_node
|
19
|
+
|
20
|
+
def on_var(node)
|
21
|
+
name, = *node
|
22
|
+
|
23
|
+
node.updated
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_variable_node(node)
|
27
|
+
on_var(node)
|
28
|
+
end
|
29
|
+
|
30
|
+
alias on_lvar process_variable_node
|
31
|
+
alias on_ivar process_variable_node
|
32
|
+
alias on_gvar process_variable_node
|
33
|
+
alias on_cvar process_variable_node
|
34
|
+
alias on_back_ref process_variable_node
|
35
|
+
alias on_nth_ref process_variable_node
|
36
|
+
|
37
|
+
def on_vasgn(node)
|
38
|
+
name, value_node = *node
|
39
|
+
|
40
|
+
value_node = process(value_node) if value_node
|
41
|
+
node.updated(nil, [ name, value_node ])
|
42
|
+
end
|
43
|
+
|
44
|
+
def process_var_asgn_node(node)
|
45
|
+
on_vasgn(node)
|
46
|
+
end
|
47
|
+
|
48
|
+
alias on_lvasgn process_var_asgn_node
|
49
|
+
alias on_ivasgn process_var_asgn_node
|
50
|
+
alias on_gvasgn process_var_asgn_node
|
51
|
+
alias on_cvdecl process_var_asgn_node
|
52
|
+
alias on_cvasgn process_var_asgn_node
|
53
|
+
|
54
|
+
alias on_and_asgn process_regular_node
|
55
|
+
alias on_or_asgn process_regular_node
|
56
|
+
|
57
|
+
def on_op_asgn(node)
|
58
|
+
var_node, method_name, value_node = *node
|
59
|
+
|
60
|
+
node.updated(nil, [
|
61
|
+
process(var_node), method_name, process(value_node)
|
62
|
+
])
|
63
|
+
end
|
64
|
+
|
65
|
+
alias on_mlhs process_regular_node
|
66
|
+
alias on_masgn process_regular_node
|
67
|
+
|
68
|
+
def on_const(node)
|
69
|
+
scope_node, name = *node
|
70
|
+
|
71
|
+
scope_node = process(scope_node) if scope_node
|
72
|
+
node.updated(nil, [ scope_node, name ])
|
73
|
+
end
|
74
|
+
|
75
|
+
def on_cdecl(node)
|
76
|
+
scope_node, name, value_node = *node
|
77
|
+
|
78
|
+
scope_node = process(scope_node) if scope_node
|
79
|
+
value_node = process(value_node)
|
80
|
+
node.updated(nil, [ scope_node, name, value_node ])
|
81
|
+
end
|
82
|
+
|
83
|
+
alias on_args process_regular_node
|
84
|
+
|
85
|
+
def on_argument(node)
|
86
|
+
arg_name, value_node = *node
|
87
|
+
|
88
|
+
value_node = process(value_node) if value_node
|
89
|
+
node.updated(nil, [ arg_name, value_node ])
|
90
|
+
end
|
91
|
+
|
92
|
+
def process_argument_node(node)
|
93
|
+
on_argument(node)
|
94
|
+
end
|
95
|
+
|
96
|
+
alias on_arg process_argument_node
|
97
|
+
alias on_optarg process_argument_node
|
98
|
+
alias on_splatarg process_argument_node
|
99
|
+
alias on_blockarg process_argument_node
|
100
|
+
alias on_kwarg process_argument_node
|
101
|
+
alias on_kwoptarg process_argument_node
|
102
|
+
alias on_kwsplatarg process_argument_node
|
103
|
+
|
104
|
+
alias on_arg_expr process_regular_node
|
105
|
+
alias on_restarg_expr process_regular_node
|
106
|
+
alias on_blockarg_expr process_regular_node
|
107
|
+
|
108
|
+
alias on_module process_regular_node
|
109
|
+
|
110
|
+
def on_class(node)
|
111
|
+
name_node, superclass_node, body_node = *node
|
112
|
+
|
113
|
+
superclass_node = process(superclass_node) if superclass_node
|
114
|
+
node.updated(nil, [
|
115
|
+
name_node, superclass_node, process(body_node)
|
116
|
+
])
|
117
|
+
end
|
118
|
+
|
119
|
+
alias on_sclass process_regular_node
|
120
|
+
|
121
|
+
def on_def(node)
|
122
|
+
name, args_node, body_node = *node
|
123
|
+
|
124
|
+
node.updated(nil, [
|
125
|
+
name,
|
126
|
+
process(args_node), process(body_node)
|
127
|
+
])
|
128
|
+
end
|
129
|
+
|
130
|
+
def on_defs(node)
|
131
|
+
definee_node, name, args_node, body_node = *node
|
132
|
+
|
133
|
+
node.updated(nil, [
|
134
|
+
process(definee_node), name,
|
135
|
+
process(args_node), process(body_node)
|
136
|
+
])
|
137
|
+
end
|
138
|
+
|
139
|
+
alias on_undef process_regular_node
|
140
|
+
alias on_alias process_regular_node
|
141
|
+
|
142
|
+
def on_send(node)
|
143
|
+
receiver_node, method_name, *arg_nodes = *node
|
144
|
+
|
145
|
+
receiver_node = process(receiver_node) if receiver_node
|
146
|
+
node.updated(nil, [
|
147
|
+
receiver_node, method_name, *process_all(arg_nodes)
|
148
|
+
])
|
149
|
+
end
|
150
|
+
|
151
|
+
alias on_block process_regular_node
|
152
|
+
|
153
|
+
alias on_while process_regular_node
|
154
|
+
alias on_until process_regular_node
|
155
|
+
alias on_for process_regular_node
|
156
|
+
|
157
|
+
alias on_return process_regular_node
|
158
|
+
alias on_break process_regular_node
|
159
|
+
alias on_next process_regular_node
|
160
|
+
alias on_redo process_regular_node
|
161
|
+
alias on_retry process_regular_node
|
162
|
+
alias on_super process_regular_node
|
163
|
+
alias on_yield process_regular_node
|
164
|
+
alias on_defined? process_regular_node
|
165
|
+
|
166
|
+
alias on_not process_regular_node
|
167
|
+
alias on_and process_regular_node
|
168
|
+
alias on_or process_regular_node
|
169
|
+
|
170
|
+
def on_if(node)
|
171
|
+
cond_node, if_true_node, if_false_node = *node
|
172
|
+
|
173
|
+
if_true_node = process(if_true_node) if if_true_node
|
174
|
+
if_false_node = process(if_false_node) if if_false_node
|
175
|
+
|
176
|
+
node.updated(nil, [
|
177
|
+
process(cond_node),
|
178
|
+
if_true_node, if_false_node
|
179
|
+
])
|
180
|
+
end
|
181
|
+
|
182
|
+
alias on_when process_regular_node
|
183
|
+
|
184
|
+
def on_case(node)
|
185
|
+
cond_node, *bodies = *node
|
186
|
+
when_nodes, else_node = bodies[0..-2], bodies[-1]
|
187
|
+
|
188
|
+
else_node = process(else_node) if else_node
|
189
|
+
node.updated(nil, [
|
190
|
+
process(cond_node),
|
191
|
+
*(process_all(when_nodes) << else_node)
|
192
|
+
])
|
193
|
+
end
|
194
|
+
|
195
|
+
def on_resbody(node)
|
196
|
+
exc_list_node, exc_var_node, body_node = *node
|
197
|
+
|
198
|
+
exc_list_node = process(exc_list_node) if exc_list_node
|
199
|
+
exc_var_node = process(exc_var_node) if exc_var_node
|
200
|
+
|
201
|
+
node.updated(nil, [
|
202
|
+
exc_list_node, exc_var_node,
|
203
|
+
process(body_node)
|
204
|
+
])
|
205
|
+
end
|
206
|
+
|
207
|
+
def on_rescue(node)
|
208
|
+
body_node, *handlers = *node
|
209
|
+
handler_nodes, else_node = handlers[0..-2], handlers[-1]
|
210
|
+
|
211
|
+
else_node = process(else_node) if else_node
|
212
|
+
node.updated(nil, [
|
213
|
+
process(body_node),
|
214
|
+
*(process_all(handler_nodes) << else_node)
|
215
|
+
])
|
216
|
+
end
|
217
|
+
|
218
|
+
alias on_ensure process_regular_node
|
219
|
+
|
220
|
+
alias on_begin process_regular_node
|
5
221
|
end
|
6
222
|
|
7
223
|
end
|