ASTNode

Struct ASTNode 

Source
pub struct ASTNode<N> {
    pub node: N,
    pub info: SourceInfo,
}
Expand description

Metadata for our syntax trees

Fields§

§node: N

Main data represented

§info: SourceInfo

additional information

Implementations§

Source§

impl ASTNode<Option<Policies>>

Source

pub fn with_generated_policyids( &self, ) -> Option<impl Iterator<Item = (PolicyID, &ASTNode<Option<Policy>>)>>

Iterate over the Policy nodes in this cst::Policies, with corresponding generated PolicyIDs

Source

pub fn to_policyset(&self, errs: &'_ mut Vec<ParseError>) -> Option<PolicySet>

convert cst::Policies to ast::PolicySet

Source§

impl ASTNode<Option<Policy>>

Source

pub fn to_policy_or_template( &self, id: PolicyID, errs: &'_ mut Vec<ParseError>, ) -> Option<Either<StaticPolicy, Template>>

Convert cst::Policy to an AST InlinePolicy or Template

Source

pub fn to_policy( &self, id: PolicyID, errs: &'_ mut Vec<ParseError>, ) -> Option<StaticPolicy>

Convert cst::Policy to an AST InlinePolicy. (Will fail if the CST is for a template)

Source

pub fn to_policy_template( &self, id: PolicyID, errs: &'_ mut Vec<ParseError>, ) -> Option<Template>

Convert cst::Policy to ast::Template. Works for inline policies as well, which will become templates with 0 slots

Source§

impl ASTNode<Option<Annotation>>

Source

pub fn to_kv_pair(&self, errs: &'_ mut Vec<ParseError>) -> Option<(Id, SmolStr)>

Get the (k, v) pair for the annotation. Critically, this checks validity for the strings and does unescaping

Source§

impl ASTNode<Option<Ident>>

Source

pub fn to_valid_ident(&self, errs: &'_ mut Vec<ParseError>) -> Option<Id>

Convert cst::Ident to ast::Id. Fails for reserved or invalid identifiers

Source§

impl ASTNode<Option<Expr>>

Source

pub fn to_expr(&self, errs: &'_ mut Vec<ParseError>) -> Option<Expr>

convert cst::Expr to ast::Expr

Source§

impl ASTNode<Option<Primary>>

Source

pub fn to_string_literal( &self, errs: &'_ mut Vec<ParseError>, ) -> Option<SmolStr>

convert cst::Primary representing a string literal to a SmolStr. Fails (and adds to errs) if the Primary wasn’t a string literal.

Source§

impl ASTNode<Option<Ref>>

Source

pub fn to_ref(&self, errs: &'_ mut Vec<ParseError>) -> Option<EntityUID>

convert cst::Ref to ast::EntityUID

Source§

impl<N> ASTNode<N>

Source

pub fn new(node: N, left: usize, right: usize) -> Self

Create a new Node from main data

Source

pub fn from_source(node: N, info: SourceInfo) -> Self

Create a new Node from main data

Source

pub fn as_ref(&self) -> ASTNode<&N>

like Option.as_ref()

Source

pub fn map<D>(self, f: impl FnOnce(N) -> D) -> ASTNode<D>

map the main data, leaving the SourceInfo alone

Source

pub fn into_inner(self) -> (N, SourceInfo)

consume the Node, producing the main data and the SourceInfo

Source§

impl<T> ASTNode<Option<T>>

Convenience methods on ASTNode<Option<T>>

Source

pub fn as_inner_pair(&self) -> (&SourceInfo, Option<&T>)

Similar to .as_inner(), but also gives access to the SourceInfo

Source

pub fn as_inner(&self) -> Option<&T>

Get the inner data as &T, if it exists

Source

pub fn collapse(&self) -> Option<ASTNode<&T>>

None if the node is empty, otherwise a node without the Option

Source

pub fn apply<F, R>(&self, f: F) -> Option<R>
where F: FnOnce(&T, &SourceInfo) -> Option<R>,

Apply the function f to the main data and source info. Returns None if no main data or if f returns None.

Source

pub fn into_apply<F, R>(self, f: F) -> Option<R>
where F: FnOnce(T, SourceInfo) -> Option<R>,

Apply the function f to the main data and source info, consuming them. Returns None if no main data or if f returns None.

Trait Implementations§

Source§

impl<N: Clone> Clone for ASTNode<N>

Source§

fn clone(&self) -> ASTNode<N>

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<N: Debug> Debug for ASTNode<N>

Source§

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

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

impl<N: PartialEq> PartialEq for ASTNode<N>

Source§

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

ignores metadata

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<N: Eq> Eq for ASTNode<N>

Auto Trait Implementations§

§

impl<N> Freeze for ASTNode<N>
where N: Freeze,

§

impl<N> RefUnwindSafe for ASTNode<N>
where N: RefUnwindSafe,

§

impl<N> Send for ASTNode<N>
where N: Send,

§

impl<N> Sync for ASTNode<N>
where N: Sync,

§

impl<N> Unpin for ASTNode<N>
where N: Unpin,

§

impl<N> UnwindSafe for ASTNode<N>
where N: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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.