Struct cedar_policy_core::parser::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>>
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 PolicyID
s
sourcepub fn to_policyset(&self, errs: &mut ParseErrors) -> Option<PolicySet>
pub fn to_policyset(&self, errs: &mut ParseErrors) -> 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 ParseErrors,
) -> Option<Either<StaticPolicy, Template>>
pub fn to_policy_or_template( &self, id: PolicyID, errs: &mut ParseErrors, ) -> Option<Either<StaticPolicy, Template>>
Convert cst::Policy
to an AST InlinePolicy
or Template
sourcepub fn to_policy(
&self,
id: PolicyID,
errs: &mut ParseErrors,
) -> Option<StaticPolicy>
pub fn to_policy( &self, id: PolicyID, errs: &mut ParseErrors, ) -> 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 ParseErrors,
) -> Option<Template>
pub fn to_policy_template( &self, id: PolicyID, errs: &mut ParseErrors, ) -> 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 ParseErrors) -> Option<(Id, SmolStr)>
pub fn to_kv_pair(&self, errs: &mut ParseErrors) -> 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 ParseErrors) -> Option<Id>
pub fn to_valid_ident(&self, errs: &mut ParseErrors) -> Option<Id>
Convert cst::Ident
to ast::Id
. Fails for reserved or invalid identifiers
source§impl ASTNode<Option<Expr>>
impl ASTNode<Option<Expr>>
sourcepub fn to_expr(&self, errs: &mut ParseErrors) -> Option<Expr>
pub fn to_expr(&self, errs: &mut ParseErrors) -> Option<Expr>
convert cst::Expr
to ast::Expr
source§impl ASTNode<Option<Primary>>
impl ASTNode<Option<Primary>>
sourcepub fn to_string_literal(&self, errs: &mut ParseErrors) -> Option<SmolStr>
pub fn to_string_literal(&self, errs: &mut ParseErrors) -> 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>>
impl ASTNode<Option<Ref>>
sourcepub fn to_ref(&self, errs: &mut ParseErrors) -> Option<EntityUID>
pub fn to_ref(&self, errs: &mut ParseErrors) -> Option<EntityUID>
convert cst::Ref
to ast::EntityUID
source§impl<N> ASTNode<N>
impl<N> ASTNode<N>
sourcepub fn from_source(info: impl Into<SourceInfo>, node: N) -> Self
pub fn from_source(info: impl Into<SourceInfo>, node: N) -> Self
Create a new Node from main data
sourcepub fn map<M>(self, f: impl FnOnce(N) -> M) -> ASTNode<M>
pub fn map<M>(self, f: impl FnOnce(N) -> M) -> ASTNode<M>
Transform the inner value while retaining the attached source info.
sourcepub fn into_inner(self) -> (N, SourceInfo)
pub fn into_inner(self) -> (N, SourceInfo)
Consume the ASTNode
, yielding the node and attached source info.
source§impl<N> ASTNode<Option<N>>
impl<N> ASTNode<Option<N>>
Convenience methods on ASTNode<Option<N>>
sourcepub fn as_inner_pair(&self) -> (&SourceInfo, Option<&N>)
pub fn as_inner_pair(&self) -> (&SourceInfo, Option<&N>)
Similar to .as_inner()
, but also gives access to the SourceInfo
sourcepub fn collapse(&self) -> Option<ASTNode<&N>>
pub fn collapse(&self) -> Option<ASTNode<&N>>
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§
source§impl<'de, N> Deserialize<'de> for ASTNode<N>where
N: Deserialize<'de>,
impl<'de, N> Deserialize<'de> for ASTNode<N>where
N: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<N: Diagnostic> Diagnostic for ASTNode<N>
impl<N: Diagnostic> Diagnostic for ASTNode<N>
source§fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
Diagnostic
. Ideally also globally unique, and documented
in the toplevel crate’s documentation for easy searching. Rust path
format (foo::bar::baz
) is recommended, but more classic codes like
E0123
or enums will work just fine.source§fn severity(&self) -> Option<Severity>
fn severity(&self) -> Option<Severity>
ReportHandler
s to change the display format
of this diagnostic. Read moresource§fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
Diagnostic
. Do you have any
advice for the poor soul who’s just run into this issue?source§fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
Diagnostic
.source§fn source_code(&self) -> Option<&dyn SourceCode>
fn source_code(&self) -> Option<&dyn SourceCode>
Diagnostic
’s Diagnostic::labels
to.source§fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>
Diagnostic
’s Diagnostic::source_code
Diagnostic
s.source§fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
source§impl<N: Error> Error for ASTNode<N>
impl<N: Error> Error for ASTNode<N>
source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
source§fn description(&self) -> &str
fn description(&self) -> &str
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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