Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-syntax/src/tree_sitter/query/property.rs')
-rw-r--r--helix-syntax/src/tree_sitter/query/property.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/helix-syntax/src/tree_sitter/query/property.rs b/helix-syntax/src/tree_sitter/query/property.rs
new file mode 100644
index 00000000..53f162c5
--- /dev/null
+++ b/helix-syntax/src/tree_sitter/query/property.rs
@@ -0,0 +1,20 @@
+use crate::tree_sitter::query::predicate::{InvalidPredicateError, Predicate};
+use crate::tree_sitter::query::QueryStr;
+
+#[derive(Debug)]
+pub struct QueryProperty {
+ pub key: QueryStr,
+ pub val: Option<QueryStr>,
+}
+
+impl QueryProperty {
+ pub fn parse(predicate: &Predicate) -> Result<Self, InvalidPredicateError> {
+ predicate.check_min_arg_count(1)?;
+ predicate.check_max_arg_count(2)?;
+ let key = predicate.query_str_arg(0)?;
+ let val = (predicate.num_args() == 1)
+ .then(|| predicate.query_str_arg(1))
+ .transpose()?;
+ Ok(QueryProperty { key, val })
+ }
+}