pub struct Automaton<'q> { /* private fields */ }
Expand description

A minimal, deterministic automaton representing a JSONPath query.

Implementations§

source§

impl<'q> Automaton<'q>

source

pub fn new(query: &'q JsonPathQuery) -> Result<Self, CompilerError>

Convert a JsonPathQuery into a minimal deterministic automaton.

§Errors
source

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());
source

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());
source

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.

source

pub fn initial_state(&self) -> State

Returns the initial state of the automaton.

Query execution should start from this state.

source

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));
source

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));
source

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));
source

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));
source

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()));
source

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()));
source

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()));

Trait Implementations§

source§

impl<'q> Debug for Automaton<'q>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'q> Display for Automaton<'q>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'q> Index<State> for Automaton<'q>

§

type Output = StateTable<'q>

The returned type after indexing.
source§

fn index(&self, index: State) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<'q> PartialEq for Automaton<'q>

source§

fn eq(&self, other: &Automaton<'q>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'q> Eq for Automaton<'q>

source§

impl<'q> StructuralPartialEq for Automaton<'q>

Auto Trait Implementations§

§

impl<'q> Freeze for Automaton<'q>

§

impl<'q> RefUnwindSafe for Automaton<'q>

§

impl<'q> Send for Automaton<'q>

§

impl<'q> Sync for Automaton<'q>

§

impl<'q> Unpin for Automaton<'q>

§

impl<'q> UnwindSafe for Automaton<'q>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.