syntax_tree_ext 0.3.1 → 0.4.1
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/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/lib/syntax_tree_ext/version.rb +1 -1
- data/lib/syntax_tree_ext.rb +35 -1
- 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: f369f11506e5b0deee505fd45a2dc9528dcc949afbd3c251445976e74a5e1e34
|
4
|
+
data.tar.gz: d7c8c612139042547ea4a3b94e4b22d09776763a9a1abaa1f55a16857b56a94c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba91207069dff6049b134b310065ba6443834bbc43e9e0f1a161ff16d8e3d20d781df00364e9633cd71e07d870827ccedd15fa0eecd32e7a02fd82d89daea180
|
7
|
+
data.tar.gz: 054e6676cf631d02cc37f620d3bc5689463e38054217a972d0cd5108077ce8e852881e9b1995a3158eb4b9e930de3b3523ab757e0871f979df8bf95791765fb6
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/syntax_tree_ext.rb
CHANGED
@@ -52,7 +52,7 @@ module SyntaxTree
|
|
52
52
|
value == 'true'
|
53
53
|
when VarRef
|
54
54
|
value.to_value
|
55
|
-
when Label, TStringContent, Ident
|
55
|
+
when Const, Label, TStringContent, Ident
|
56
56
|
value
|
57
57
|
when ArrayLiteral
|
58
58
|
contents.parts.map { |part| part.to_value }
|
@@ -65,6 +65,27 @@ module SyntaxTree
|
|
65
65
|
source[location.start_char...location.end_char]
|
66
66
|
end
|
67
67
|
|
68
|
+
# Convert node to a hash, so that it can be converted to a json.
|
69
|
+
def to_hash
|
70
|
+
result = { node_type: self.class.name.split('::').last }
|
71
|
+
unless deconstruct_keys([]).empty?
|
72
|
+
deconstruct_keys([]).each do |key, value|
|
73
|
+
result[key] =
|
74
|
+
case value
|
75
|
+
when Array
|
76
|
+
value.map { |v| v.respond_to?(:to_hash) ? v.to_hash : v }
|
77
|
+
when SyntaxTree::Node, SyntaxTree::Location
|
78
|
+
value.to_hash
|
79
|
+
else
|
80
|
+
value
|
81
|
+
end
|
82
|
+
end
|
83
|
+
else
|
84
|
+
result[:children] = children.map { |c| c.respond_to?(:to_hash) ? c.to_hash : c }
|
85
|
+
end
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
68
89
|
# Respond key value and source for hash node
|
69
90
|
def method_missing(method_name, *args, &block)
|
70
91
|
return super unless respond_to_assocs?
|
@@ -111,4 +132,17 @@ module SyntaxTree
|
|
111
132
|
assoc_key.end_with?(':') ? assoc_key == "#{key}:" : assoc_key == key
|
112
133
|
end
|
113
134
|
end
|
135
|
+
|
136
|
+
class Location
|
137
|
+
def to_hash
|
138
|
+
{
|
139
|
+
start_line: start_line,
|
140
|
+
start_char: start_char,
|
141
|
+
start_column: start_column,
|
142
|
+
end_line: end_line,
|
143
|
+
end_char: end_char,
|
144
|
+
end_column: end_column,
|
145
|
+
}
|
146
|
+
end
|
147
|
+
end
|
114
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_tree_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: syntax_tree
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
|
-
rubygems_version: 3.4.
|
64
|
+
rubygems_version: 3.4.13
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: extend syntax_tree
|