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

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 ParseErrors) -> 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 ParseErrors, ) -> Option<Either<StaticPolicy, Template>>

Convert cst::Policy to an AST InlinePolicy or Template

source

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)

source

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

source

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

source

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

source

pub fn to_expr(&self, errs: &mut ParseErrors) -> Option<Expr>

convert cst::Expr to ast::Expr

source§

impl ASTNode<Option<Primary>>

source

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

source

pub fn to_ref(&self, errs: &mut ParseErrors) -> 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(info: impl Into<SourceInfo>, node: N) -> Self

Create a new Node from main data

source

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

Transform the inner value while retaining the attached source info.

source

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

Converts from &ASTNode<N> to ASTNode<&N>.

source

pub fn as_mut(&mut self) -> ASTNode<&mut N>

Converts from &mut ASTNode<N> to ASTNode<&mut N>.

source

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

Consume the ASTNode, yielding the node and attached source info.

source§

impl<N: Clone> ASTNode<&N>

source

pub fn cloned(self) -> ASTNode<N>

Converts a ASTNode<&N> to a ASTNode<N> by cloning the inner value.

source§

impl<N: Copy> ASTNode<&N>

source

pub fn copied(self) -> ASTNode<N>

Converts a ASTNode<&N> to a ASTNode<N> by copying the inner value.

source§

impl<N> ASTNode<Option<N>>

Convenience methods on ASTNode<Option<N>>

source

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

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

source

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

Get the inner data as &N, if it exists

source

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

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(&N, &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(N, 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<'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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<N: Diagnostic> Diagnostic for ASTNode<N>

source§

fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>>

Unique diagnostic code that can be used to look up more information about this 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>

Diagnostic severity. This may be used by ReportHandlers to change the display format of this diagnostic. Read more
source§

fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>>

Additional help text related to this 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>>

URL to visit for a more detailed explanation/help about this Diagnostic.
source§

fn source_code(&self) -> Option<&dyn SourceCode>

Source code to apply this Diagnostic’s Diagnostic::labels to.
source§

fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>

Labels to apply to this Diagnostic’s Diagnostic::source_code
source§

fn related<'a>( &'a self, ) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>>

Additional related Diagnostics.
source§

fn diagnostic_source(&self) -> Option<&dyn Diagnostic>

The cause of the error.
source§

impl<N: Display> Display for ASTNode<N>

source§

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

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

impl<N: Error> Error for ASTNode<N>

source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
source§

impl<N: Hash> Hash for ASTNode<N>

source§

fn hash<H: Hasher>(&self, state: &mut H)

ignores metadata

1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. 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> Serialize for ASTNode<N>
where N: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToSmolStr for T
where T: Display + ?Sized,

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,