pub struct ASTNode<N> {
pub node: N,
pub info: SourceInfo,
}Expand description
Metadata for our syntax trees
Fields§
§node: NMain data represented
info: SourceInfoadditional information
Implementations§
Source§impl ASTNode<Option<Policies>>
impl ASTNode<Option<Policies>>
Sourcepub fn with_generated_policyids(
&self,
) -> Option<impl Iterator<Item = (PolicyID, &ASTNode<Option<Policy>>)>>
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
Sourcepub fn to_policyset(&self, errs: &'_ mut Vec<ParseError>) -> Option<PolicySet>
pub fn to_policyset(&self, errs: &'_ mut Vec<ParseError>) -> Option<PolicySet>
convert cst::Policies to ast::PolicySet
Source§impl ASTNode<Option<Policy>>
impl ASTNode<Option<Policy>>
Sourcepub fn to_policy_or_template(
&self,
id: PolicyID,
errs: &'_ mut Vec<ParseError>,
) -> Option<Either<StaticPolicy, Template>>
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
Sourcepub fn to_policy(
&self,
id: PolicyID,
errs: &'_ mut Vec<ParseError>,
) -> Option<StaticPolicy>
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)
Sourcepub fn to_policy_template(
&self,
id: PolicyID,
errs: &'_ mut Vec<ParseError>,
) -> Option<Template>
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>>
impl ASTNode<Option<Annotation>>
Sourcepub fn to_kv_pair(&self, errs: &'_ mut Vec<ParseError>) -> Option<(Id, SmolStr)>
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>>
impl ASTNode<Option<Ident>>
Sourcepub fn to_valid_ident(&self, errs: &'_ mut Vec<ParseError>) -> Option<Id>
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<Primary>>
impl ASTNode<Option<Primary>>
Sourcepub fn to_string_literal(
&self,
errs: &'_ mut Vec<ParseError>,
) -> Option<SmolStr>
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<N> ASTNode<N>
impl<N> ASTNode<N>
Sourcepub fn from_source(node: N, info: SourceInfo) -> Self
pub fn from_source(node: N, info: SourceInfo) -> Self
Create a new Node from main data
Sourcepub fn map<D>(self, f: impl FnOnce(N) -> D) -> ASTNode<D>
pub fn map<D>(self, f: impl FnOnce(N) -> D) -> ASTNode<D>
map the main data, leaving the SourceInfo alone
Sourcepub fn into_inner(self) -> (N, SourceInfo)
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>>
impl<T> ASTNode<Option<T>>
Convenience methods on ASTNode<Option<T>>
Sourcepub fn as_inner_pair(&self) -> (&SourceInfo, Option<&T>)
pub fn as_inner_pair(&self) -> (&SourceInfo, Option<&T>)
Similar to .as_inner(), but also gives access to the SourceInfo
Sourcepub fn collapse(&self) -> Option<ASTNode<&T>>
pub fn collapse(&self) -> Option<ASTNode<&T>>
None if the node is empty, otherwise a node without the Option
Sourcepub fn apply<F, R>(&self, f: F) -> Option<R>
pub fn apply<F, R>(&self, f: F) -> Option<R>
Apply the function f to the main data and source info. Returns None
if no main data or if f returns None.
Sourcepub fn into_apply<F, R>(self, f: F) -> Option<R>
pub fn into_apply<F, R>(self, f: F) -> 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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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