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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14e5005eed3acbb6399f68c0edf358ba15f4565eb4d99e20652158dbd1c2594e
4
- data.tar.gz: 8fee6e5e40b9db6adcd72cf72e2705124b9a7e6fcc90ad4673600c1f5074cd69
3
+ metadata.gz: 7d9ecce5098c654a026b3f08bd8e5dc0a87b696d5e56102f11a40540a7b45d72
4
+ data.tar.gz: 41b5bc8b68fb82183e1d641e735fa9083365c5077402193cbf2128c026b1140e
5
5
  SHA512:
6
- metadata.gz: 1801ffc4ecfa3e7693009267a8a22225f53d04668ca5ddf4c59ba7e0bd2fc5c9e5b5ecfde771aa9631911bd19a0d0e198abcfd18cfe476d3c64ffb7df4480662
7
- data.tar.gz: 1fec3247f8836c5bf8175530efe0cb51e692e922c431d2f7d81b4f7dd22d895849cfe1af57996c4dff4a18a29bfdecbd30d0bdba24a94dffc4540609f24c3830
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 but augments it to return a
41
- `TreeStand::Tree` instead of the underlying `TreeSitter::Tree`. Similarly, `TreeStand::Tree#root_node` returns a
42
- `TreeStand::Node` & `TreeSitter::Tree#root_node` returns a `TreeSitter::Node`.
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
 
@@ -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]
@@ -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(tree, document)
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!(tree, document)
49
- tree = parse_string(tree, document)
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)
@@ -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(@ts_tree, @document)
112
+ new_tree = @parser.parse_string(@document, tree: self)
113
113
  @ts_tree = new_tree.ts_tree
114
114
  end
115
115
  end
@@ -1,4 +1,4 @@
1
1
  module TreeStand
2
2
  # The current version of the gem.
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
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.5
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-12 00:00:00.000000000 Z
11
+ date: 2023-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk