syntax_tree_ext 0.3.0 → 0.4.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/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/lib/syntax_tree_ext/version.rb +1 -1
- data/lib/syntax_tree_ext.rb +37 -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: 252bb9039575140c0f6880c558a9dc3b19b08e400f673184672a4064584473aa
|
|
4
|
+
data.tar.gz: cfe4011f7e28f90f1ce9a30573fde27529f0f92eabc1af79719cd2d5a4405033
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f729e476eb65c5587c4a2bc3fd6026ef9debd27af3b951b4a9a269480fad087c819a337084b401df9cc15e8ea82349879245f427bcbb0d1026c4d55b707d6c59
|
|
7
|
+
data.tar.gz: c329ff9f956c7ba8e718ffc8df2f5f05c6bd7c6e556c28828e3da5378db4fcd91f44e7a71a242391e2ff7b53750b57b3133247285e0a78bac10e53747d285876
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/syntax_tree_ext.rb
CHANGED
|
@@ -52,8 +52,10 @@ module SyntaxTree
|
|
|
52
52
|
value == 'true'
|
|
53
53
|
when VarRef
|
|
54
54
|
value.to_value
|
|
55
|
-
when Label, TStringContent
|
|
55
|
+
when Label, TStringContent, Ident
|
|
56
56
|
value
|
|
57
|
+
when ArrayLiteral
|
|
58
|
+
contents.parts.map { |part| part.to_value }
|
|
57
59
|
else
|
|
58
60
|
self
|
|
59
61
|
end
|
|
@@ -63,6 +65,27 @@ module SyntaxTree
|
|
|
63
65
|
source[location.start_char...location.end_char]
|
|
64
66
|
end
|
|
65
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
|
+
|
|
66
89
|
# Respond key value and source for hash node
|
|
67
90
|
def method_missing(method_name, *args, &block)
|
|
68
91
|
return super unless respond_to_assocs?
|
|
@@ -109,4 +132,17 @@ module SyntaxTree
|
|
|
109
132
|
assoc_key.end_with?(':') ? assoc_key == "#{key}:" : assoc_key == key
|
|
110
133
|
end
|
|
111
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
|
|
112
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.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: 2023-
|
|
11
|
+
date: 2023-06-08 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
|