1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! # QueryParser - parsing Methods
//!
//! This module contains method implementations for `QueryParser`.
//!
//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
use crate::algebra::PropertyPath;
use anyhow::Result;
use super::types::Token;
use super::queryparser_type::QueryParser;
impl QueryParser {
/// Parse property path sequences
pub(super) fn parse_property_path_sequence(&mut self) -> Result<PropertyPath> {
let mut left = self.parse_property_path_postfix()?;
// The lexer emits `/` as `Token::Divide` (its arithmetic spelling); in a
// property-path position it is the sequence operator, never division, so
// accept it here. (`Token::Slash` is retained for safety though the
// current lexer never produces it.)
while matches!(self.peek(), Some(Token::Slash) | Some(Token::Divide)) {
self.advance();
let right = self.parse_property_path_postfix()?;
left = PropertyPath::sequence(left, right);
}
Ok(left)
}
/// Parse property path with postfix operators (*, +, ?)
pub(super) fn parse_property_path_postfix(&mut self) -> Result<PropertyPath> {
let mut path = self.parse_property_path_primary()?;
loop {
match self.peek() {
Some(Token::Star) => {
self.advance();
path = PropertyPath::zero_or_more(path);
}
Some(Token::Plus) => {
self.advance();
path = PropertyPath::one_or_more(path);
}
Some(Token::Question) => {
self.advance();
path = PropertyPath::zero_or_one(path);
}
_ => break,
}
}
Ok(path)
}
}