cedar_policy_core::parser

Struct Node

Source
pub struct Node<T> {
    pub node: T,
    pub loc: Loc,
}
Expand description

Metadata for our syntax trees

Fields§

§node: T

Main data represented

§loc: Loc

Source location

Implementations§

Source§

impl Node<Option<Expr>>

Source

pub fn to_ref(&self, var: Var) -> Result<EntityUID, ParseErrors>

Extract a single EntityUID from this expression. The expression must be exactly a single entity literal expression.

Source

pub fn to_ref_or_slot(&self, var: Var) -> Result<EntityReference, ParseErrors>

Extract a single EntityUID or a template slot from this expression. The expression must be exactly a single entity literal expression or a single template slot.

Source

pub fn to_refs(&self, var: Var) -> Result<OneOrMultipleRefs, ParseErrors>

Extract a single EntityUID or set of EntityUIDs from this expression. The expression must either be exactly a single entity literal expression a single set literal expression, containing some number of entity literals.

Source§

impl Node<Option<Policies>>

Source

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

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

Source

pub fn to_policyset(&self) -> Result<PolicySet, ParseErrors>

convert cst::Policies to ast::PolicySet

Source§

impl Node<Option<Policy>>

Source

pub fn to_policy_or_template( &self, id: PolicyID, ) -> Result<Either<StaticPolicy, Template>, ParseErrors>

Convert cst::Policy to an AST InlinePolicy or Template

Source

pub fn to_policy(&self, id: PolicyID) -> Result<StaticPolicy, ParseErrors>

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) -> Result<Template, ParseErrors>

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

Source§

impl Node<Option<Annotation>>

Source

pub fn to_kv_pair<T>( &self, annotation_constructor: impl Fn(Option<SmolStr>, &Loc) -> T, ) -> Result<(AnyId, T), ParseErrors>

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

Source§

impl Node<Option<Ident>>

Source

pub fn to_valid_ident(&self) -> Result<Id, ParseErrors>

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

Source

pub fn to_any_ident(&self) -> Result<AnyId, ParseErrors>

Convert cst::Ident to ast::AnyId. This method does not fail for reserved identifiers; see notes on ast::AnyId. (It does fail for invalid identifiers, but there are no invalid identifiers at the time of this writing; see notes on cst::Ident::Invalid)

Source§

impl Node<Option<Expr>>

Source

pub fn to_expr(&self) -> Result<Expr, ParseErrors>

convert cst::Expr to ast::Expr

Source§

impl Node<Option<Member>>

Source

pub fn to_lit(&self) -> Option<&Literal>

Try to convert cst::Member into a cst::Literal, i.e. match Member(Primary(Literal(_), [])). It does not match the Expr arm of Primary, which means expressions like (1) are not considered as literals on the CST level.

Source§

impl Node<Option<Primary>>

Source

pub fn to_string_literal(&self) -> Result<SmolStr, ParseErrors>

convert cst::Primary representing a string literal to a SmolStr.

Source§

impl Node<Option<Ref>>

Source

pub fn to_ref(&self) -> Result<EntityUID, ParseErrors>

convert cst::Ref to ast::EntityUID

Source§

impl<T> Node<T>

Source

pub fn with_source_loc(node: T, loc: Loc) -> Self

Create a new Node with the given source location

Source

pub fn map<R>(self, f: impl FnOnce(T) -> R) -> Node<R>

Transform the inner value while retaining the attached source info.

Source

pub fn as_ref(&self) -> Node<&T>

Converts from &Node<T> to Node<&T>.

Source

pub fn as_mut(&mut self) -> Node<&mut T>

Converts from &mut Node<T> to Node<&mut T>.

Source

pub fn into_inner(self) -> (T, Loc)

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

Source

pub fn to_ast_err(&self, error_kind: impl Into<ToASTErrorKind>) -> ToASTError

Utility to construct a ToAstError with the source location taken from this node.

Source§

impl<T: Clone> Node<&T>

Source

pub fn cloned(self) -> Node<T>

Converts a Node<&T> to a Node<T> by cloning the inner value.

Source§

impl<T: Copy> Node<&T>

Source

pub fn copied(self) -> Node<T>

Converts a Node<&T> to a Node<T> by copying the inner value.

Source§

impl<T> Node<Option<T>>

Convenience methods on Node<Option<T>>

Source

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

Get the inner data as &T, if it exists

Source

pub fn collapse(&self) -> Option<Node<&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, &Loc) -> 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, Loc) -> Option<R>,

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

Source

pub fn try_as_inner(&self) -> Result<&T, ToASTError>

Get node data if present or return the error EmptyNodeInvariantViolation

Source

pub fn try_into_inner(self) -> Result<T, ToASTError>

Get node data if present or return the error EmptyNodeInvariantViolation

Trait Implementations§

Source§

impl<T: Clone> Clone for Node<T>

Source§

fn clone(&self) -> Node<T>

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<T: Debug> Debug for Node<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for Node<T>
where T: 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<T: Diagnostic> Diagnostic for Node<T>

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 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 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<T: Display> Display for Node<T>

Source§

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

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

impl<T: Error> Error for Node<T>

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<T: Hash> Hash for Node<T>

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<T: PartialEq> PartialEq for Node<T>

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<T> Serialize for Node<T>
where T: 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 TryFrom<&Node<Option<Add>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(a: &Node<Option<Add>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<And>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(a: &Node<Option<And>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<Expr>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(e: &Node<Option<Expr>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<Literal>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(lit: &Node<Option<Literal>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<Member>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(m: &Node<Option<Member>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<Mult>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(m: &Node<Option<Mult>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<Name>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(name: &Node<Option<Name>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<Or>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(o: &Node<Option<Or>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<Relation>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(r: &Node<Option<Relation>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl TryFrom<&Node<Option<Unary>>> for Expr

Source§

type Error = ParseErrors

The type returned in the event of a conversion error.
Source§

fn try_from(u: &Node<Option<Unary>>) -> Result<Expr, ParseErrors>

Performs the conversion.
Source§

impl<T: Eq> Eq for Node<T>

Auto Trait Implementations§

§

impl<T> Freeze for Node<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Node<T>
where T: RefUnwindSafe,

§

impl<T> Send for Node<T>
where T: Send,

§

impl<T> Sync for Node<T>
where T: Sync,

§

impl<T> Unpin for Node<T>
where T: Unpin,

§

impl<T> UnwindSafe for Node<T>
where T: 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>,