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.
- checksums.yaml +4 -4
- data/src/lib.rs +38 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 73a601edb6bb285bf825a5b588c6fb9ae58fa8f1a0bda7c4d537cdfc9f72a912
|
|
4
|
+
data.tar.gz: 331e45aafcaf276595cfa679aa5de2524204b5ba4bcb138d4c1b423471576964
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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))?;
|