tree_sitter_language_pack 1.2.1 → 1.3.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/src/lib.rs +38 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e39e2e8f16d680a03503e0fc7a5340cc8900a9c11250d423dcafc70dbb38a308
4
- data.tar.gz: 22863be51d8d97eef161733d4864edac0a07ad96cef21672b3e4da9950c039c4
3
+ metadata.gz: 73a601edb6bb285bf825a5b588c6fb9ae58fa8f1a0bda7c4d537cdfc9f72a912
4
+ data.tar.gz: 331e45aafcaf276595cfa679aa5de2524204b5ba4bcb138d4c1b423471576964
5
5
  SHA512:
6
- metadata.gz: 6e9afb8bbf4644808bac37295187463bbc9d8f702fc6e3e239a530044e31d95e57f966b1d97e6c8077832102edc439c19bbfc0261cb7aaedd16fba931b6e014b
7
- data.tar.gz: 9248459136e6233d742c6832618663cc5bb209d0b56e583abcc45f0ba1aae9bc3ebd56e75cba149dbf92b8e061fa3c8db9637a56770c4f113a3b3a530edd42f6
6
+ metadata.gz: e197f722769c8cbb45aabbe38d713bfb234036c74d523d521041814916e5518ef6f4acd5c6b66ab0f1317404d7fc608b5043915aa93331c876769363674627d8
7
+ data.tar.gz: b3efc14816133eec048d9a988fba3b0620a991a3d3c9426eb6968bdce14925d6eeaa20bfb4394d0e561f828f7661e720d344cff09ec3bd421dc2697aa0fcc752
data/src/lib.rs CHANGED
@@ -100,6 +100,42 @@ fn process(ruby: &Ruby, source: String, config_json: String) -> Result<String, E
100
100
  .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("serialization failed: {e}")))
101
101
  }
102
102
 
103
+ /// Extract patterns from source code using a JSON configuration.
104
+ ///
105
+ /// The config JSON must contain:
106
+ /// - `language` (string): the language name
107
+ /// - `patterns` (object): named patterns to run, each with a `query` field
108
+ ///
109
+ /// Returns a JSON string with extraction results.
110
+ fn extract(ruby: &Ruby, source: String, config_json: String) -> Result<String, Error> {
111
+ let config: tree_sitter_language_pack::ExtractionConfig = serde_json::from_str(&config_json)
112
+ .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
113
+
114
+ let result = tree_sitter_language_pack::extract_patterns(&source, &config)
115
+ .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))?;
116
+
117
+ serde_json::to_string(&result)
118
+ .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("serialization failed: {e}")))
119
+ }
120
+
121
+ /// Validate extraction patterns without running them.
122
+ ///
123
+ /// The config JSON must contain:
124
+ /// - `language` (string): the language name
125
+ /// - `patterns` (object): named patterns to validate
126
+ ///
127
+ /// Returns a JSON string with validation results.
128
+ fn validate_extraction(ruby: &Ruby, config_json: String) -> Result<String, Error> {
129
+ let config: tree_sitter_language_pack::ExtractionConfig = serde_json::from_str(&config_json)
130
+ .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("invalid config JSON: {e}")))?;
131
+
132
+ let result = tree_sitter_language_pack::validate_extraction(&config)
133
+ .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("{e}")))?;
134
+
135
+ serde_json::to_string(&result)
136
+ .map_err(|e| Error::new(ruby.exception_runtime_error(), format!("serialization failed: {e}")))
137
+ }
138
+
103
139
  /// Initialize the language pack with configuration.
104
140
  ///
105
141
  /// Accepts a JSON string with optional fields:
@@ -187,6 +223,8 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
187
223
  module.define_module_function("get_language_ptr", function!(get_language_ptr, 1))?;
188
224
  module.define_module_function("parse_string", function!(parse_string, 2))?;
189
225
  module.define_module_function("process", function!(process, 2))?;
226
+ module.define_module_function("extract", function!(extract, 2))?;
227
+ module.define_module_function("validate_extraction", function!(validate_extraction, 1))?;
190
228
 
191
229
  // Download API functions
192
230
  module.define_module_function("init", function!(rb_init, 1))?;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_sitter_language_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kreuzberg.dev