tree_stand 0.1.5 → 0.1.6
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/README.md +4 -3
- data/lib/tree_stand/node.rb +1 -1
- data/lib/tree_stand/parser.rb +7 -5
- data/lib/tree_stand/tree.rb +1 -1
- data/lib/tree_stand/version.rb +1 -1
- 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: 7d9ecce5098c654a026b3f08bd8e5dc0a87b696d5e56102f11a40540a7b45d72
|
|
4
|
+
data.tar.gz: 41b5bc8b68fb82183e1d641e735fa9083365c5077402193cbf2128c026b1140e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1a91dcfa898f9341ed7d8493204cec0ff1170b157e8598226a41858faa96de9f4df45b6e1e449c5c817b3edc7b44efa9bfb7bbfae6a1f4a031580ff0663a0e3
|
|
7
|
+
data.tar.gz: 23cc338e725309b833f1b9200101f191772798e3a85d1610c41237522096a7454013fcf6252de8b161c62f7831a263f2ec94603aff4be47739b4a78cc4fdcedc
|
data/README.md
CHANGED
|
@@ -37,9 +37,10 @@ ruby_parser = TreeStand::Parser.new("ruby")
|
|
|
37
37
|
### API Conventions
|
|
38
38
|
|
|
39
39
|
TreeStand aims to provide APIs similar to TreeSitter when possible. For example, the TreeSitter parser exposes a
|
|
40
|
-
`#parse_string(tree, document)` method. TreeStand replicates this behaviour
|
|
41
|
-
`TreeStand::Tree` instead of the underlying `TreeSitter::Tree`.
|
|
42
|
-
`TreeStand::Node` & `TreeSitter::Tree#root_node` returns a
|
|
40
|
+
`#parse_string(tree, document)` method. TreeStand replicates this behaviour closely with it's `#parse_string(document,
|
|
41
|
+
tree: nil)` method but augments it to return a `TreeStand::Tree` instead of the underlying `TreeSitter::Tree`.
|
|
42
|
+
Similarly, `TreeStand::Tree#root_node` returns a `TreeStand::Node` & `TreeSitter::Tree#root_node` returns a
|
|
43
|
+
`TreeSitter::Node`.
|
|
43
44
|
|
|
44
45
|
The underlying objects are accessible via a `ts_` prefixed attribute, e.g. `ts_parser`, `ts_tree`, `ts_node`, etc.
|
|
45
46
|
|
data/lib/tree_stand/node.rb
CHANGED
|
@@ -159,7 +159,7 @@ module TreeStand
|
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
# A convience method for getting the text of the node. Each {TreeStand::Node}
|
|
162
|
-
# wraps the parent {#tree} and has access to the source document.
|
|
162
|
+
# wraps the parent {TreeStand::Tree #tree} and has access to the source document.
|
|
163
163
|
# @return [String]
|
|
164
164
|
def text
|
|
165
165
|
@tree.document[@ts_node.start_byte...@ts_node.end_byte]
|
data/lib/tree_stand/parser.rb
CHANGED
|
@@ -30,11 +30,13 @@ module TreeStand
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
# Parse the provided document with the TreeSitter parser.
|
|
33
|
-
# @param tree [TreeStand::Tree]
|
|
33
|
+
# @param tree [TreeStand::Tree, nil] providing the old tree will allow the
|
|
34
|
+
# parser to take advantage of incremental parsing and improve performance
|
|
35
|
+
# by re-useing nodes from the old tree.
|
|
34
36
|
# @param document [String]
|
|
35
37
|
# @return [TreeStand::Tree]
|
|
36
|
-
def parse_string(
|
|
37
|
-
# There's a bug with passing a non-nil tree
|
|
38
|
+
def parse_string(document, tree: nil)
|
|
39
|
+
# @todo There's a bug with passing a non-nil tree
|
|
38
40
|
ts_tree = @ts_parser.parse_string(nil, document)
|
|
39
41
|
TreeStand::Tree.new(self, ts_tree, document)
|
|
40
42
|
end
|
|
@@ -45,8 +47,8 @@ module TreeStand
|
|
|
45
47
|
#
|
|
46
48
|
# @see #parse_string
|
|
47
49
|
# @raise [TreeStand::InvalidDocument]
|
|
48
|
-
def parse_string!(
|
|
49
|
-
tree = parse_string(
|
|
50
|
+
def parse_string!(document, tree: nil)
|
|
51
|
+
tree = parse_string(document, tree: tree)
|
|
50
52
|
return tree unless tree.any?(&:error?)
|
|
51
53
|
|
|
52
54
|
raise(InvalidDocument, <<~ERROR)
|
data/lib/tree_stand/tree.rb
CHANGED
|
@@ -109,7 +109,7 @@ module TreeStand
|
|
|
109
109
|
|
|
110
110
|
def replace_with_new_doc(new_document)
|
|
111
111
|
@document = new_document
|
|
112
|
-
new_tree = @parser.parse_string(@
|
|
112
|
+
new_tree = @parser.parse_string(@document, tree: self)
|
|
113
113
|
@ts_tree = new_tree.ts_tree
|
|
114
114
|
end
|
|
115
115
|
end
|
data/lib/tree_stand/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tree_stand
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- derekstride
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-01-
|
|
11
|
+
date: 2023-01-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: zeitwerk
|