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.rs | 19 |
1 files changed, 19 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..037644b9 --- /dev/null +++ b/helix-syntax/src/tree_sitter/query/property.rs @@ -0,0 +1,19 @@ +use crate::tree_sitter::query::predicate::{InvalidPredicateError, Predicate}; +use crate::tree_sitter::query::QueryStr; + +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.str_arg(0)?; + let val = (predicate.num_args() == 1) + .then(|| predicate.str_arg(1)) + .transpose()?; + Ok(QueryProperty { key, val }) + } +} |