pub struct Automaton { /* private fields */ }
Expand description
A minimal, deterministic automaton representing a JSONPath query.
Implementations§
Source§impl Automaton
impl Automaton
Sourcepub fn new(query: &JsonPathQuery) -> Result<Self, CompilerError>
pub fn new(query: &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_select_root_query(&self) -> bool
pub fn is_select_root_query(&self) -> bool
Returns whether this automaton represents the select-root JSONPath query (‘$’).
§Examples
let query = rsonpath_syntax::parse("$").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(automaton.is_select_root_query());
let query = rsonpath_syntax::parse("$.a").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(!automaton.is_select_root_query());
Sourcepub fn is_empty_query(&self) -> bool
pub fn is_empty_query(&self) -> bool
Returns whether this automaton represents an empty JSONPath query that cannot accept anything.
A query like this can be created by, for example, putting a trivially false filter or an empty slice into the query.
§Examples
let query = rsonpath_syntax::parse("$[::0]").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(automaton.is_empty_query());
let query = rsonpath_syntax::parse("$").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 = rsonpath_syntax::parse("$.a").unwrap();
let automaton = Automaton::new(&query).unwrap();
let state_2 = automaton[automaton.initial_state()].member_transitions()[0].1;
assert!(automaton.is_accepting(state_2));
Sourcepub fn has_any_array_item_transition(&self, state: State) -> bool
pub fn has_any_array_item_transition(&self, state: State) -> bool
Returns whether the given state transitions to any list.
§Example
let query = rsonpath_syntax::parse("$[2]").unwrap();
let automaton = Automaton::new(&query).unwrap();
let state = automaton.initial_state();
assert!(automaton.has_any_array_item_transition(state));
Sourcepub fn has_first_array_index_transition_to_accepting(
&self,
state: State,
) -> bool
pub fn has_first_array_index_transition_to_accepting( &self, state: State, ) -> bool
Returns whether the given state is accepting the first item in a list.
§Example
let query = rsonpath_syntax::parse("$[0]").unwrap();
let automaton = Automaton::new(&query).unwrap();
let state = automaton.initial_state();
assert!(automaton.has_first_array_index_transition_to_accepting(state));
let query = rsonpath_syntax::parse("$[1]").unwrap();
let automaton = Automaton::new(&query).unwrap();
let state = automaton.initial_state();
assert!(!automaton.has_first_array_index_transition_to_accepting(state));
Sourcepub fn has_array_index_transition_to_accepting(
&self,
state: State,
match_index: &JsonUInt,
) -> bool
pub fn has_array_index_transition_to_accepting( &self, state: State, match_index: &JsonUInt, ) -> bool
Returns whether the given state is accepting the item at a given index in a list.
§Example
let query = rsonpath_syntax::parse("$[1]").unwrap();
let automaton = Automaton::new(&query).unwrap();
let state = automaton.initial_state();
let match_index_1 = JsonUInt::try_from(1).unwrap();
let match_index_2 = JsonUInt::try_from(2).unwrap();
assert!(automaton.has_array_index_transition_to_accepting(state, &match_index_1));
assert!(!automaton.has_array_index_transition_to_accepting(state, &match_index_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 = rsonpath_syntax::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 = rsonpath_syntax::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 = rsonpath_syntax::parse("$.a").unwrap();
let automaton = Automaton::new(&query).unwrap();
assert!(automaton.is_unitary(automaton.initial_state()));