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>>
impl Node<Option<Expr>>
Sourcepub fn to_ref(&self, var: Var) -> Result<EntityUID, ParseErrors>
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.
Sourcepub fn to_ref_or_slot(&self, var: Var) -> Result<EntityReference, ParseErrors>
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.
Sourcepub fn to_refs(&self, var: Var) -> Result<OneOrMultipleRefs, ParseErrors>
pub fn to_refs(&self, var: Var) -> Result<OneOrMultipleRefs, ParseErrors>
Extract a single EntityUID
or set of EntityUID
s 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>>
impl Node<Option<Policies>>
Sourcepub fn with_generated_policyids(
&self,
) -> Result<impl Iterator<Item = (PolicyID, &Node<Option<Policy>>)>, ParseErrors>
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 PolicyID
s
Sourcepub fn to_policyset(&self) -> Result<PolicySet, ParseErrors>
pub fn to_policyset(&self) -> Result<PolicySet, ParseErrors>
convert cst::Policies
to ast::PolicySet
Source§impl Node<Option<Policy>>
impl Node<Option<Policy>>
Sourcepub fn to_policy_or_template(
&self,
id: PolicyID,
) -> Result<Either<StaticPolicy, Template>, ParseErrors>
pub fn to_policy_or_template( &self, id: PolicyID, ) -> Result<Either<StaticPolicy, Template>, ParseErrors>
Convert cst::Policy
to an AST InlinePolicy
or Template
Sourcepub fn to_policy(&self, id: PolicyID) -> Result<StaticPolicy, ParseErrors>
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)
Sourcepub fn to_policy_template(&self, id: PolicyID) -> Result<Template, ParseErrors>
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>>
impl Node<Option<Annotation>>
Sourcepub fn to_kv_pair<T>(
&self,
annotation_constructor: impl Fn(Option<SmolStr>, &Loc) -> T,
) -> Result<(AnyId, T), ParseErrors>
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>>
impl Node<Option<Ident>>
Sourcepub fn to_valid_ident(&self) -> Result<Id, ParseErrors>
pub fn to_valid_ident(&self) -> Result<Id, ParseErrors>
Convert cst::Ident
to ast::Id
. Fails for reserved or invalid identifiers
Sourcepub fn to_any_ident(&self) -> Result<AnyId, ParseErrors>
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>>
impl Node<Option<Expr>>
Sourcepub fn to_expr(&self) -> Result<Expr, ParseErrors>
pub fn to_expr(&self) -> Result<Expr, ParseErrors>
convert cst::Expr
to ast::Expr
Source§impl Node<Option<Primary>>
impl Node<Option<Primary>>
Sourcepub fn to_string_literal(&self) -> Result<SmolStr, ParseErrors>
pub fn to_string_literal(&self) -> Result<SmolStr, ParseErrors>
convert cst::Primary
representing a string literal to a SmolStr
.
Source§impl Node<Option<Ref>>
impl Node<Option<Ref>>
Sourcepub fn to_ref(&self) -> Result<EntityUID, ParseErrors>
pub fn to_ref(&self) -> Result<EntityUID, ParseErrors>
convert cst::Ref
to ast::EntityUID
Source§impl<T> Node<T>
impl<T> Node<T>
Sourcepub fn with_source_loc(node: T, loc: Loc) -> Self
pub fn with_source_loc(node: T, loc: Loc) -> Self
Create a new Node with the given source location
Sourcepub fn map<R>(self, f: impl FnOnce(T) -> R) -> Node<R>
pub fn map<R>(self, f: impl FnOnce(T) -> R) -> Node<R>
Transform the inner value while retaining the attached source info.
Sourcepub fn into_inner(self) -> (T, Loc)
pub fn into_inner(self) -> (T, Loc)
Consume the Node
, yielding the node and attached source info.
Sourcepub fn to_ast_err(&self, error_kind: impl Into<ToASTErrorKind>) -> ToASTError
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> Node<Option<T>>
impl<T> Node<Option<T>>
Convenience methods on Node<Option<T>>
Sourcepub fn collapse(&self) -> Option<Node<&T>>
pub fn collapse(&self) -> Option<Node<&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 Loc
, consuming them.
Returns None
if no main data or if f
returns None
.
Sourcepub fn try_as_inner(&self) -> Result<&T, ToASTError>
pub fn try_as_inner(&self) -> Result<&T, ToASTError>
Get node data if present or return the error EmptyNodeInvariantViolation
Sourcepub fn try_into_inner(self) -> Result<T, ToASTError>
pub fn try_into_inner(self) -> Result<T, ToASTError>
Get node data if present or return the error EmptyNodeInvariantViolation
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Node<T>where
T: Deserialize<'de>,
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>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: Diagnostic> Diagnostic for Node<T>
impl<T: Diagnostic> Diagnostic for Node<T>
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
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
.Diagnostic
s.Source§fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
Source§impl<T: Error> Error for Node<T>
impl<T: Error> Error for Node<T>
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<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> 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