parser_node_ext 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +2 -2
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +33 -29
- data/sig/parser_node_ext.rbs +4 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caf4a4308e04940f7b74d41db9bdf1ae06a15f9b4a63f565f4b4731c89d11693
|
4
|
+
data.tar.gz: edcb3bc6b1d55dfec2b17b5e97e1fe5bd86b83f09e5cb4a41e2ea9c0f0c5b4cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92a28bab2a901ee32a7e19007e9eb0cd8ac01997acd033b080f9608e6bd9e333294d4b683a124af72cecd2aaaf523571bb57714082ccb8e5cf6b0e0627f7078e
|
7
|
+
data.tar.gz: b4bff787710ace35fbbce28815f95d6e4f5487ae7c21eb6601e4890ed6f8253831b6a38a9b50598301d77b8080518e48d00c5ba7b4a2384208d7155717d92c7b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.6.0 (2023-01-06)
|
4
|
+
|
5
|
+
* Support `value` for `float`, `int`, `str` and `sym` nodes
|
6
|
+
* Support `if` node
|
7
|
+
* Support `case`/`when` node
|
8
|
+
* Truly dynamically define methods based on const `TYPE_CHILDREN`
|
9
|
+
|
10
|
+
## 0.5.1 (2022-12-26)
|
11
|
+
|
12
|
+
* hash node pairs should return an array of pair nodes
|
13
|
+
|
14
|
+
## 0.5.0 (2022-12-25)
|
15
|
+
|
16
|
+
* Add primitive types
|
17
|
+
|
3
18
|
## 0.4.1 (2022-10-21)
|
4
19
|
|
5
20
|
* Update error message
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
parser_node_ext (0.
|
4
|
+
parser_node_ext (0.6.0)
|
5
5
|
parser
|
6
6
|
|
7
7
|
GEM
|
@@ -9,7 +9,7 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
11
|
diff-lcs (1.5.0)
|
12
|
-
parser (3.
|
12
|
+
parser (3.2.0.0)
|
13
13
|
ast (~> 2.4.1)
|
14
14
|
rake (13.0.6)
|
15
15
|
rspec (3.11.0)
|
data/lib/parser_node_ext.rb
CHANGED
@@ -14,6 +14,7 @@ module ParserNodeExt
|
|
14
14
|
begin: %i[body],
|
15
15
|
block: %i[caller arguments body],
|
16
16
|
blockarg: %i[name],
|
17
|
+
case: %i[expression when_statements else_statement],
|
17
18
|
const: %i[parent_const name],
|
18
19
|
class: %i[name parent_class body],
|
19
20
|
csend: %i[receiver message arguments],
|
@@ -23,9 +24,10 @@ module ParserNodeExt
|
|
23
24
|
definded?: %i[arguments],
|
24
25
|
defs: %i[self name arguments body],
|
25
26
|
false: [],
|
26
|
-
float: [],
|
27
|
+
float: %i[value],
|
27
28
|
hash: %i[pairs],
|
28
|
-
|
29
|
+
if: %i[expression if_statement else_statement],
|
30
|
+
int: %i[value],
|
29
31
|
ivasgn: %i[left_value right_value],
|
30
32
|
ivar: %i[name],
|
31
33
|
lvar: %i[name],
|
@@ -38,10 +40,11 @@ module ParserNodeExt
|
|
38
40
|
pair: %i[key value],
|
39
41
|
restarg: %i[name],
|
40
42
|
send: %i[receiver message arguments],
|
41
|
-
str: [],
|
43
|
+
str: %i[value],
|
42
44
|
super: %i[arguments],
|
43
|
-
sym: [],
|
45
|
+
sym: %i[value],
|
44
46
|
true: [],
|
47
|
+
when: %i[expression body],
|
45
48
|
zsuper: []
|
46
49
|
}
|
47
50
|
|
@@ -80,22 +83,8 @@ module ParserNodeExt
|
|
80
83
|
parent.children[index + 1..]
|
81
84
|
end
|
82
85
|
|
83
|
-
# Dyamically defined method
|
84
|
-
|
85
|
-
# based on const TYPE_CHILDREN.
|
86
|
-
%i[
|
87
|
-
caller
|
88
|
-
key
|
89
|
-
left_value
|
90
|
-
message
|
91
|
-
name
|
92
|
-
pairs
|
93
|
-
parent_class
|
94
|
-
parent_const
|
95
|
-
receiver
|
96
|
-
right_value
|
97
|
-
value
|
98
|
-
].each do |method_name|
|
86
|
+
# Dyamically defined method based on const TYPE_CHILDREN.
|
87
|
+
TYPE_CHILDREN.values.flatten.uniq.each do |method_name|
|
99
88
|
define_method(method_name) do
|
100
89
|
index = TYPE_CHILDREN[type]&.index(method_name)
|
101
90
|
return children[index] if index
|
@@ -153,6 +142,10 @@ module ParserNodeExt
|
|
153
142
|
case type
|
154
143
|
when :begin
|
155
144
|
children
|
145
|
+
when :when
|
146
|
+
return [] if children[1].nil?
|
147
|
+
|
148
|
+
:begin == children[1].type ? children[1].body : children[1..-1]
|
156
149
|
when :def, :block, :class, :module
|
157
150
|
return [] if children[2].nil?
|
158
151
|
|
@@ -166,18 +159,29 @@ module ParserNodeExt
|
|
166
159
|
end
|
167
160
|
end
|
168
161
|
|
169
|
-
|
170
|
-
|
162
|
+
def when_statements
|
163
|
+
if :case == type
|
164
|
+
children[1...-1]
|
165
|
+
else
|
166
|
+
raise MethodNotSupported, "when_statements is not supported for #{self}"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def else_statement
|
171
|
+
children[-1]
|
172
|
+
end
|
173
|
+
|
174
|
+
# Get pairs of :hash node.
|
171
175
|
# @example
|
172
|
-
# node # s(:
|
173
|
-
# node.
|
174
|
-
# @return [Parser::AST::Node]
|
176
|
+
# node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar")))
|
177
|
+
# node.pairs # [s(:pair, s(:sym, :foo), s(:sym, :bar)), s(:pair, s(:str, "foo"), s(:str, "bar"))]
|
178
|
+
# @return [Array<Parser::AST::Node>] pairs of node.
|
175
179
|
# @raise [MethodNotSupported] if calls on other node.
|
176
|
-
def
|
177
|
-
if :
|
178
|
-
children
|
180
|
+
def pairs
|
181
|
+
if :hash == type
|
182
|
+
children
|
179
183
|
else
|
180
|
-
raise MethodNotSupported, "
|
184
|
+
raise MethodNotSupported, "pairs is not supported for #{self}"
|
181
185
|
end
|
182
186
|
end
|
183
187
|
|
data/sig/parser_node_ext.rbs
CHANGED
@@ -5,6 +5,9 @@ module ParserNodeExt
|
|
5
5
|
def arguments: () -> Array[Parser::AST::Node]
|
6
6
|
def body: () -> Array[Parser::AST::Node]
|
7
7
|
def caller: () -> Parser::AST::Node
|
8
|
+
def else_statement: () -> Parser::AST::Node
|
9
|
+
def expression: () -> Parser::AST::Node
|
10
|
+
def if_statement: () -> Parser::AST::Node
|
8
11
|
def key: () -> Parser::AST::Node
|
9
12
|
def left_value: () -> Parser::AST::Node | Symbol
|
10
13
|
def message: () -> Symbol
|
@@ -15,6 +18,7 @@ module ParserNodeExt
|
|
15
18
|
def right_value: () -> Parser::AST::Node
|
16
19
|
def self: () -> Parser::AST::Node
|
17
20
|
def value: () -> Parser::AST::Node
|
21
|
+
def when_statements: () -> Array[Parser::AST::Node]
|
18
22
|
|
19
23
|
def to_hash: () -> Hash
|
20
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parser_node_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
66
|
+
rubygems_version: 3.4.1
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: extend parser node
|