tree_haver 3.2.3 → 3.2.5
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
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +193 -3
- data/README.md +189 -69
- data/lib/tree_haver/backend_api.rb +349 -0
- data/lib/tree_haver/backends/citrus.rb +37 -8
- data/lib/tree_haver/backends/commonmarker.rb +31 -6
- data/lib/tree_haver/backends/java.rb +160 -22
- data/lib/tree_haver/backends/markly.rb +34 -4
- data/lib/tree_haver/backends/prism.rb +21 -8
- data/lib/tree_haver/backends/psych.rb +24 -0
- data/lib/tree_haver/language_registry.rb +57 -3
- data/lib/tree_haver/node.rb +15 -1
- data/lib/tree_haver/rspec/dependency_tags.rb +249 -23
- data/lib/tree_haver/version.rb +1 -1
- data/lib/tree_haver.rb +291 -22
- data.tar.gz.sig +0 -0
- metadata +5 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5491d352853baeea6501864dec4d703cfd57fea279d6e16edf104c2f1d533c90
|
|
4
|
+
data.tar.gz: 5c71898a5022f0459bc502bfeb977d7fc7e909ffb3fd0c30fe0b4e2055811fe9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3ebc956fca1d0e57925f3a152aa2465bb0b86c5fcb0fc1622fe0f038d00214d38c04cb2c52bdbb08250074d48bbd2096353bf14d5d70a0b3a7ae9b58997e79a
|
|
7
|
+
data.tar.gz: 53192de159ce84a508b9795a866ab01ea23af4de7f9b8c4f2be077a7dff1cc394959462926a948a89c84670668beb2a7c2b5eac9f735c39ffabc6f99c6fe9cbb
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
**# Changelog
|
|
2
2
|
|
|
3
3
|
[![SemVer 2.0.0][📌semver-img]][📌semver] [![Keep-A-Changelog 1.0.0][📗keep-changelog-img]][📗keep-changelog]
|
|
4
4
|
|
|
@@ -30,6 +30,192 @@ Please file a bug if you notice a violation of semantic versioning.
|
|
|
30
30
|
|
|
31
31
|
### Security
|
|
32
32
|
|
|
33
|
+
## [3.2.5] - 2026-01-05
|
|
34
|
+
|
|
35
|
+
- TAG: [v3.2.5][3.2.5t]
|
|
36
|
+
- COVERAGE: 92.07% -- 2230/2422 lines in 23 files
|
|
37
|
+
- BRANCH COVERAGE: 74.69% -- 788/1055 branches in 23 files
|
|
38
|
+
- 90.37% documented
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
|
|
42
|
+
- **Markly backend**: `Node#text` now correctly handles container nodes (headings, paragraphs, etc.)
|
|
43
|
+
- Previously returned empty string because `string_content` was checked first (responds but returns empty for containers)
|
|
44
|
+
- Now falls through to `to_plaintext` or children concatenation when `string_content` is empty
|
|
45
|
+
- **Commonmarker backend**: `Node#text` now correctly handles container nodes
|
|
46
|
+
- Previously could return empty string in edge cases
|
|
47
|
+
- Now consistently falls through to children concatenation when `string_content` is empty or raises TypeError
|
|
48
|
+
|
|
49
|
+
## [3.2.4] - 2026-01-04
|
|
50
|
+
|
|
51
|
+
- TAG: [v3.2.4][3.2.4t]
|
|
52
|
+
- COVERAGE: 92.07% -- 2229/2421 lines in 23 files
|
|
53
|
+
- BRANCH COVERAGE: 74.79% -- 786/1051 branches in 23 files
|
|
54
|
+
- 90.37% documented
|
|
55
|
+
|
|
56
|
+
### Added
|
|
57
|
+
|
|
58
|
+
- **External backend registration via `backend_module`** - External gems can now register
|
|
59
|
+
their own pure Ruby backends using the same API as built-in backends. This enables gems
|
|
60
|
+
like rbs-merge to integrate with `TreeHaver.parser_for` without modifying tree_haver:
|
|
61
|
+
```ruby
|
|
62
|
+
TreeHaver.register_language(
|
|
63
|
+
:rbs,
|
|
64
|
+
backend_module: Rbs::Merge::Backends::RbsBackend,
|
|
65
|
+
backend_type: :rbs,
|
|
66
|
+
gem_name: "rbs",
|
|
67
|
+
)
|
|
68
|
+
# Now TreeHaver.parser_for(:rbs) works!
|
|
69
|
+
```
|
|
70
|
+
- **`Backends::PURE_RUBY_BACKENDS` constant** - Maps pure Ruby backend names to their
|
|
71
|
+
language and module info. Used for auto-registration of built-in backends.
|
|
72
|
+
- **`TreeHaver.register_builtin_backends!`** - Registers built-in pure Ruby backends
|
|
73
|
+
(Prism, Psych, Commonmarker, Markly) in the LanguageRegistry using the same API that
|
|
74
|
+
external backends use. Called automatically by `parser_for` on first use.
|
|
75
|
+
- **`TreeHaver.ensure_builtin_backends_registered!`** - Idempotent helper that ensures
|
|
76
|
+
built-in backends are registered exactly once.
|
|
77
|
+
- **`parser_for` now supports registered `backend_module` backends** - When a language
|
|
78
|
+
has a registered `backend_module`, `parser_for` will use it. This enables external
|
|
79
|
+
gems to provide language support without tree-sitter grammars:
|
|
80
|
+
- Checks LanguageRegistry for registered `backend_module` entries
|
|
81
|
+
- Creates parser from the backend module's `Parser` and `Language` classes
|
|
82
|
+
- Falls back to tree-sitter and Citrus if no backend_module matches
|
|
83
|
+
- **RBS dependency tags in `DependencyTags`** - New RSpec tags for RBS parsing:
|
|
84
|
+
- `:rbs_grammar` - tree-sitter-rbs grammar is available and parsing works
|
|
85
|
+
- `:rbs_parsing` - at least one RBS parser (rbs gem OR tree-sitter-rbs) is available
|
|
86
|
+
- `:rbs_gem` - the official rbs gem is available (MRI only)
|
|
87
|
+
- Negated versions: `:not_rbs_grammar`, `:not_rbs_parsing`, `:not_rbs_gem`
|
|
88
|
+
- New availability methods: `tree_sitter_rbs_available?`, `rbs_gem_available?`, `any_rbs_backend_available?`
|
|
89
|
+
- **Support for tree-sitter 0.26.x ABI** - TreeHaver now fully supports grammars built
|
|
90
|
+
against tree-sitter 0.26.x (LANGUAGE_VERSION 15). This required updates to vendored
|
|
91
|
+
dependencies:
|
|
92
|
+
- **ruby-tree-sitter**: Updated to support tree-sitter 0.26.3 C library API changes
|
|
93
|
+
including new `ts_language_abi_version()` function, UTF-16 encoding split, and
|
|
94
|
+
removal of deprecated parser timeout/cancellation APIs
|
|
95
|
+
- **tree_stump (Rust backend)**: Updated to tree-sitter Rust crate 0.26.3 with new
|
|
96
|
+
`abi_version()` method, `u32` child indices, and streaming iterator-based query matches
|
|
97
|
+
- **MRI backend now loads grammars with LANGUAGE_VERSION 15** - Previously, MRI backend
|
|
98
|
+
using ruby_tree_sitter could only load grammars with LANGUAGE_VERSION ≤ 14. Now supports
|
|
99
|
+
grammars built against tree-sitter 0.26.x.
|
|
100
|
+
- **Rust backend now loads grammars with LANGUAGE_VERSION 15** - Previously, the tree_stump
|
|
101
|
+
Rust backend reported "Incompatible language version 15. Expected minimum 13, maximum 14".
|
|
102
|
+
Now supports the latest grammar format.
|
|
103
|
+
- **BackendAPI validation module** - New `TreeHaver::BackendAPI` module for validating
|
|
104
|
+
backend API compliance:
|
|
105
|
+
- `BackendAPI.validate(backend_module)` - Returns validation results hash
|
|
106
|
+
- `BackendAPI.validate!(backend_module)` - Raises on validation failure
|
|
107
|
+
- `BackendAPI.validate_node_instance(node)` - Validates a node instance
|
|
108
|
+
- Defines required and optional methods for Language, Parser, Tree, and Node classes
|
|
109
|
+
- Documents API contract for wrapper vs raw backends
|
|
110
|
+
- New `examples/validate_backends.rb` script to validate all backends
|
|
111
|
+
- **Java backend Node class now implements full API** - Added missing methods to ensure
|
|
112
|
+
API consistency with other backends:
|
|
113
|
+
- `parent` - Get parent node
|
|
114
|
+
- `next_sibling` - Get next sibling node
|
|
115
|
+
- `prev_sibling` - Get previous sibling node
|
|
116
|
+
- `named?` - Check if node is named
|
|
117
|
+
- `child_by_field_name` - Get child by field name
|
|
118
|
+
- All methods properly handle jtreesitter 0.26.0's `Optional<Node>` return types
|
|
119
|
+
- **Three environment variables for backend control** - Fine-grained control over which
|
|
120
|
+
backends are available:
|
|
121
|
+
- `TREE_HAVER_BACKEND` - Single backend selection (auto, mri, ffi, rust, java, citrus, etc.)
|
|
122
|
+
- `TREE_HAVER_NATIVE_BACKEND` - Allow list for native backends (auto, none, or comma-separated
|
|
123
|
+
list like `mri,ffi`). Use `none` for pure-Ruby-only mode.
|
|
124
|
+
- `TREE_HAVER_RUBY_BACKEND` - Allow list for pure Ruby backends (auto, none, or comma-separated
|
|
125
|
+
list like `citrus,prism`). Use `none` for native-only mode.
|
|
126
|
+
- **Backend availability now respects allow lists** - When `TREE_HAVER_NATIVE_BACKEND` is set
|
|
127
|
+
to specific backends (e.g., `mri,ffi`), all other native backends are treated as unavailable.
|
|
128
|
+
This applies to ALL backend selection mechanisms:
|
|
129
|
+
- Auto-selection in `backend_module`
|
|
130
|
+
- Explicit selection via `with_backend(:rust)` - returns nil/unavailable
|
|
131
|
+
- Explicit selection via `resolve_backend_module(:rust)` - returns nil
|
|
132
|
+
- RSpec dependency tags (`ffi_available?`, etc.)
|
|
133
|
+
|
|
134
|
+
This makes the environment variables a **hard restriction**, not just a hint for auto-selection.
|
|
135
|
+
Use `TREE_HAVER_NATIVE_BACKEND=none` for pure-Ruby-only mode, or specify exactly which
|
|
136
|
+
native backends are permitted (e.g., `mri,ffi`).
|
|
137
|
+
- **Java backend updated for jtreesitter 0.26.0** - Full compatibility with jtreesitter 0.26.0:
|
|
138
|
+
- Updated `Parser#parse` and `Parser#parse_string` to handle `Optional<Tree>` return type
|
|
139
|
+
- Updated `Tree#root_node` to handle `Optional<Node>` return type
|
|
140
|
+
- Fixed `parse_string` argument order to match jtreesitter 0.26.0 API: `parse(String, Tree)`
|
|
141
|
+
- Updated `Language.load_by_name` to use `SymbolLookup` API (single-arg `load(name)` removed)
|
|
142
|
+
- Added `bin/setup-jtreesitter` script to download jtreesitter JAR from Maven Central
|
|
143
|
+
- Added `bin/build-grammar` script to build tree-sitter grammars from source
|
|
144
|
+
- Older versions of jtreesitter are NOT supported
|
|
145
|
+
- **`TREE_HAVER_BACKEND_PROTECT` environment variable** - Explicit control over backend
|
|
146
|
+
conflict protection. Set to `false` to disable protection that prevents mixing
|
|
147
|
+
incompatible native backends (e.g., FFI after MRI). Useful for testing scenarios
|
|
148
|
+
where you understand the risks. Default behavior (protection enabled) unchanged.
|
|
149
|
+
|
|
150
|
+
### Changed
|
|
151
|
+
|
|
152
|
+
- **API normalized: `from_library` is now universal** - All language-specific backends
|
|
153
|
+
(Psych, Prism, Commonmarker, Markly) now implement `Language.from_library` for API
|
|
154
|
+
consistency. This allows `TreeHaver.parser_for(:yaml)` to work uniformly regardless
|
|
155
|
+
of which backend is active:
|
|
156
|
+
- **Psych**: `from_library` accepts (and ignores) path/symbol, returns YAML language
|
|
157
|
+
- **Prism**: `from_library` accepts (and ignores) path/symbol, returns Ruby language
|
|
158
|
+
- **Commonmarker**: `from_library` accepts (and ignores) path/symbol, returns Markdown language
|
|
159
|
+
- **Markly**: `from_library` accepts (and ignores) path/symbol, returns Markdown language
|
|
160
|
+
- All raise `TreeHaver::NotAvailable` if a different language is requested
|
|
161
|
+
- **Citrus backend `from_library` now looks up registered grammars** - Instead of always
|
|
162
|
+
raising an error, `Backends::Citrus::Language.from_library` now looks up registered
|
|
163
|
+
Citrus grammars by name via `LanguageRegistry`. This enables `TreeHaver.parser_for(:toml)`
|
|
164
|
+
to work seamlessly when a Citrus grammar has been registered with
|
|
165
|
+
`TreeHaver.register_language(:toml, grammar_module: TomlRB::Document)`.
|
|
166
|
+
- **Java backend requires jtreesitter >= 0.26.0** - Due to API changes in jtreesitter,
|
|
167
|
+
older versions are no longer supported. The tree-sitter runtime library must also be
|
|
168
|
+
version 0.26.x to match.
|
|
169
|
+
by the RSpec dependency tags. This ensures tests tagged with `:mri_backend` only run when
|
|
170
|
+
MRI is in the allow list. Same for `TREE_HAVER_RUBY_BACKEND` and pure Ruby backends.
|
|
171
|
+
- New `TreeHaver.allowed_native_backends` method returns the allow list for native backends.
|
|
172
|
+
- New `TreeHaver.allowed_ruby_backends` method returns the allow list for pure Ruby backends.
|
|
173
|
+
- New `TreeHaver.backend_allowed?(backend)` method checks if a specific backend is allowed
|
|
174
|
+
based on the current environment variable settings.
|
|
175
|
+
- New `DependencyTags.allowed_native_backends` and `DependencyTags.allowed_ruby_backends` methods.
|
|
176
|
+
- Updated `examples/test_backend_selection.rb` script to test all three environment variables.
|
|
177
|
+
- **`LanguageRegistry` now supports any backend type** - Previously only `:tree_sitter` and
|
|
178
|
+
`:citrus` were documented. Now supports arbitrary backend types including `:prism`, `:psych`,
|
|
179
|
+
`:commonmarker`, `:markly`, `:rbs`, or any custom type. External gems can register their
|
|
180
|
+
own backend types using the same API.
|
|
181
|
+
- **`register_language` accepts `backend_module` parameter** - New parameter for registering
|
|
182
|
+
pure Ruby backends. The module must provide `Language` and `Parser` classes with the
|
|
183
|
+
standard TreeHaver API (`available?`, `capabilities`, `from_library`, etc.).
|
|
184
|
+
|
|
185
|
+
### Fixed
|
|
186
|
+
|
|
187
|
+
- **`TreeHaver::Node#text` now handles backends with different `text` method signatures** -
|
|
188
|
+
Previously, `Node#text` would call `@inner_node.text` directly, but `TreeStump::Node#text`
|
|
189
|
+
(Rust backend) requires the source as an argument (`text(source)`). This caused
|
|
190
|
+
`ArgumentError: wrong number of arguments (given 0, expected 1)` when using the Rust
|
|
191
|
+
backend. Now `Node#text` checks the method arity and passes the source when required:
|
|
192
|
+
- Arity 0 or -1: calls `@inner_node.text` without arguments
|
|
193
|
+
- Arity >= 1: calls `@inner_node.text(@source)` with source
|
|
194
|
+
- Falls back to byte-based extraction if source is available
|
|
195
|
+
|
|
196
|
+
- **AUTO mode now gracefully falls back when explicitly requested backend is blocked** -
|
|
197
|
+
Previously, if `TREE_HAVER_BACKEND=ffi` was set in the environment but FFI was blocked
|
|
198
|
+
due to MRI being used first (backend conflict protection), `parser_for` would raise a
|
|
199
|
+
`BackendConflict` error. Now, when the explicitly requested backend is blocked by a
|
|
200
|
+
**backend conflict** (e.g., FFI after MRI causes segfaults):
|
|
201
|
+
- `backend_module` detects the conflict and falls back to auto-selection
|
|
202
|
+
- `resolve_native_backend_module` rescues `BackendConflict` and continues to the next
|
|
203
|
+
backend in the priority list
|
|
204
|
+
- This enables seamless multi-backend usage in test suites where different tests use
|
|
205
|
+
different backends, but one backend has already "poisoned" the process for another.
|
|
206
|
+
|
|
207
|
+
Note: This fallback only applies to **backend conflicts** (runtime incompatibility).
|
|
208
|
+
If a backend is disallowed by `TREE_HAVER_NATIVE_BACKEND` or `TREE_HAVER_RUBY_BACKEND`,
|
|
209
|
+
it will simply be unavailable—no error is raised, but no fallback occurs either.
|
|
210
|
+
|
|
211
|
+
- **`java_backend_available?` now verifies grammar loading works** - Previously, the
|
|
212
|
+
`DependencyTags.java_backend_available?` method only checked if java-tree-sitter
|
|
213
|
+
classes could be loaded, but didn't verify that grammars could actually be used.
|
|
214
|
+
This caused tests tagged with `:java_backend` to run on JRuby even when the grammar
|
|
215
|
+
`.so` files (built for MRI) were incompatible with java-tree-sitter's Foreign Function
|
|
216
|
+
Memory API. Now the check does a live test by attempting to load a grammar, ensuring
|
|
217
|
+
the tag accurately reflects whether the Java backend is fully functional.
|
|
218
|
+
|
|
33
219
|
## [3.2.3] - 2026-01-02
|
|
34
220
|
|
|
35
221
|
- TAG: [v3.2.3][3.2.3t]
|
|
@@ -715,7 +901,11 @@ Despite the major version bump to 3.0.0 (following semver due to the breaking `L
|
|
|
715
901
|
|
|
716
902
|
- Initial release
|
|
717
903
|
|
|
718
|
-
[Unreleased]: https://github.com/kettle-rb/tree_haver/compare/v3.2.
|
|
904
|
+
[Unreleased]: https://github.com/kettle-rb/tree_haver/compare/v3.2.5...HEAD
|
|
905
|
+
[3.2.5]: https://github.com/kettle-rb/tree_haver/compare/v3.2.4...v3.2.5
|
|
906
|
+
[3.2.5t]: https://github.com/kettle-rb/tree_haver/releases/tag/v3.2.5
|
|
907
|
+
[3.2.4]: https://github.com/kettle-rb/tree_haver/compare/v3.2.3...v3.2.4
|
|
908
|
+
[3.2.4t]: https://github.com/kettle-rb/tree_haver/releases/tag/v3.2.4
|
|
719
909
|
[3.2.3]: https://github.com/kettle-rb/tree_haver/compare/v3.2.2...v3.2.3
|
|
720
910
|
[3.2.3t]: https://github.com/kettle-rb/tree_haver/releases/tag/v3.2.3
|
|
721
911
|
[3.2.2]: https://github.com/kettle-rb/tree_haver/compare/v3.2.1...v3.2.2
|
|
@@ -735,4 +925,4 @@ Despite the major version bump to 3.0.0 (following semver due to the breaking `L
|
|
|
735
925
|
[2.0.0]: https://github.com/kettle-rb/tree_haver/compare/v1.0.0...v2.0.0
|
|
736
926
|
[2.0.0t]: https://github.com/kettle-rb/tree_haver/releases/tag/v2.0.0
|
|
737
927
|
[1.0.0]: https://github.com/kettle-rb/tree_haver/compare/a89211bff10f4440b96758a8ac9d7d539001b0c8...v1.0.0
|
|
738
|
-
[1.0.0t]: https://github.com/kettle-rb/tree_haver/tags/v1.0.0
|
|
928
|
+
[1.0.0t]: https://github.com/kettle-rb/tree_haver/tags/v1.0.0**
|