tree_haver 3.0.0 → 3.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ddc5d837509119a581acd92a33fc7819b6e6dd40a727d1eb0b074d1e944c22f
4
- data.tar.gz: f7b329ee2245068b3bc05e9e6c250e565bbb3b617a50840617f389c2f18dc679
3
+ metadata.gz: ad698ec9d939142aa2fd735e356ee50e83be0b2bc9ac16358f15b48f18d11d13
4
+ data.tar.gz: 51d0e7f2cb6d39bd0e10ffca602e096e86d463ccc38cbce5e0997dce39ca1bb2
5
5
  SHA512:
6
- metadata.gz: 66e9dda1e2638d5340ad99a48959d63002293225a3fc636ea776f5718e0ed388628a4a9fe87c1b0150ae265ec812dd763b1cecfe434044148a1fffc16a9e78b1
7
- data.tar.gz: 9545f9a6b25e6f5944c60b1c7e1a3ecc278cea04c5274b3c34a3d3a0d9d83f14324bda96820286e21ae627c380200866ee47cf6161a12f9bffc9ff72064c3aec
6
+ metadata.gz: 0c0c55b6be53012357cd638e8997f1bd201310e494750b90a82a3f9588fb505a059ead9f056ffc443c424ca2a3cf6370d27e0b508a30faa90a39403bb067cb85
7
+ data.tar.gz: 71d9577716ab0edb436fa784dbfc5d6c81360c745ed98ef156c57475b6cd1f11eccf0030f2565e12d7dcf5035fcdf8fdc2c1eca64f81623109b1318048f41db4
checksums.yaml.gz.sig CHANGED
@@ -1,3 +1,3 @@
1
- �S�����z�'�w�wu|�,�Ƴ� y�Ҥlj�{���xԝ��.��
2
- ��+mb@}Aޞ�����VvD����6@C�~��<��q�^�{@)Z<|pء2���G��S��?��&ᔵS*��)z��Հ�-?m9�ҕ�c���*:|zv�\�a<o�Λ%b��#��u�͞�
3
- ��o�>(>�Uj �BQ� ���N� ��P8%���@z�؀ ��!�ԋ�����l\�n #癝�t��(�E�jw�][8��4�o�B^�*�eqh��1�w]/"J�_�<REi����ˉ��P痛��Z�����u�L��b!P>�����٤��c��s��Vlu<�X�����0�gF�6!5z��8q��n�\(�@���d��n�3�@���} Q�
1
+
2
+ �†' ��w|n`5vi�/��n�@bF��0ZLr�vη �lg�+��W2��S�V��;����H�0�����RD��A�Md ��D^M�}��ŋ"�~,x�兪���W)�UDF�`�͕aWN֚�G����
4
3
  
4
+ � c�>�
data/CHANGELOG.md CHANGED
@@ -30,6 +30,99 @@ Please file a bug if you notice a violation of semantic versioning.
30
30
 
31
31
  ### Security
32
32
 
33
+ ## [3.1.0] - 2025-12-18
34
+
35
+ - TAG: [v3.1.0][3.1.0t]
36
+ - COVERAGE: 82.65% -- 943/1141 lines in 11 files
37
+ - BRANCH COVERAGE: 63.80% -- 349/547 branches in 11 files
38
+ - 88.97% documented
39
+
40
+ ### Added
41
+
42
+ - **Position API Enhancements** – Added consistent position methods to all backend Node classes for compatibility with `*-merge` gems
43
+ - `start_line` - Returns 1-based line number where node starts (converts 0-based `start_point.row` to 1-based)
44
+ - `end_line` - Returns 1-based line number where node ends (converts 0-based `end_point.row` to 1-based)
45
+ - `source_position` - Returns hash `{start_line:, end_line:, start_column:, end_column:}` with 1-based lines and 0-based columns
46
+ - `first_child` - Convenience method that returns `children.first` for iteration compatibility
47
+ - **Fixed:** `TreeHaver::Node#start_point` and `#end_point` now handle both Point objects and hashes from backends (Prism, Citrus return hashes)
48
+ - **Fixed:** Added Psych, Commonmarker, and Markly backends to `resolve_backend_module` and `backend_module` case statements so they can be explicitly selected with `TreeHaver.backend = :psych` etc.
49
+ - **Fixed:** Added Prism, Psych, Commonmarker, and Markly backends to `unwrap_language` method so language objects are properly passed to backend parsers
50
+ - **Fixed:** Commonmarker backend's `text` method now safely handles container nodes that don't have string_content (wraps in rescue TypeError)
51
+ - **Added to:**
52
+ - Main `TreeHaver::Node` wrapper (used by tree-sitter backends: MRI, FFI, Java, Rust)
53
+ - `Backends::Commonmarker::Node` - uses Commonmarker's `sourcepos` (already 1-based)
54
+ - `Backends::Markly::Node` - uses Markly's `source_position` (already 1-based)
55
+ - `Backends::Prism::Node` - uses Prism's `location` (already 1-based)
56
+ - `Backends::Psych::Node` - calculates from `start_point`/`end_point` (0-based)
57
+ - `Backends::Citrus::Node` - calculates from `start_point`/`end_point` (0-based)
58
+ - **Backward Compatible:** Existing `start_point`/`end_point` methods continue to work unchanged
59
+ - **Purpose:** Enables all `*-merge` gems to use consistent position API without backend-specific workarounds
60
+
61
+ - **Prism Backend** – New backend wrapping Ruby's official Prism parser (stdlib in Ruby 3.4+, gem for 3.2+)
62
+ - `TreeHaver::Backends::Prism::Language` - Language wrapper (Ruby-only)
63
+ - `TreeHaver::Backends::Prism::Parser` - Parser with `parse` and `parse_string` methods
64
+ - `TreeHaver::Backends::Prism::Tree` - Tree wrapper with `root_node`, `errors`, `warnings`, `comments`
65
+ - `TreeHaver::Backends::Prism::Node` - Node wrapper implementing full TreeHaver::Node protocol
66
+ - Registered with `:prism` backend name, no conflicts with other backends
67
+
68
+ - **Psych Backend** – New backend wrapping Ruby's standard library YAML parser
69
+ - `TreeHaver::Backends::Psych::Language` - Language wrapper (YAML-only)
70
+ - `TreeHaver::Backends::Psych::Parser` - Parser with `parse` and `parse_string` methods
71
+ - `TreeHaver::Backends::Psych::Tree` - Tree wrapper with `root_node`, `errors`
72
+ - `TreeHaver::Backends::Psych::Node` - Node wrapper implementing TreeHaver::Node protocol
73
+ - Psych-specific methods: `mapping?`, `sequence?`, `scalar?`, `alias?`, `mapping_entries`, `anchor`, `tag`, `value`
74
+ - Registered with `:psych` backend name, no conflicts with other backends
75
+
76
+ - **Commonmarker Backend** – New backend wrapping the Commonmarker gem (comrak Rust parser)
77
+ - `TreeHaver::Backends::Commonmarker::Language` - Language wrapper with parse options passthrough
78
+ - `TreeHaver::Backends::Commonmarker::Parser` - Parser with `parse` and `parse_string` methods
79
+ - `TreeHaver::Backends::Commonmarker::Tree` - Tree wrapper with `root_node`
80
+ - `TreeHaver::Backends::Commonmarker::Node` - Node wrapper implementing TreeHaver::Node protocol
81
+ - Commonmarker-specific methods: `header_level`, `fence_info`, `url`, `title`, `next_sibling`, `previous_sibling`, `parent`
82
+ - Registered with `:commonmarker` backend name, no conflicts with other backends
83
+
84
+ - **Markly Backend** – New backend wrapping the Markly gem (cmark-gfm C library)
85
+ - `TreeHaver::Backends::Markly::Language` - Language wrapper with flags and extensions passthrough
86
+ - `TreeHaver::Backends::Markly::Parser` - Parser with `parse` and `parse_string` methods
87
+ - `TreeHaver::Backends::Markly::Tree` - Tree wrapper with `root_node`
88
+ - `TreeHaver::Backends::Markly::Node` - Node wrapper implementing TreeHaver::Node protocol
89
+ - Type normalization: `:header` → `"heading"`, `:hrule` → `"thematic_break"`, `:html` → `"html_block"`
90
+ - Markly-specific methods: `header_level`, `fence_info`, `url`, `title`, `next_sibling`, `previous_sibling`, `parent`, `raw_type`
91
+ - Registered with `:markly` backend name, no conflicts with other backends
92
+
93
+ - **Automatic Citrus Fallback** – When tree-sitter fails, automatically fall back to Citrus backend
94
+ - `TreeHaver::Language.method_missing` now catches tree-sitter loading errors (`NotAvailable`, `ArgumentError`, `LoadError`, `FFI::NotFoundError`) and falls back to registered Citrus grammar
95
+ - `TreeHaver::Parser#initialize` now catches parser creation errors and falls back to Citrus parser when backend is `:auto`
96
+ - `TreeHaver::Parser#language=` automatically switches to Citrus parser when a Citrus language is assigned
97
+ - Enables seamless use of pure-Ruby parsers (like toml-rb) when tree-sitter runtime is unavailable
98
+
99
+ - **GrammarFinder Runtime Check** – `GrammarFinder#available?` now verifies tree-sitter runtime is actually usable
100
+ - New `GrammarFinder.tree_sitter_runtime_usable?` class method tests if parser can be created
101
+ - `TREE_SITTER_BACKENDS` constant defines which backends use tree-sitter (MRI, FFI, Rust, Java)
102
+ - Prevents registration of grammars when tree-sitter runtime isn't functional
103
+ - `GrammarFinder.reset_runtime_check!` for testing
104
+
105
+ - **Empty ENV Variable as Explicit Skip** – Setting `TREE_SITTER_<LANG>_PATH=''` explicitly disables that grammar
106
+ - Previously, empty string was treated same as unset (would search paths)
107
+ - Now, empty string means "do not use tree-sitter for this language"
108
+ - Allows explicit opt-out to force fallback to alternative backends like Citrus
109
+ - Useful for testing and environments where tree-sitter isn't desired
110
+
111
+ - **TOML Examples** – New example scripts demonstrating TOML parsing with various backends
112
+ - `examples/auto_toml.rb` - Auto backend selection with Citrus fallback demonstration
113
+ - `examples/ffi_toml.rb` - FFI backend with TOML
114
+ - `examples/mri_toml.rb` - MRI backend with TOML
115
+ - `examples/rust_toml.rb` - Rust backend with TOML
116
+ - `examples/java_toml.rb` - Java backend with TOML (JRuby only)
117
+
118
+ ### Fixed
119
+
120
+ - **BREAKING**: `TreeHaver::Language.method_missing` no longer raises `ArgumentError` when only Citrus grammar is registered and tree-sitter backend is active – it now falls back to Citrus instead
121
+ - Previously: Would raise "No grammar registered for :lang compatible with tree_sitter backend"
122
+ - Now: Returns `TreeHaver::Backends::Citrus::Language` if Citrus grammar is registered
123
+ - Migration: If you were catching this error, update your code to handle the fallback behavior
124
+ - This is a bug fix, but would be a breaking change for some users who were relying on the old behavior
125
+
33
126
  ## [3.0.0] - 2025-12-16
34
127
 
35
128
  - TAG: [v3.0.0][3.0.0t]
@@ -272,7 +365,9 @@ Despite the major version bump to 3.0.0 (following semver due to the breaking `L
272
365
 
273
366
  - Initial release
274
367
 
275
- [Unreleased]: https://github.com/kettle-rb/tree_haver/compare/v3.0.0...HEAD
368
+ [Unreleased]: https://github.com/kettle-rb/tree_haver/compare/v3.1.0...HEAD
369
+ [3.1.0]: https://github.com/kettle-rb/tree_haver/compare/v3.0.0...v3.1.0
370
+ [3.1.0t]: https://github.com/kettle-rb/tree_haver/releases/tag/v3.1.0
276
371
  [3.0.0]: https://github.com/kettle-rb/tree_haver/compare/v2.0.0...v3.0.0
277
372
  [3.0.0t]: https://github.com/kettle-rb/tree_haver/releases/tag/v3.0.0
278
373
  [2.0.0]: https://github.com/kettle-rb/tree_haver/compare/v1.0.0...v2.0.0
data/CONTRIBUTING.md CHANGED
@@ -44,9 +44,21 @@ bin/rake -T
44
44
 
45
45
  ## Backend Compatibility Testing
46
46
 
47
- TreeHaver supports multiple backends (MRI, FFI, Rust, Citrus), but not all backends can coexist
48
- in the same Ruby process. Notably, **FFI and MRI backends conflict** at the libtree-sitter runtime
49
- level—using both in the same process will cause segfaults.
47
+ TreeHaver supports multiple backends with different characteristics:
48
+
49
+ - **MRI**: ruby_tree_sitter (C extension, tree-sitter grammars)
50
+ - **FFI**: Pure Ruby FFI bindings (tree-sitter grammars)
51
+ - **Rust**: tree_stump (Rust extension, tree-sitter grammars)
52
+ - **Citrus**: Pure Ruby parser (TOML only via toml-rb grammar)
53
+
54
+ Not all backends can coexist in the same Ruby process. Notably, **FFI and MRI backends conflict**
55
+ at the libtree-sitter runtime level—using both in the same process will cause segfaults.
56
+
57
+ The **Citrus backend** works differently:
58
+ - Uses pure Ruby parsing (no .so files)
59
+ - Currently only supports TOML via toml-rb grammar
60
+ - Can coexist with tree-sitter backends
61
+ - Useful for testing multi-backend scenarios
50
62
 
51
63
  The `bin/backend-matrix` script helps test and document backend compatibility by running tests
52
64
  in isolated subprocesses.
@@ -57,14 +69,21 @@ in isolated subprocesses.
57
69
  # Test all backends with TOML grammar (default)
58
70
  bin/backend-matrix
59
71
 
60
- # Test specific backend order
61
- bin/backend-matrix ffi mri rust
72
+ # Test specific backend order (including Citrus)
73
+ bin/backend-matrix ffi mri rust citrus
74
+
75
+ # Test Citrus with tree-sitter backends
76
+ bin/backend-matrix citrus mri ffi # Citrus before tree-sitter
77
+ bin/backend-matrix mri citrus ffi # Citrus between tree-sitter
62
78
 
63
79
  # Test with a different grammar
64
80
  bin/backend-matrix --grammar=json
65
81
 
66
82
  # Test multiple grammars
67
83
  bin/backend-matrix --grammars=json,toml,bash
84
+
85
+ # Citrus only supports TOML
86
+ bin/backend-matrix --grammar=toml citrus
68
87
  ```
69
88
 
70
89
  ### All Permutations Mode
@@ -72,11 +91,13 @@ bin/backend-matrix --grammars=json,toml,bash
72
91
  Test all possible backend combinations by spawning fresh subprocesses for each:
73
92
 
74
93
  ```shell
75
- # Test all 15 backend combinations (1-backend, 2-backend, 3-backend)
94
+ # Test all 64 backend combinations (4 backends: 4 1-backend + 12 2-backend + 24 3-backend + 24 4-backend)
76
95
  bin/backend-matrix --all-permutations
77
96
 
78
97
  # With multiple grammars
79
98
  bin/backend-matrix --all-permutations --grammars=json,toml
99
+
100
+ # Note: Citrus only supports TOML, so JSON/Bash tests will skip for Citrus
80
101
  ```
81
102
 
82
103
  ### Cross-Grammar Testing
@@ -121,18 +142,23 @@ Example findings:
121
142
 
122
143
  ```
123
144
  Backend Pair Compatibility:
124
- ╭──────────────┬────────────────────┬─────────┬────────╮
125
- │ Backend Pair │ Compatibility │ Working │ Failed │
126
- ├──────────────┼────────────────────┼─────────┼────────┤
127
- │ ffi+mri │ ✗ Incompatible │ 0 │ 8 │
128
- │ mri+rust │ ✓ Fully compatible │ 8 │ 0 │
129
- │ ffi+rust │ ✓ Fully compatible │ 8 │ 0 │
130
- ╰──────────────┴────────────────────┴─────────┴────────╯
145
+ ╭───────────────┬────────────────────┬─────────┬────────╮
146
+ │ Backend Pair │ Compatibility │ Working │ Failed │
147
+ ├───────────────┼────────────────────┼─────────┼────────┤
148
+ │ ffi+mri │ ✗ Incompatible │ 0 │ 8 │
149
+ │ mri+rust │ ✓ Fully compatible │ 8 │ 0 │
150
+ │ ffi+rust │ ✓ Fully compatible │ 8 │ 0 │
151
+ │ citrus+mri │ ✓ Fully compatible │ 2 │ 0 │
152
+ │ citrus+ffi │ ✓ Fully compatible │ 2 │ 0 │
153
+ │ citrus+rust │ ✓ Fully compatible │ 2 │ 0 │
154
+ ╰───────────────┴────────────────────┴─────────┴────────╯
155
+
156
+ Note: Citrus only supports TOML, so it has fewer total combinations.
131
157
  ```
132
158
 
133
159
  ### Required Environment Variables
134
160
 
135
- The script requires grammar paths to be set:
161
+ The script requires grammar paths to be set for tree-sitter backends:
136
162
 
137
163
  ```shell
138
164
  export TREE_SITTER_TOML_PATH=/path/to/libtree-sitter-toml.so
@@ -142,6 +168,12 @@ export TREE_SITTER_BASH_PATH=/path/to/libtree-sitter-bash.so
142
168
 
143
169
  See `.envrc` for examples of how these are typically configured.
144
170
 
171
+ **For Citrus backend:**
172
+ - Requires the `toml-rb` gem (pure Ruby TOML parser)
173
+ - **Auto-installs**: Script uses bundler inline to install `toml-rb` automatically if missing
174
+ - No environment variables needed (doesn't use .so files)
175
+ - Only supports TOML grammar
176
+
145
177
  ## Environment Variables for Local Development
146
178
 
147
179
  Below are the primary environment variables recognized by stone_checksums (and its integrated tools). Unless otherwise noted, set boolean values to the string "true" to enable.