BuildGraph

Struct BuildGraph 

Source
pub struct BuildGraph<'src> { /* private fields */ }
Expand description

Build-time graph for query compilation.

Nodes are stored in a flat vector, referenced by NodeId. Definitions map names to their entry points.

Implementations§

Source§

impl<'src> BuildGraph<'src>

Source

pub fn new() -> Self

Source

pub fn add_node(&mut self, node: BuildNode<'src>) -> NodeId

Source

pub fn add_epsilon(&mut self) -> NodeId

Source

pub fn clone_node_with_nav(&mut self, node_id: NodeId, nav: Nav) -> NodeId

Clone a node, creating a new node with the same matcher, effects, and ref_marker, but with the specified nav and copying the successors list.

Source

pub fn add_matcher(&mut self, matcher: BuildMatcher<'src>) -> NodeId

Source

pub fn add_definition(&mut self, name: &'src str, entry: NodeId)

Source

pub fn definition(&self, name: &str) -> Option<NodeId>

Source

pub fn definitions(&self) -> impl Iterator<Item = (&'src str, NodeId)> + '_

Source

pub fn node(&self, id: NodeId) -> &BuildNode<'src>

Source

pub fn node_mut(&mut self, id: NodeId) -> &mut BuildNode<'src>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = (NodeId, &BuildNode<'src>)>

Source

pub fn connect(&mut self, from: NodeId, to: NodeId)

Source

pub fn connect_exit(&mut self, fragment: Fragment, to: NodeId)

Source

pub fn matcher_fragment(&mut self, matcher: BuildMatcher<'src>) -> Fragment

Source

pub fn epsilon_fragment(&mut self) -> Fragment

Source

pub fn sequence(&mut self, fragments: &[Fragment]) -> Fragment

Connect fragments in sequence: f1 → f2 → … → fn

Source

pub fn alternation(&mut self, fragments: &[Fragment]) -> Fragment

Connect fragments in parallel (alternation): entry → [f1|f2|…|fn] → exit

Source

pub fn zero_or_more(&mut self, inner: Fragment, nav: Nav) -> Fragment

Zero or more (greedy): inner*

Source

pub fn zero_or_more_lazy(&mut self, inner: Fragment, nav: Nav) -> Fragment

Zero or more (non-greedy): inner*?

Source

pub fn one_or_more(&mut self, inner: Fragment, nav: Nav) -> Fragment

One or more (greedy): inner+

Source

pub fn one_or_more_lazy(&mut self, inner: Fragment, nav: Nav) -> Fragment

One or more (non-greedy): inner+?

Source

pub fn optional(&mut self, inner: Fragment) -> Fragment

Optional (greedy): inner?

Source

pub fn optional_lazy(&mut self, inner: Fragment) -> Fragment

Optional (non-greedy): inner??

Source

pub fn zero_or_more_array(&mut self, inner: Fragment, nav: Nav) -> Fragment

Zero or more with array collection (greedy): inner*

Source

pub fn zero_or_more_array_lazy(&mut self, inner: Fragment, nav: Nav) -> Fragment

Zero or more with array collection (non-greedy): inner*?

Source

pub fn one_or_more_array(&mut self, inner: Fragment, nav: Nav) -> Fragment

One or more with array collection (greedy): inner+

Source

pub fn one_or_more_array_lazy(&mut self, inner: Fragment, nav: Nav) -> Fragment

One or more with array collection (non-greedy): inner+?

Source

pub fn zero_or_more_array_qis(&mut self, inner: Fragment, nav: Nav) -> Fragment

Zero or more with QIS object wrapping (greedy): inner*

Each iteration is wrapped in StartObject/EndObject to keep multiple captures coupled per-iteration.

Source

pub fn zero_or_more_array_qis_lazy( &mut self, inner: Fragment, nav: Nav, ) -> Fragment

Zero or more with QIS object wrapping (non-greedy): inner*?

Source

pub fn one_or_more_array_qis(&mut self, inner: Fragment, nav: Nav) -> Fragment

One or more with QIS object wrapping (greedy): inner+

Source

pub fn one_or_more_array_qis_lazy( &mut self, inner: Fragment, nav: Nav, ) -> Fragment

One or more with QIS object wrapping (non-greedy): inner+?

Source

pub fn optional_qis(&mut self, inner: Fragment) -> Fragment

Optional with QIS object wrapping: inner?

Wraps the optional value in an object scope.

Source

pub fn optional_qis_lazy(&mut self, inner: Fragment) -> Fragment

Optional with QIS object wrapping (non-greedy): inner??

Source

pub fn wrap_definitions_with_root(&mut self, root_kind: &'src str)

Wrap definitions that don’t already match the root node kind.

For each definition whose entry matcher doesn’t match root_kind, prepends a transition that matches the root and descends into children. This allows queries like (function_declaration) to work when the interpreter starts at tree root (e.g., program).

Source§

impl<'src> BuildGraph<'src>

Source

pub fn printer(&self) -> GraphPrinter<'_, 'src>

Source

pub fn dump(&self) -> String

Source

pub fn dump_with_dead(&self, dead_nodes: &HashSet<NodeId>) -> String

Source

pub fn dump_live(&self, dead_nodes: &HashSet<NodeId>) -> String

Trait Implementations§

Source§

impl<'src> Debug for BuildGraph<'src>

Source§

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

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

impl Default for BuildGraph<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'src> Freeze for BuildGraph<'src>

§

impl<'src> RefUnwindSafe for BuildGraph<'src>

§

impl<'src> Send for BuildGraph<'src>

§

impl<'src> Sync for BuildGraph<'src>

§

impl<'src> Unpin for BuildGraph<'src>

§

impl<'src> UnwindSafe for BuildGraph<'src>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

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

Performs the conversion.