Struct rsonpath_lib::query::automaton::Automaton
source · pub struct Automaton<'q> { /* private fields */ }
Expand description
A minimal, deterministic automaton representing a JSONPath query.
Implementations§
source§impl<'q> Automaton<'q>
impl<'q> Automaton<'q>
sourcepub fn new(query: &'q JsonPathQuery) -> Result<Self, CompilerError>
pub fn new(query: &'q JsonPathQuery) -> Result<Self, CompilerError>
Convert a JsonPathQuery
into a minimal deterministic automaton.
Errors
CompilerError::QueryTooComplex
raised if the query is too complex and the automaton size was exceeded.CompilerError::NotSupported
raised if the query contains elements not yet supported by the compiler.
sourcepub fn is_empty_query(&self) -> bool
pub fn is_empty_query(&self) -> bool
Returns whether this automaton represents an empty JSONPath query (‘$’).
Examples
let query = JsonPathQuery::parse("$").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(automaton.is_empty_query());
let query = JsonPathQuery::parse("$.a").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(!automaton.is_empty_query());
sourcepub fn rejecting_state(&self) -> State
pub fn rejecting_state(&self) -> State
Returns the rejecting state of the automaton.
The state is defined as the unique state from which there exists no accepting run. If the query automaton reaches this state, the current subtree is guaranteed to have no matches.
sourcepub fn initial_state(&self) -> State
pub fn initial_state(&self) -> State
Returns the initial state of the automaton.
Query execution should start from this state.
sourcepub fn is_accepting(&self, state: State) -> bool
pub fn is_accepting(&self, state: State) -> bool
Returns whether the given state is accepting.
Example
let query = JsonPathQuery::parse("$.a").unwrap();
let automaton = Automaton::new(&query).unwrap();
let state_2 = automaton[automaton.initial_state()].transitions()[0].1;
assert!(automaton.is_accepting(state_2));
sourcepub fn has_transition_to_accepting(&self, state: State) -> bool
pub fn has_transition_to_accepting(&self, state: State) -> bool
Returns whether the given state has any transitions (labelled or fallback) to an accepting state.
Example
let query = JsonPathQuery::parse("$.a").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(automaton.has_transition_to_accepting(automaton.initial_state()));
sourcepub fn is_rejecting(&self, state: State) -> bool
pub fn is_rejecting(&self, state: State) -> bool
Returns whether the given state is rejecting, i.e. there exist no accepting runs from it.
Example
let query = JsonPathQuery::parse("$.a").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(automaton.is_rejecting(automaton.rejecting_state()));
sourcepub fn is_unitary(&self, state: State) -> bool
pub fn is_unitary(&self, state: State) -> bool
Returns whether the given state is unitary. A unitary state is one that has exactly one labelled transition and its fallback targets the rejecting state.
Intuitively, there exists only one label that progresses towards acceptance from this state.
Example
let query = JsonPathQuery::parse("$.a").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(automaton.is_unitary(automaton.initial_state()));