use super::{SyntaxElement, SyntaxNode, SyntaxToken};
use crate::syntax::SyntaxKind;
pub trait CstNode<'tree, 'src>: Copy {
fn can_cast(kind: SyntaxKind) -> bool;
fn cast(node: SyntaxNode<'tree, 'src>) -> Option<Self>;
fn syntax(self) -> SyntaxNode<'tree, 'src>;
}
macro_rules! typed_node {
($name:ident, $kind:ident) => {
#[doc = concat!("Typed wrapper for a [`SyntaxKind::", stringify!($kind), "`] node.")]
#[derive(Clone, Copy, Debug)]
pub struct $name<'tree, 'src>(SyntaxNode<'tree, 'src>);
impl<'tree, 'src> CstNode<'tree, 'src> for $name<'tree, 'src> {
fn can_cast(kind: SyntaxKind) -> bool {
kind == SyntaxKind::$kind
}
fn cast(node: SyntaxNode<'tree, 'src>) -> Option<Self> {
Self::can_cast(node.kind()).then_some(Self(node))
}
fn syntax(self) -> SyntaxNode<'tree, 'src> {
self.0
}
}
};
}
typed_node!(SourceFile, SourceFile);
typed_node!(Module, Module);
typed_node!(ModuleHeader, ModuleHeader);
typed_node!(Imports, Imports);
typed_node!(ImportGroup, ImportGroup);
typed_node!(UnparsedRegion, UnparsedRegion);
typed_node!(ValueAssignment, ValueAssignment);
typed_node!(TypeAssignment, TypeAssignment);
typed_node!(TextualConventionDefinition, TextualConventionDefinition);
typed_node!(ObjectTypeDefinition, ObjectTypeDefinition);
typed_node!(ModuleIdentityDefinition, ModuleIdentityDefinition);
typed_node!(ObjectIdentityDefinition, ObjectIdentityDefinition);
typed_node!(NotificationTypeDefinition, NotificationTypeDefinition);
typed_node!(TrapTypeDefinition, TrapTypeDefinition);
typed_node!(MacroDefinition, MacroDefinition);
typed_node!(ObjectGroupDefinition, ObjectGroupDefinition);
typed_node!(NotificationGroupDefinition, NotificationGroupDefinition);
typed_node!(ModuleComplianceDefinition, ModuleComplianceDefinition);
typed_node!(AgentCapabilitiesDefinition, AgentCapabilitiesDefinition);
typed_node!(ComplianceModule, ComplianceModule);
typed_node!(MandatoryGroupsClause, MandatoryGroupsClause);
typed_node!(ComplianceGroup, ComplianceGroup);
typed_node!(ComplianceObject, ComplianceObject);
typed_node!(WriteSyntaxClause, WriteSyntaxClause);
typed_node!(SupportsModule, SupportsModule);
typed_node!(IncludesClause, IncludesClause);
typed_node!(VariationClause, VariationClause);
typed_node!(CreationRequiresClause, CreationRequiresClause);
typed_node!(SyntaxClause, SyntaxClause);
typed_node!(AccessClause, AccessClause);
typed_node!(StatusClause, StatusClause);
typed_node!(DescriptionClause, DescriptionClause);
typed_node!(ReferenceClause, ReferenceClause);
typed_node!(UnitsClause, UnitsClause);
typed_node!(DisplayHintClause, DisplayHintClause);
typed_node!(IndexClause, IndexClause);
typed_node!(IndexItem, IndexItem);
typed_node!(AugmentsClause, AugmentsClause);
typed_node!(DefvalClause, DefvalClause);
typed_node!(DefvalContent, DefvalContent);
typed_node!(ObjectsClause, ObjectsClause);
typed_node!(NotificationsClause, NotificationsClause);
typed_node!(RevisionClause, RevisionClause);
typed_node!(LastUpdatedClause, LastUpdatedClause);
typed_node!(OrganizationClause, OrganizationClause);
typed_node!(ContactInfoClause, ContactInfoClause);
typed_node!(EnterpriseClause, EnterpriseClause);
typed_node!(VariablesClause, VariablesClause);
typed_node!(ProductReleaseClause, ProductReleaseClause);
typed_node!(OidAssignment, OidAssignment);
typed_node!(OidComponent, OidComponent);
typed_node!(TypeRefSyntax, TypeRefSyntax);
typed_node!(IntegerEnumSyntax, IntegerEnumSyntax);
typed_node!(BitsSyntax, BitsSyntax);
typed_node!(ConstrainedSyntax, ConstrainedSyntax);
typed_node!(Constraint, Constraint);
typed_node!(Range, Range);
typed_node!(NamedNumber, NamedNumber);
typed_node!(SequenceOfSyntax, SequenceOfSyntax);
typed_node!(SequenceSyntax, SequenceSyntax);
typed_node!(SequenceField, SequenceField);
typed_node!(ChoiceSyntax, ChoiceSyntax);
typed_node!(TaggedSyntax, TaggedSyntax);
typed_node!(OctetStringSyntax, OctetStringSyntax);
typed_node!(ObjectIdentifierSyntax, ObjectIdentifierSyntax);
typed_node!(ErrorRegion, Error);
#[derive(Clone, Copy, Debug)]
pub enum Definition<'tree, 'src> {
ValueAssignment(ValueAssignment<'tree, 'src>),
TypeAssignment(TypeAssignment<'tree, 'src>),
TextualConvention(TextualConventionDefinition<'tree, 'src>),
ObjectType(ObjectTypeDefinition<'tree, 'src>),
ModuleIdentity(ModuleIdentityDefinition<'tree, 'src>),
ObjectIdentity(ObjectIdentityDefinition<'tree, 'src>),
NotificationType(NotificationTypeDefinition<'tree, 'src>),
TrapType(TrapTypeDefinition<'tree, 'src>),
Macro(MacroDefinition<'tree, 'src>),
ObjectGroup(ObjectGroupDefinition<'tree, 'src>),
NotificationGroup(NotificationGroupDefinition<'tree, 'src>),
ModuleCompliance(ModuleComplianceDefinition<'tree, 'src>),
AgentCapabilities(AgentCapabilitiesDefinition<'tree, 'src>),
Error(ErrorRegion<'tree, 'src>),
}
#[derive(Clone, Copy, Debug)]
pub enum ComplianceRefinement<'tree, 'src> {
Group(ComplianceGroup<'tree, 'src>),
Object(ComplianceObject<'tree, 'src>),
}
impl<'tree, 'src> ComplianceRefinement<'tree, 'src> {
pub fn cast(node: SyntaxNode<'tree, 'src>) -> Option<Self> {
match node.kind() {
SyntaxKind::ComplianceGroup => ComplianceGroup::cast(node).map(Self::Group),
SyntaxKind::ComplianceObject => ComplianceObject::cast(node).map(Self::Object),
_ => None,
}
}
pub fn syntax(self) -> SyntaxNode<'tree, 'src> {
match self {
Self::Group(node) => node.syntax(),
Self::Object(node) => node.syntax(),
}
}
}
impl<'tree, 'src> Definition<'tree, 'src> {
pub fn cast(node: SyntaxNode<'tree, 'src>) -> Option<Self> {
match node.kind() {
SyntaxKind::ValueAssignment => ValueAssignment::cast(node).map(Self::ValueAssignment),
SyntaxKind::TypeAssignment => TypeAssignment::cast(node).map(Self::TypeAssignment),
SyntaxKind::TextualConventionDefinition => {
TextualConventionDefinition::cast(node).map(Self::TextualConvention)
}
SyntaxKind::ObjectTypeDefinition => {
ObjectTypeDefinition::cast(node).map(Self::ObjectType)
}
SyntaxKind::ModuleIdentityDefinition => {
ModuleIdentityDefinition::cast(node).map(Self::ModuleIdentity)
}
SyntaxKind::ObjectIdentityDefinition => {
ObjectIdentityDefinition::cast(node).map(Self::ObjectIdentity)
}
SyntaxKind::NotificationTypeDefinition => {
NotificationTypeDefinition::cast(node).map(Self::NotificationType)
}
SyntaxKind::TrapTypeDefinition => TrapTypeDefinition::cast(node).map(Self::TrapType),
SyntaxKind::MacroDefinition => MacroDefinition::cast(node).map(Self::Macro),
SyntaxKind::ObjectGroupDefinition => {
ObjectGroupDefinition::cast(node).map(Self::ObjectGroup)
}
SyntaxKind::NotificationGroupDefinition => {
NotificationGroupDefinition::cast(node).map(Self::NotificationGroup)
}
SyntaxKind::ModuleComplianceDefinition => {
ModuleComplianceDefinition::cast(node).map(Self::ModuleCompliance)
}
SyntaxKind::AgentCapabilitiesDefinition => {
AgentCapabilitiesDefinition::cast(node).map(Self::AgentCapabilities)
}
SyntaxKind::Error if is_definition_or_recovery(node) => {
ErrorRegion::cast(node).map(Self::Error)
}
_ => None,
}
}
pub fn syntax(self) -> SyntaxNode<'tree, 'src> {
match self {
Self::ValueAssignment(node) => node.syntax(),
Self::TypeAssignment(node) => node.syntax(),
Self::TextualConvention(node) => node.syntax(),
Self::ObjectType(node) => node.syntax(),
Self::ModuleIdentity(node) => node.syntax(),
Self::ObjectIdentity(node) => node.syntax(),
Self::NotificationType(node) => node.syntax(),
Self::TrapType(node) => node.syntax(),
Self::Macro(node) => node.syntax(),
Self::ObjectGroup(node) => node.syntax(),
Self::NotificationGroup(node) => node.syntax(),
Self::ModuleCompliance(node) => node.syntax(),
Self::AgentCapabilities(node) => node.syntax(),
Self::Error(node) => node.syntax(),
}
}
pub fn name(self) -> Option<SyntaxToken<'tree, 'src>> {
match self {
Self::ValueAssignment(node) => node.name(),
Self::TypeAssignment(node) => node.name(),
Self::TextualConvention(node) => node.name(),
Self::ObjectType(node) => node.name(),
Self::ModuleIdentity(node) => node.name(),
Self::ObjectIdentity(node) => node.name(),
Self::NotificationType(node) => node.name(),
Self::TrapType(node) => node.name(),
Self::Macro(node) => node.name(),
Self::ObjectGroup(node) => node.name(),
Self::NotificationGroup(node) => node.name(),
Self::ModuleCompliance(node) => node.name(),
Self::AgentCapabilities(node) => node.name(),
Self::Error(_) => None,
}
}
}
fn child_node<'tree, 'src, N>(node: SyntaxNode<'tree, 'src>) -> Option<N>
where
N: CstNode<'tree, 'src>,
{
node.children()
.filter_map(SyntaxElement::as_node)
.find_map(N::cast)
}
fn child_token<'tree, 'src>(
node: SyntaxNode<'tree, 'src>,
kind: SyntaxKind,
) -> Option<SyntaxToken<'tree, 'src>> {
node.children()
.filter_map(SyntaxElement::as_token)
.find(|token| token.kind() == kind)
}
fn child_token_matching<'tree, 'src>(
node: SyntaxNode<'tree, 'src>,
predicate: impl Fn(SyntaxKind) -> bool,
) -> Option<SyntaxToken<'tree, 'src>> {
node.children()
.filter_map(SyntaxElement::as_token)
.find(|token| predicate(token.kind()))
}
fn child_nodes<'tree, 'src, N>(node: SyntaxNode<'tree, 'src>) -> impl Iterator<Item = N>
where
N: CstNode<'tree, 'src>,
{
node.children()
.filter_map(SyntaxElement::as_node)
.filter_map(N::cast)
}
fn first_token<'tree, 'src>(node: SyntaxNode<'tree, 'src>) -> Option<SyntaxToken<'tree, 'src>> {
node.children().find_map(SyntaxElement::as_token)
}
fn last_token<'tree, 'src>(node: SyntaxNode<'tree, 'src>) -> Option<SyntaxToken<'tree, 'src>> {
node.children().filter_map(SyntaxElement::as_token).last()
}
fn child_type_syntax<'tree, 'src>(
node: SyntaxNode<'tree, 'src>,
) -> Option<SyntaxNode<'tree, 'src>> {
node.children()
.filter_map(SyntaxElement::as_node)
.find(|child| is_type_syntax_kind(child.kind()))
}
fn token_after<'tree, 'src>(
node: SyntaxNode<'tree, 'src>,
marker: SyntaxKind,
expected: SyntaxKind,
) -> Option<SyntaxToken<'tree, 'src>> {
let mut after_marker = false;
node.children().find_map(|element| {
let token = element.as_token()?;
if token.kind() == marker {
after_marker = true;
return None;
}
(after_marker && token.kind() == expected).then_some(token)
})
}
fn is_definition_kind(kind: SyntaxKind) -> bool {
matches!(
kind,
SyntaxKind::ValueAssignment
| SyntaxKind::TypeAssignment
| SyntaxKind::TextualConventionDefinition
| SyntaxKind::ObjectTypeDefinition
| SyntaxKind::ModuleIdentityDefinition
| SyntaxKind::ObjectIdentityDefinition
| SyntaxKind::NotificationTypeDefinition
| SyntaxKind::TrapTypeDefinition
| SyntaxKind::MacroDefinition
| SyntaxKind::ObjectGroupDefinition
| SyntaxKind::NotificationGroupDefinition
| SyntaxKind::ModuleComplianceDefinition
| SyntaxKind::AgentCapabilitiesDefinition
)
}
fn is_definition_or_recovery(node: SyntaxNode<'_, '_>) -> bool {
is_definition_kind(node.kind())
|| (node.kind() == SyntaxKind::Error
&& node
.children()
.filter_map(SyntaxElement::as_node)
.any(|child| is_definition_kind(child.kind())))
}
impl<'tree, 'src> SourceFile<'tree, 'src> {
pub fn modules(self) -> impl Iterator<Item = Module<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(Module::cast)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(ErrorRegion::cast)
}
pub fn definitions(self) -> impl Iterator<Item = Definition<'tree, 'src>> {
self.modules().flat_map(Module::definitions)
}
}
impl<'tree, 'src> Module<'tree, 'src> {
pub fn header(self) -> Option<ModuleHeader<'tree, 'src>> {
child_node(self.0)
}
pub fn imports(self) -> Option<Imports<'tree, 'src>> {
child_node(self.0)
}
pub fn end(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwEnd)
}
pub fn unparsed_regions(self) -> impl Iterator<Item = UnparsedRegion<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(UnparsedRegion::cast)
}
pub fn definitions(self) -> impl Iterator<Item = Definition<'tree, 'src>> {
self.unparsed_regions().flat_map(|region| {
region
.syntax()
.children()
.filter_map(SyntaxElement::as_node)
.filter(|node| is_definition_or_recovery(*node))
.filter_map(Definition::cast)
})
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(ErrorRegion::cast)
}
}
macro_rules! definition_common {
($name:ident, $keyword:ident) => {
impl<'tree, 'src> $name<'tree, 'src> {
pub fn name(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0)
}
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::$keyword)
}
pub fn assignment(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::ColonColonEqual)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.descendant_nodes()
.skip(1)
.filter_map(ErrorRegion::cast)
}
}
};
}
definition_common!(TextualConventionDefinition, KwTextualConvention);
definition_common!(ObjectTypeDefinition, KwObjectType);
definition_common!(ModuleIdentityDefinition, KwModuleIdentity);
definition_common!(ObjectIdentityDefinition, KwObjectIdentity);
definition_common!(NotificationTypeDefinition, KwNotificationType);
definition_common!(TrapTypeDefinition, KwTrapType);
definition_common!(MacroDefinition, KwMacro);
definition_common!(ObjectGroupDefinition, KwObjectGroup);
definition_common!(NotificationGroupDefinition, KwNotificationGroup);
definition_common!(ModuleComplianceDefinition, KwModuleCompliance);
definition_common!(AgentCapabilitiesDefinition, KwAgentCapabilities);
impl<'tree, 'src> TypeAssignment<'tree, 'src> {
pub fn name(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0)
}
pub fn assignment(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::ColonColonEqual)
}
pub fn type_syntax(self) -> Option<SyntaxNode<'tree, 'src>> {
child_type_syntax(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.descendant_nodes()
.skip(1)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> ValueAssignment<'tree, 'src> {
pub fn name(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0)
}
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
self.0
.descendant_tokens()
.find(|token| token.kind() == SyntaxKind::KwObject)
}
pub fn identifier(self) -> Option<SyntaxToken<'tree, 'src>> {
self.0
.descendant_tokens()
.find(|token| token.kind() == SyntaxKind::KwIdentifier)
}
pub fn assignment(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::ColonColonEqual)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.descendant_nodes()
.skip(1)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> TextualConventionDefinition<'tree, 'src> {
pub fn display_hint(self) -> Option<DisplayHintClause<'tree, 'src>> {
child_node(self.0)
}
pub fn status(self) -> Option<StatusClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn reference(self) -> Option<ReferenceClause<'tree, 'src>> {
child_node(self.0)
}
pub fn syntax_clause(self) -> Option<SyntaxClause<'tree, 'src>> {
child_node(self.0)
}
}
impl<'tree, 'src> ObjectTypeDefinition<'tree, 'src> {
pub fn syntax_clause(self) -> Option<SyntaxClause<'tree, 'src>> {
child_node(self.0)
}
pub fn units(self) -> Option<UnitsClause<'tree, 'src>> {
child_node(self.0)
}
pub fn access(self) -> Option<AccessClause<'tree, 'src>> {
child_node(self.0)
}
pub fn status(self) -> Option<StatusClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn reference(self) -> Option<ReferenceClause<'tree, 'src>> {
child_node(self.0)
}
pub fn index(self) -> Option<IndexClause<'tree, 'src>> {
child_node(self.0)
}
pub fn augments(self) -> Option<AugmentsClause<'tree, 'src>> {
child_node(self.0)
}
pub fn defval(self) -> Option<DefvalClause<'tree, 'src>> {
child_node(self.0)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
}
impl<'tree, 'src> ModuleIdentityDefinition<'tree, 'src> {
pub fn last_updated(self) -> Option<LastUpdatedClause<'tree, 'src>> {
child_node(self.0)
}
pub fn organization(self) -> Option<OrganizationClause<'tree, 'src>> {
child_node(self.0)
}
pub fn contact_info(self) -> Option<ContactInfoClause<'tree, 'src>> {
child_node(self.0)
}
pub fn descriptions(self) -> impl Iterator<Item = DescriptionClause<'tree, 'src>> {
child_nodes(self.0)
}
pub fn revisions(self) -> impl Iterator<Item = RevisionClause<'tree, 'src>> {
child_nodes(self.0)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
}
macro_rules! status_description_oid_definition {
($name:ident) => {
impl<'tree, 'src> $name<'tree, 'src> {
pub fn status(self) -> Option<StatusClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn reference(self) -> Option<ReferenceClause<'tree, 'src>> {
child_node(self.0)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
}
};
}
status_description_oid_definition!(ObjectIdentityDefinition);
status_description_oid_definition!(NotificationTypeDefinition);
impl<'tree, 'src> NotificationTypeDefinition<'tree, 'src> {
pub fn objects(self) -> Option<ObjectsClause<'tree, 'src>> {
child_node(self.0)
}
}
impl<'tree, 'src> TrapTypeDefinition<'tree, 'src> {
pub fn enterprise(self) -> Option<EnterpriseClause<'tree, 'src>> {
child_node(self.0)
}
pub fn variables(self) -> Option<VariablesClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn reference(self) -> Option<ReferenceClause<'tree, 'src>> {
child_node(self.0)
}
pub fn trap_number(self) -> Option<SyntaxToken<'tree, 'src>> {
token_after(self.0, SyntaxKind::ColonColonEqual, SyntaxKind::Number)
}
}
macro_rules! group_definition {
($name:ident, $members:ident, $method:ident) => {
impl<'tree, 'src> $name<'tree, 'src> {
pub fn $method(self) -> Option<$members<'tree, 'src>> {
child_node(self.0)
}
pub fn status(self) -> Option<StatusClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn reference(self) -> Option<ReferenceClause<'tree, 'src>> {
child_node(self.0)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
}
};
}
group_definition!(ObjectGroupDefinition, ObjectsClause, objects);
group_definition!(
NotificationGroupDefinition,
NotificationsClause,
notifications
);
impl<'tree, 'src> ModuleComplianceDefinition<'tree, 'src> {
pub fn status(self) -> Option<StatusClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn reference(self) -> Option<ReferenceClause<'tree, 'src>> {
child_node(self.0)
}
pub fn modules(self) -> impl Iterator<Item = ComplianceModule<'tree, 'src>> {
child_nodes(self.0)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
}
impl<'tree, 'src> ComplianceModule<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwModule)
}
pub fn module_name(self) -> Option<SyntaxToken<'tree, 'src>> {
token_after(self.0, SyntaxKind::KwModule, SyntaxKind::UppercaseIdent)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
pub fn mandatory_groups(self) -> Option<MandatoryGroupsClause<'tree, 'src>> {
child_node(self.0)
}
pub fn mandatory_group_clauses(
self,
) -> impl Iterator<Item = MandatoryGroupsClause<'tree, 'src>> {
child_nodes(self.0)
}
pub fn refinements(self) -> impl Iterator<Item = ComplianceRefinement<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(ComplianceRefinement::cast)
}
pub fn groups(self) -> impl Iterator<Item = ComplianceGroup<'tree, 'src>> {
child_nodes(self.0)
}
pub fn objects(self) -> impl Iterator<Item = ComplianceObject<'tree, 'src>> {
child_nodes(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.descendant_nodes()
.skip(1)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> ComplianceGroup<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwGroup)
}
pub fn group(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, SyntaxKind::is_identifier)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.descendant_nodes()
.skip(1)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> ComplianceObject<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwObject)
}
pub fn object(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, SyntaxKind::is_identifier)
}
pub fn syntax_clause(self) -> Option<SyntaxClause<'tree, 'src>> {
child_node(self.0)
}
pub fn write_syntax(self) -> Option<WriteSyntaxClause<'tree, 'src>> {
child_node(self.0)
}
pub fn min_access(self) -> Option<AccessClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.descendant_nodes()
.skip(1)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> AgentCapabilitiesDefinition<'tree, 'src> {
pub fn product_release(self) -> Option<ProductReleaseClause<'tree, 'src>> {
child_node(self.0)
}
pub fn status(self) -> Option<StatusClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn reference(self) -> Option<ReferenceClause<'tree, 'src>> {
child_node(self.0)
}
pub fn supports(self) -> impl Iterator<Item = SupportsModule<'tree, 'src>> {
child_nodes(self.0)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
}
impl<'tree, 'src> SupportsModule<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwSupports)
}
pub fn module_name(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, SyntaxKind::is_identifier)
}
pub fn oid(self) -> Option<OidAssignment<'tree, 'src>> {
child_node(self.0)
}
pub fn includes(self) -> Option<IncludesClause<'tree, 'src>> {
child_node(self.0)
}
pub fn includes_clauses(self) -> impl Iterator<Item = IncludesClause<'tree, 'src>> {
child_nodes(self.0)
}
pub fn variations(self) -> impl Iterator<Item = VariationClause<'tree, 'src>> {
child_nodes(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.descendant_nodes()
.skip(1)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> VariationClause<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwVariation)
}
pub fn target(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, SyntaxKind::is_identifier)
}
pub fn syntax_clause(self) -> Option<SyntaxClause<'tree, 'src>> {
child_node(self.0)
}
pub fn write_syntax(self) -> Option<WriteSyntaxClause<'tree, 'src>> {
child_node(self.0)
}
pub fn access(self) -> Option<AccessClause<'tree, 'src>> {
child_node(self.0)
}
pub fn creation_requires(self) -> Option<CreationRequiresClause<'tree, 'src>> {
child_node(self.0)
}
pub fn defval(self) -> Option<DefvalClause<'tree, 'src>> {
child_node(self.0)
}
pub fn description(self) -> Option<DescriptionClause<'tree, 'src>> {
child_node(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.descendant_nodes()
.skip(1)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> MacroDefinition<'tree, 'src> {
pub fn body(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::OpaqueText)
}
pub fn end(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwEnd)
}
}
impl<'tree, 'src> ModuleHeader<'tree, 'src> {
pub fn name(self) -> Option<SyntaxToken<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_token)
.find(|token| token.kind().is_identifier())
}
pub fn definitions(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwDefinitions)
}
pub fn assignment(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::ColonColonEqual)
}
pub fn begin(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwBegin)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> Imports<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwImports)
}
pub fn groups(self) -> impl Iterator<Item = ImportGroup<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(ImportGroup::cast)
}
pub fn semicolon(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::Semicolon)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> ImportGroup<'tree, 'src> {
pub fn symbols(self) -> impl Iterator<Item = SyntaxToken<'tree, 'src>> {
let mut before_from = true;
self.0.children().filter_map(move |element| {
let token = element.as_token()?;
if token.kind() == SyntaxKind::KwFrom {
before_from = false;
return None;
}
(before_from && is_import_symbol(token.kind())).then_some(token)
})
}
pub fn from(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwFrom)
}
pub fn module_name(self) -> Option<SyntaxToken<'tree, 'src>> {
let mut after_from = false;
self.0.children().find_map(|element| {
let token = element.as_token()?;
if token.kind() == SyntaxKind::KwFrom {
after_from = true;
return None;
}
(after_from && token.kind() == SyntaxKind::UppercaseIdent).then_some(token)
})
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.filter_map(ErrorRegion::cast)
}
}
impl<'tree, 'src> SyntaxClause<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwSyntax)
}
pub fn type_syntax(self) -> Option<SyntaxNode<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.find(|node| is_type_syntax_kind(node.kind()))
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> WriteSyntaxClause<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwWriteSyntax)
}
pub fn type_syntax(self) -> Option<SyntaxNode<'tree, 'src>> {
child_type_syntax(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
macro_rules! value_clause {
($name:ident, $keyword:ident, $value:expr) => {
impl<'tree, 'src> $name<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::$keyword)
}
pub fn value(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, $value)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
};
}
impl<'tree, 'src> AccessClause<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, |kind| {
matches!(
kind,
SyntaxKind::KwMaxAccess | SyntaxKind::KwMinAccess | SyntaxKind::KwAccess
)
})
}
pub fn value(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, is_access_value_kind)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
value_clause!(StatusClause, KwStatus, is_status_value_kind);
value_clause!(DescriptionClause, KwDescription, |kind| kind
== SyntaxKind::QuotedString);
value_clause!(ReferenceClause, KwReference, |kind| kind
== SyntaxKind::QuotedString);
value_clause!(UnitsClause, KwUnits, |kind| kind
== SyntaxKind::QuotedString);
value_clause!(DisplayHintClause, KwDisplayHint, |kind| kind
== SyntaxKind::QuotedString);
value_clause!(RevisionClause, KwRevision, |kind| kind
== SyntaxKind::QuotedString);
value_clause!(LastUpdatedClause, KwLastUpdated, |kind| kind
== SyntaxKind::QuotedString);
value_clause!(OrganizationClause, KwOrganization, |kind| kind
== SyntaxKind::QuotedString);
value_clause!(ContactInfoClause, KwContactInfo, |kind| kind
== SyntaxKind::QuotedString);
value_clause!(EnterpriseClause, KwEnterprise, SyntaxKind::is_identifier);
value_clause!(ProductReleaseClause, KwProductRelease, |kind| kind
== SyntaxKind::QuotedString);
macro_rules! name_list_clause {
($name:ident, $keyword:ident) => {
impl<'tree, 'src> $name<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::$keyword)
}
pub fn l_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LBrace)
}
pub fn names(self) -> impl Iterator<Item = SyntaxToken<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_token)
.filter(|token| token.kind().is_identifier())
}
pub fn r_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RBrace)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
};
}
name_list_clause!(ObjectsClause, KwObjects);
name_list_clause!(NotificationsClause, KwNotifications);
name_list_clause!(VariablesClause, KwVariables);
name_list_clause!(MandatoryGroupsClause, KwMandatoryGroups);
name_list_clause!(IncludesClause, KwIncludes);
name_list_clause!(CreationRequiresClause, KwCreationRequires);
impl<'tree, 'src> AugmentsClause<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwAugments)
}
pub fn l_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LBrace)
}
pub fn target(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, SyntaxKind::is_identifier)
}
pub fn r_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RBrace)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> IndexClause<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwIndex)
}
pub fn l_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LBrace)
}
pub fn items(self) -> impl Iterator<Item = IndexItem<'tree, 'src>> {
child_nodes(self.0)
}
pub fn r_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RBrace)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> IndexItem<'tree, 'src> {
pub fn implied(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwImplied)
}
pub fn object(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, |kind| {
kind.is_identifier() || kind == SyntaxKind::KwOctet
})
}
pub fn string_keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwString)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> DefvalClause<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwDefval)
}
pub fn content(self) -> Option<DefvalContent<'tree, 'src>> {
child_node(self.0)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> DefvalContent<'tree, 'src> {
pub fn l_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0).filter(|token| token.kind() == SyntaxKind::LBrace)
}
pub fn tokens(self) -> impl Iterator<Item = SyntaxToken<'tree, 'src>> {
let has_close = self.r_brace().is_some();
let token_count = self.0.descendant_tokens().count();
self.0
.descendant_tokens()
.enumerate()
.filter_map(move |(index, token)| {
if index == 0 || (has_close && index + 1 == token_count) {
None
} else {
Some(token)
}
})
}
pub fn r_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
last_token(self.0).filter(|token| token.kind() == SyntaxKind::RBrace)
}
}
impl<'tree, 'src> OidAssignment<'tree, 'src> {
pub fn l_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LBrace)
}
pub fn components(self) -> impl Iterator<Item = OidComponent<'tree, 'src>> {
child_nodes(self.0)
}
pub fn r_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RBrace)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> OidComponent<'tree, 'src> {
pub fn module(self) -> Option<SyntaxToken<'tree, 'src>> {
let has_dot = child_token(self.0, SyntaxKind::Dot).is_some();
has_dot.then(|| first_token(self.0)).flatten()
}
pub fn dot(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::Dot)
}
pub fn name(self) -> Option<SyntaxToken<'tree, 'src>> {
let mut after_dot = self.dot().is_none();
self.0.children().find_map(|element| {
let token = element.as_token()?;
if token.kind() == SyntaxKind::Dot {
after_dot = true;
return None;
}
(after_dot && token.kind().is_identifier()).then_some(token)
})
}
pub fn l_paren(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LParen)
}
pub fn number(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::Number)
}
pub fn r_paren(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RParen)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> TypeRefSyntax<'tree, 'src> {
pub fn name(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0)
}
}
macro_rules! named_number_syntax {
($name:ident, $keyword:ident) => {
impl<'tree, 'src> $name<'tree, 'src> {
pub fn base(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0)
}
pub fn l_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LBrace)
}
pub fn values(self) -> impl Iterator<Item = NamedNumber<'tree, 'src>> {
child_nodes(self.0)
}
pub fn r_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RBrace)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
};
}
named_number_syntax!(IntegerEnumSyntax, KwInteger);
named_number_syntax!(BitsSyntax, KwBits);
impl<'tree, 'src> NamedNumber<'tree, 'src> {
pub fn label(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0)
.filter(|token| token.kind().is_identifier() || token.kind().is_status_access_keyword())
}
pub fn l_paren(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LParen)
}
pub fn value(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, |kind| {
matches!(kind, SyntaxKind::Number | SyntaxKind::NegativeNumber)
})
}
pub fn r_paren(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RParen)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> ConstrainedSyntax<'tree, 'src> {
pub fn base(self) -> Option<SyntaxNode<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.find(|node| is_type_syntax_kind(node.kind()))
}
pub fn constraint(self) -> Option<Constraint<'tree, 'src>> {
child_node(self.0)
}
}
impl<'tree, 'src> Constraint<'tree, 'src> {
pub fn l_paren(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LParen)
}
pub fn size(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwSize)
}
pub fn ranges(self) -> impl Iterator<Item = Range<'tree, 'src>> {
child_nodes(self.0)
}
pub fn r_paren(self) -> Option<SyntaxToken<'tree, 'src>> {
last_token(self.0).filter(|token| token.kind() == SyntaxKind::RParen)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> Range<'tree, 'src> {
pub fn min(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0)
}
pub fn dot_dot(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::DotDot)
}
pub fn max(self) -> Option<SyntaxToken<'tree, 'src>> {
let mut after_dot_dot = false;
self.0.children().find_map(|element| {
let token = element.as_token()?;
if token.kind() == SyntaxKind::DotDot {
after_dot_dot = true;
return None;
}
(after_dot_dot && is_range_value_kind(token.kind())).then_some(token)
})
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> SequenceOfSyntax<'tree, 'src> {
pub fn sequence(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwSequence)
}
pub fn of(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwOf)
}
pub fn entry_type(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, is_type_reference_kind)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
macro_rules! fields_syntax {
($name:ident, $keyword:ident) => {
impl<'tree, 'src> $name<'tree, 'src> {
pub fn keyword(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::$keyword)
}
pub fn l_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LBrace)
}
pub fn fields(self) -> impl Iterator<Item = SequenceField<'tree, 'src>> {
child_nodes(self.0)
}
pub fn r_brace(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RBrace)
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
};
}
fields_syntax!(SequenceSyntax, KwSequence);
fields_syntax!(ChoiceSyntax, KwChoice);
impl<'tree, 'src> SequenceField<'tree, 'src> {
pub fn name(self) -> Option<SyntaxToken<'tree, 'src>> {
first_token(self.0).filter(|token| token.kind().is_identifier())
}
pub fn type_syntax(self) -> Option<SyntaxNode<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.find(|node| is_type_syntax_kind(node.kind()))
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> TaggedSyntax<'tree, 'src> {
pub fn l_bracket(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::LBracket)
}
pub fn tag_class(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token_matching(self.0, |kind| {
matches!(kind, SyntaxKind::KwApplication | SyntaxKind::KwUniversal)
})
}
pub fn tag_number(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::Number)
}
pub fn r_bracket(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::RBracket)
}
pub fn implicit(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwImplicit)
}
pub fn inner(self) -> Option<SyntaxNode<'tree, 'src>> {
self.0
.children()
.filter_map(SyntaxElement::as_node)
.find(|node| is_type_syntax_kind(node.kind()))
}
pub fn recovery_regions(self) -> impl Iterator<Item = ErrorRegion<'tree, 'src>> {
child_nodes(self.0)
}
}
impl<'tree, 'src> OctetStringSyntax<'tree, 'src> {
pub fn octet(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwOctet)
}
pub fn string(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwString)
}
}
impl<'tree, 'src> ObjectIdentifierSyntax<'tree, 'src> {
pub fn object(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwObject)
}
pub fn identifier(self) -> Option<SyntaxToken<'tree, 'src>> {
child_token(self.0, SyntaxKind::KwIdentifier)
}
}
fn is_type_reference_kind(kind: SyntaxKind) -> bool {
kind.is_identifier() || kind.is_type_keyword() || kind == SyntaxKind::ForbiddenKeyword
}
fn is_type_syntax_kind(kind: SyntaxKind) -> bool {
matches!(
kind,
SyntaxKind::TypeRefSyntax
| SyntaxKind::IntegerEnumSyntax
| SyntaxKind::BitsSyntax
| SyntaxKind::ConstrainedSyntax
| SyntaxKind::SequenceOfSyntax
| SyntaxKind::SequenceSyntax
| SyntaxKind::ChoiceSyntax
| SyntaxKind::TaggedSyntax
| SyntaxKind::OctetStringSyntax
| SyntaxKind::ObjectIdentifierSyntax
)
}
fn is_range_value_kind(kind: SyntaxKind) -> bool {
matches!(
kind,
SyntaxKind::Number
| SyntaxKind::NegativeNumber
| SyntaxKind::HexString
| SyntaxKind::UppercaseIdent
| SyntaxKind::ForbiddenKeyword
)
}
fn is_access_value_kind(kind: SyntaxKind) -> bool {
matches!(
kind,
SyntaxKind::KwReadOnly
| SyntaxKind::KwReadWrite
| SyntaxKind::KwReadCreate
| SyntaxKind::KwNotAccessible
| SyntaxKind::KwAccessibleForNotify
| SyntaxKind::KwWriteOnly
| SyntaxKind::KwNotImplemented
)
}
fn is_status_value_kind(kind: SyntaxKind) -> bool {
matches!(
kind,
SyntaxKind::KwCurrent
| SyntaxKind::KwDeprecated
| SyntaxKind::KwObsolete
| SyntaxKind::KwMandatory
| SyntaxKind::KwOptional
)
}
fn is_import_symbol(kind: SyntaxKind) -> bool {
kind.is_identifier() || kind.is_macro_keyword() || kind.is_type_keyword()
}