tree_haver 1.0.0 → 3.0.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.
@@ -47,7 +47,7 @@ module TreeHaver
47
47
  # Get list of candidate library names
48
48
  def self.lib_candidates: () -> Array[String]
49
49
 
50
- # Load the Tree-sitter runtime library
50
+ # Load the tree-sitter runtime library
51
51
  def self.try_load!: () -> void
52
52
 
53
53
  # Check if the library is loaded
@@ -281,5 +281,72 @@ module TreeHaver
281
281
  class Node
282
282
  end
283
283
  end
284
+
285
+ # Citrus backend using pure Ruby Citrus parser
286
+ module Citrus
287
+ # Check if the Citrus backend is available
288
+ def self.available?: () -> bool
289
+
290
+ # Reset the load state (for testing)
291
+ def self.reset!: () -> void
292
+
293
+ # Get capabilities supported by this backend
294
+ def self.capabilities: () -> Hash[Symbol, untyped]
295
+
296
+ class Language
297
+ attr_reader grammar_module: untyped
298
+
299
+ # Create a new language from a Citrus grammar module
300
+ def initialize: (untyped grammar_module) -> void
301
+ end
302
+
303
+ class Parser
304
+ # Create a new parser instance
305
+ def initialize: () -> void
306
+
307
+ # Set the grammar for this parser
308
+ def language=: (Language | untyped grammar) -> (Language | untyped)
309
+
310
+ # Parse source code
311
+ def parse: (String source) -> untyped
312
+
313
+ private
314
+
315
+ @grammar: untyped
316
+ end
317
+
318
+ class Tree
319
+ attr_reader root_match: untyped
320
+ attr_reader source: String
321
+
322
+ def initialize: (untyped root_match, String source) -> void
323
+
324
+ def root_node: () -> Node
325
+ end
326
+
327
+ class Node
328
+ attr_reader match: untyped
329
+ attr_reader source: String
330
+
331
+ def initialize: (untyped match, String source) -> void
332
+
333
+ def type: () -> String
334
+
335
+ def start_byte: () -> Integer
336
+
337
+ def end_byte: () -> Integer
338
+
339
+ def text: () -> String
340
+
341
+ def child_count: () -> Integer
342
+
343
+ def child: (Integer index) -> Node?
344
+
345
+ def children: () -> Array[Node]
346
+
347
+ def each: () { (Node) -> void } -> void
348
+ | () -> Enumerator[Node, nil]
349
+ end
350
+ end
284
351
  end
285
352
  end
@@ -26,6 +26,7 @@ module TreeHaver
26
26
  def self.sanitize_language_name: (String | Symbol | nil name) -> Symbol?
27
27
  def self.validation_errors: (String? path) -> Array[String]
28
28
  def self.windows_absolute_path?: (String path) -> bool
29
+ def self.has_valid_extension?: (String path) -> bool
29
30
  end
30
31
  end
31
32
 
data/sig/tree_haver.rbs CHANGED
@@ -1,6 +1,6 @@
1
1
  # Type definitions for TreeHaver
2
2
  #
3
- # TreeHaver is a cross-Ruby adapter for the Tree-sitter parsing library
3
+ # TreeHaver is a cross-Ruby adapter for the tree-sitter parsing library
4
4
 
5
5
  module TreeHaver
6
6
  VERSION: String
@@ -44,7 +44,7 @@ module TreeHaver
44
44
  # Fetch a registered language entry
45
45
  def self.registered_language: (Symbol | String name) -> Hash[Symbol, String?]?
46
46
 
47
- # Represents a Tree-sitter language grammar
47
+ # Represents a tree-sitter language grammar
48
48
  class Language
49
49
  # Load a language grammar from a shared library
50
50
  def self.from_library: (String path, ?symbol: String?, ?name: String?) -> Language
@@ -57,7 +57,7 @@ module TreeHaver
57
57
  def self.respond_to_missing?: (Symbol method_name, ?bool include_private) -> bool
58
58
  end
59
59
 
60
- # Represents a Tree-sitter parser instance
60
+ # Represents a tree-sitter parser instance
61
61
  class Parser
62
62
  # Create a new parser instance
63
63
  def initialize: () -> void
@@ -68,6 +68,9 @@ module TreeHaver
68
68
  # Parse source code into a syntax tree
