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 copy 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<ASTNode<N>> for ASTNode<N>

source§

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

ignores metadata

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

Auto Trait Implementations§

§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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