syntax_tree_ext 0.6.4 → 0.7.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 +6 -0
- data/Gemfile.lock +1 -1
- data/lib/syntax_tree_ext/version.rb +1 -1
- data/lib/syntax_tree_ext.rb +3 -48
- 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: 97f2ba6521c0048eaaa6f65a4a17b4f34891b0eef53d968374f7e44bf4e75246
|
4
|
+
data.tar.gz: 27bd10410c6189066f89c6a94e7ce1b92d84a59be1598eba177ed2f0ee617818
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb7aeb9a688f2d789e54087caf16a031b7f1caa8c9f553f5be17b3b086532456914c9c61f391e08860b9fd22496a2de07c3653a7d6430863cbd550321937176d
|
7
|
+
data.tar.gz: b52f466c32ca64172aaeb0b8ede41f4c93feef922b4f1d36ac24a522a844f21319eac8b025c85fc51e02054bd7464471830f19070bd8c0d5b50435427c482230
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/syntax_tree_ext.rb
CHANGED
@@ -18,11 +18,11 @@ module SyntaxTreeExt
|
|
18
18
|
end
|
19
19
|
|
20
20
|
module SyntaxTree
|
21
|
-
class
|
21
|
+
class << self
|
22
22
|
alias_method :original_parse, :parse
|
23
23
|
|
24
|
-
def parse
|
25
|
-
node = original_parse
|
24
|
+
def parse(source)
|
25
|
+
node = original_parse(source)
|
26
26
|
node.set_parent_node_and_source(source)
|
27
27
|
node
|
28
28
|
end
|
@@ -50,17 +50,6 @@ module SyntaxTree
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def siblings
|
54
|
-
child_nodes = parent_node.deconstruct_keys([]).except(:location, :comments).values
|
55
|
-
if child_nodes.is_a?(Array) && child_nodes.size == 1 && child_nodes.first.is_a?(Array)
|
56
|
-
index = child_nodes.first.index(self)
|
57
|
-
return child_nodes.first[index + 1...]
|
58
|
-
end
|
59
|
-
|
60
|
-
index = child_nodes.index(self)
|
61
|
-
child_nodes[index + 1...]
|
62
|
-
end
|
63
|
-
|
64
53
|
def keys
|
65
54
|
if is_a?(BareAssocHash) || is_a?(HashLiteral)
|
66
55
|
assocs.map(&:key)
|
@@ -120,27 +109,6 @@ module SyntaxTree
|
|
120
109
|
source[location.start_char...location.end_char]
|
121
110
|
end
|
122
111
|
|
123
|
-
# Convert node to a hash, so that it can be converted to a json.
|
124
|
-
def to_hash
|
125
|
-
result = { node_type: self.class.name.split('::').last }
|
126
|
-
unless deconstruct_keys([]).empty?
|
127
|
-
deconstruct_keys([]).each do |key, value|
|
128
|
-
result[key] =
|
129
|
-
case value
|
130
|
-
when Array
|
131
|
-
value.map { |v| v.respond_to?(:to_hash) ? v.to_hash : v }
|
132
|
-
when SyntaxTree::Node, SyntaxTree::Location
|
133
|
-
value.to_hash
|
134
|
-
else
|
135
|
-
value
|
136
|
-
end
|
137
|
-
end
|
138
|
-
else
|
139
|
-
result[:children] = children.map { |c| c.respond_to?(:to_hash) ? c.to_hash : c }
|
140
|
-
end
|
141
|
-
result
|
142
|
-
end
|
143
|
-
|
144
112
|
# Respond key value and source for hash node
|
145
113
|
def method_missing(method_name, *args, &block)
|
146
114
|
return super unless respond_to_assocs?
|
@@ -187,17 +155,4 @@ module SyntaxTree
|
|
187
155
|
assoc_key.end_with?(':') ? assoc_key == "#{key}:" : assoc_key == key
|
188
156
|
end
|
189
157
|
end
|
190
|
-
|
191
|
-
class Location
|
192
|
-
def to_hash
|
193
|
-
{
|
194
|
-
start_line: start_line,
|
195
|
-
start_char: start_char,
|
196
|
-
start_column: start_column,
|
197
|
-
end_line: end_line,
|
198
|
-
end_char: end_char,
|
199
|
-
end_column: end_column,
|
200
|
-
}
|
201
|
-
end
|
202
|
-
end
|
203
158
|
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.7.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: 2024-02-10 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.
|
64
|
+
rubygems_version: 3.5.3
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: extend syntax_tree
|