69
69
  def parse: (String source) -> Tree
70
70
 
71
+ # Parse with optional incremental parsing support
72
+ def parse_string: (Tree? old_tree, String source) -> Tree
73
+
71
74
  private
72
75
 
73
76
  @impl: untyped
@@ -75,30 +78,113 @@ module TreeHaver
75
78
 
76
79
  # Represents a parsed syntax tree
77
80
  class Tree
81
+ attr_reader inner_tree: untyped
82
+ attr_reader source: String?
83
+
78
84
  # Get the root node of the syntax tree
79
- def root_node: () -> Node
85
+ def root_node: () -> Node?
80
86
 
81
- private
87
+ # Edit the tree for incremental parsing
88
+ def edit: (
89
+ start_byte: Integer,
90
+ old_end_byte: Integer,
91
+ new_end_byte: Integer,
92
+ start_point: Hash[Symbol, Integer],
93
+ old_end_point: Hash[Symbol, Integer],
94
+ new_end_point: Hash[Symbol, Integer]
95
+ ) -> void
82
96
 
83
- def initialize: (untyped impl) -> void
97
+ # Check if the current backend supports incremental parsing
98
+ def supports_editing?: () -> bool
84
99
 
85
- @impl: untyped
100
+ # String representation
101
+ def inspect: () -> String
102
+
103
+ # Check if tree responds to a method (includes delegation to inner_tree)
104
+ def respond_to_missing?: (Symbol method_name, ?bool include_private) -> bool
105
+
106
+ # Delegate unknown methods to the underlying backend-specific tree
107
+ def method_missing: (Symbol method_name, *untyped args, **untyped kwargs) ?{ () -> untyped } -> untyped
108
+
109
+ private
110
+
111
+ def initialize: (untyped inner_tree, ?source: String?) -> void
86
112
  end
87
113
 
88
114
  # Represents a node in the syntax tree
89
115
  class Node
116
+ attr_reader inner_node: untyped
117
+ attr_reader source: String?
118
+
90
119
  # Get the type name of this node
91
120
  def type: () -> String
92
121
 
122
+ # Get the text content of this node
123
+ def text: () -> String?
124
+
125
+ # Get the start byte offset
126
+ def start_byte: () -> Integer
127
+
128
+ # Get the end byte offset
129
+ def end_byte: () -> Integer
130
+
131
+ # Get the start point (row, column)
132
+ def start_point: () -> Point
133
+
134
+ # Get the end point (row, column)
135
+ def end_point: () -> Point
136
+
137
+ # Get the number of child nodes
138
+ def child_count: () -> Integer
139
+
140
+ # Get a child node by index
141
+ def child: (Integer index) -> Node?
142
+
143
+ # Get all children as an array
144
+ def children: () -> Array[Node]
145
+
93
146
  # Iterate over child nodes
94
147
  def each: () { (Node child) -> void } -> nil
95
148
  | () -> Enumerator[Node, nil]
96
149
 
150
+ # Get a named child by field name
151
+ def child_by_field_name: (String | Symbol field_name) -> Node?
152
+
153
+ # Get the parent node
154
+ def parent: () -> Node?
155
+
156
+ # Get the next sibling node
157
+ def next_sibling: () -> Node?
158
+
159
+ # Get the previous sibling node
160
+ def prev_sibling: () -> Node?
161
+
162
+ # Check if node responds to a method (includes delegation to inner_node)
163
+ def respond_to_missing?: (Symbol method_name, ?bool include_private) -> bool
164
+
165
+ # Delegate unknown methods to the underlying backend-specific node
166
+ def method_missing: (Symbol method_name, *untyped args, **untyped kwargs) ?{ () -> untyped } -> untyped
167
+
97
168
  private
98
169
 
99
- def initialize: (untyped impl) -> void
170
+ def initialize: (untyped inner_node, ?source: String?) -> void
171
+ end
172
+
173
+ # Position in source code that works as both object and hash
174
+ class Point
175
+ attr_reader row: Integer
176
+ attr_reader column: Integer
100
177
 
101
- @impl: untyped
178
+ def initialize: (row: Integer, column: Integer) -> void
179
+
180
+ # Hash-style access
181
+ def []: (Symbol key) -> Integer?
182
+
183
+ # Convert to hash
184
+ def to_h: () -> Hash[Symbol, Integer]
185
+
186
+ # String representation
187
+ def inspect: () -> String
102
188
  end
