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_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());
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 = 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));
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 = JsonPathQuery::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 = JsonPathQuery::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 = JsonPathQuery::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<Automaton<'q>> 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> StructuralEq for Automaton<'q>

source§

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

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.