use crate::lexer::AdaTokenType;
use oak_core::{ElementType, GreenNode, UniversalElementRole};
use std::sync::Arc;
pub type AdaElement<'a> = Arc<GreenNode<'a, AdaElementType>>;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AdaElementType {
Root,
CompilationUnit,
ContextClause,
Pragma,
SubprogramDeclaration,
PackageDeclaration,
TypeDeclaration,
ObjectDeclaration,
Statement,
Expression,
Error,
Identifier,
LiteralExpression,
IdentifierExpression,
ParenthesizedExpression,
SourceFile,
ParameterList,
BlockExpression,
UseItem,
ModuleItem,
StructItem,
EnumItem,
LetStatement,
IfExpression,
WhileExpression,
LoopExpression,
ForExpression,
CallExpression,
IndexExpression,
FieldExpression,
BinaryExpression,
UnaryExpression,
}
impl ElementType for AdaElementType {
type Role = UniversalElementRole;
fn is_root(&self) -> bool {
matches!(self, Self::Root | Self::SourceFile)
}
fn is_error(&self) -> bool {
matches!(self, Self::Error)
}
fn role(&self) -> Self::Role {
use UniversalElementRole::*;
match self {
Self::Root | Self::SourceFile => Root,
Self::CompilationUnit | Self::SubprogramDeclaration | Self::PackageDeclaration | Self::TypeDeclaration | Self::ObjectDeclaration | Self::ModuleItem | Self::StructItem | Self::EnumItem => Definition,
Self::ContextClause | Self::BlockExpression | Self::ParameterList | Self::ParenthesizedExpression => Container,
Self::Statement | Self::Pragma | Self::UseItem | Self::LetStatement => Statement,
Self::Expression
| Self::BinaryExpression
| Self::UnaryExpression
| Self::IfExpression
| Self::WhileExpression
| Self::LoopExpression
| Self::ForExpression
| Self::IdentifierExpression
| Self::LiteralExpression
| Self::IndexExpression
| Self::FieldExpression => Expression,
Self::CallExpression => Call,
Self::Identifier => Reference,
Self::Error => Error,
}
}
}
impl From<AdaTokenType> for AdaElementType {
fn from(token_type: AdaTokenType) -> Self {
match token_type {
AdaTokenType::Identifier => Self::Identifier,
AdaTokenType::StringLiteral | AdaTokenType::CharacterLiteral | AdaTokenType::NumberLiteral => Self::LiteralExpression,
_ => Self::Error,
}
}
}