103
189
 
104
190
  # Thread-safe language registrations and cache
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_haver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter H. Boling
@@ -207,9 +207,9 @@ dependencies:
207
207
  - - ">="
208
208
  - !ruby/object:Gem::Version
209
209
  version: 1.0.3
210
- description: "\U0001F334 TreeHaver is a cross-Ruby adapter for the Tree-sitter parsing
210
+ description: "\U0001F334 TreeHaver is a cross-Ruby adapter for the tree-sitter parsing
211
211
  library that works seamlessly across MRI Ruby, JRuby, and TruffleRuby. It provides
212
- a unified API for parsing source code using Tree-sitter grammars, regardless of
212
+ a unified API for parsing source code using tree-sitter grammars, regardless of
213
213
  your Ruby implementation. Like Faraday for HTTP or multi_json for JSON, TreeHaver
214
214
  lets you write once and run anywhere with automatic backend selection (MRI C extensions,
215
215
  Rust extensions, FFI, or Java)."
@@ -240,14 +240,18 @@ files:
240
240
  - RUBOCOP.md
241
241
  - SECURITY.md
242
242
  - lib/tree_haver.rb
243
+ - lib/tree_haver/backends/citrus.rb
243
244
  - lib/tree_haver/backends/ffi.rb
244
245
  - lib/tree_haver/backends/java.rb
245
246
  - lib/tree_haver/backends/mri.rb
246
247
  - lib/tree_haver/backends/rust.rb
248
+ - lib/tree_haver/citrus_grammar_finder.rb
247
249
  - lib/tree_haver/compat.rb
248
250
  - lib/tree_haver/grammar_finder.rb
249
251
  - lib/tree_haver/language_registry.rb
252
+ - lib/tree_haver/node.rb
250
253
  - lib/tree_haver/path_validator.rb
254
+ - lib/tree_haver/tree.rb
251
255
  - lib/tree_haver/version.rb
252
256
  - sig/tree_haver.rbs
253
257
  - sig/tree_haver/backends.rbs
@@ -258,10 +262,10 @@ licenses:
258
262
  - MIT
259
263
  metadata:
260
264
  homepage_uri: https://tree-haver.galtzo.com/
261
- source_code_uri: https://github.com/kettle-rb/tree_haver/tree/v1.0.0
262
- changelog_uri: https://github.com/kettle-rb/tree_haver/blob/v1.0.0/CHANGELOG.md
265
+ source_code_uri: https://github.com/kettle-rb/tree_haver/tree/v3.0.0
266
+ changelog_uri: https://github.com/kettle-rb/tree_haver/blob/v3.0.0/CHANGELOG.md
263
267
  bug_tracker_uri: https://github.com/kettle-rb/tree_haver/issues
264
- documentation_uri: https://www.rubydoc.info/gems/tree_haver/1.0.0
268
+ documentation_uri: https://www.rubydoc.info/gems/tree_haver/3.0.0
265
269
  funding_uri: https://github.com/sponsors/pboling
266
270
  wiki_uri: https://github.com/kettle-rb/tree_haver/wiki
267
271
  news_uri: https://www.railsbling.com/tags/tree_haver
@@ -269,7 +273,7 @@ metadata:
269
273
  rubygems_mfa_required: 'true'
270
274
  rdoc_options:
271
275
  - "--title"
272
- - "tree_haver - \U0001F334 Cross-Ruby adapter for Tree-sitter parsing that works on
276
+ - "tree_haver - \U0001F334 Cross-Ruby adapter for tree-sitter parsing that works on
273
277
  MRI, JRuby, and TruffleRuby"
274
278
  - "--main"
275
279
  - README.md
@@ -293,6 +297,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
297
  requirements: []
294
298
  rubygems_version: 4.0.1
295
299
  specification_version: 4
296
- summary: "\U0001F334 Cross-Ruby adapter for Tree-sitter parsing that works on MRI,
300
+ summary: "\U0001F334 Cross-Ruby adapter for tree-sitter parsing that works on MRI,
297
301
  JRuby, and TruffleRuby"
298
302
  test_files: []
metadata.gz.sig CHANGED
Binary file