parser_node_ext 0.2.0 → 0.3.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 +4 -0
- data/Gemfile.lock +1 -1
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +22 -2
- data/sig/parser_node_ext.rbs +15 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b8a89fd698e65560bb6ec6288cc2739b8073440b2763c6f37d8f2a662e7d629
|
4
|
+
data.tar.gz: 36be4ab919e445d38e506f6b91cdbeac541568d328459eb6b4756d21fb1edfc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0e1ac0d615a85c08ac82a793ac3f4c205e44f14360593836ea37dc791c237b7d72691ba35525d60a2dd9e3a2dbc270fddfc036514d2cfa9680755c0850262de
|
7
|
+
data.tar.gz: f45b6a7df41303d14829b7416e761ce0b5737a9030b986522c1dd3704ea6b528390ec7137991c7916fa25c3034028e1a60298ff5fd7803e6555bc3e0ab867087
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/parser_node_ext.rb
CHANGED
@@ -5,8 +5,6 @@ require_relative "parser_node_ext/version"
|
|
5
5
|
require 'parser'
|
6
6
|
|
7
7
|
module ParserNodeExt
|
8
|
-
class Error < StandardError; end
|
9
|
-
|
10
8
|
class MethodNotSupported < StandardError; end
|
11
9
|
# Your code goes here...
|
12
10
|
|
@@ -272,6 +270,28 @@ module ParserNodeExt
|
|
272
270
|
loc.expression&.source
|
273
271
|
end
|
274
272
|
|
273
|
+
# Convert node to a hash, so that it can be converted to a json.
|
274
|
+
def to_hash
|
275
|
+
result = { type: type }
|
276
|
+
if TYPE_CHILDREN[type]
|
277
|
+
TYPE_CHILDREN[type].each do |key|
|
278
|
+
value = send(key)
|
279
|
+
result[key] =
|
280
|
+
case value
|
281
|
+
when Array
|
282
|
+
value.map { |v| v.respond_to?(:to_hash) ? v.to_hash : v }
|
283
|
+
when Parser::AST::Node
|
284
|
+
value.to_hash
|
285
|
+
else
|
286
|
+
value
|
287
|
+
end
|
288
|
+
end
|
289
|
+
else
|
290
|
+
result[:children] = children.map { |c| c.respond_to?(:to_hash) ? c.to_hash : c }
|
291
|
+
end
|
292
|
+
result
|
293
|
+
end
|
294
|
+
|
275
295
|
# Respond key value and source for hash node, e.g.
|
276
296
|
# @example
|
277
297
|
# node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
|
data/sig/parser_node_ext.rbs
CHANGED
@@ -2,17 +2,19 @@ module ParserNodeExt
|
|
2
2
|
VERSION: String
|
3
3
|
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
4
4
|
|
5
|
-
def arguments: Array[Parser::AST::Node]
|
6
|
-
def body: Array[Parser::AST::Node]
|
7
|
-
def caller: Parser::AST::Node
|
8
|
-
def key: Parser::AST::Node
|
9
|
-
def left_value: Parser::AST::Node | Symbol
|
10
|
-
def message: Symbol
|
11
|
-
def name: Parser::AST::Node | Symbol
|
12
|
-
def pairs: Array[Parser::AST::Node]
|
13
|
-
def parent_class: Parser::AST::Node
|
14
|
-
def receiver: Parser::AST::Node
|
15
|
-
def right_value: Parser::AST::Node
|
16
|
-
def self: Parser::AST::Node
|
17
|
-
def value: Parser::AST::Node
|
5
|
+
def arguments: () -> Array[Parser::AST::Node]
|
6
|
+
def body: () -> Array[Parser::AST::Node]
|
7
|
+
def caller: () -> Parser::AST::Node
|
8
|
+
def key: () -> Parser::AST::Node
|
9
|
+
def left_value: () -> Parser::AST::Node | Symbol
|
10
|
+
def message: () -> Symbol
|
11
|
+
def name: () -> Parser::AST::Node | Symbol
|
12
|
+
def pairs: () -> Array[Parser::AST::Node]
|
13
|
+
def parent_class: () -> Parser::AST::Node
|
14
|
+
def receiver: () -> Parser::AST::Node
|
15
|
+
def right_value: () -> Parser::AST::Node
|
16
|
+
def self: () -> Parser::AST::Node
|
17
|
+
def value: () -> Parser::AST::Node
|
18
|
+
|
19
|
+
def to_hash: () -> Hash
|
18
20
|
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.3.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: 2022-
|
11
|
+
date: 2022-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|