Struct Automaton

Source
pub struct Automaton { /* private fields */ }
Expand description

A minimal, deterministic automaton representing a JSONPath query.

Implementations§

Source§

impl Automaton

Source

pub fn new(query: &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 Clone for Automaton

Source§

fn clone(&self) -> Automaton

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Automaton

Source§

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

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

impl<'de> Deserialize<'de> for Automaton

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Automaton

Source§

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

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

impl Index<State> for Automaton

Source§

type Output = StateTable

The returned type after indexing.
Source§

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

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

impl PartialEq for Automaton

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Automaton

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Automaton

Source§

impl StructuralPartialEq for Automaton

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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>,

Source§

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,