Skip to main content

oak_vlang/parser/
element_type.rs

1use crate::lexer::token_type::VLangTokenType;
2use oak_core::{ElementType, UniversalElementRole};
3
4/// Element types for the V language.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub enum VLangElementType {
8    /// The root source file.
9    SourceFile,
10    /// A token element.
11    Token(VLangTokenType),
12}
13
14impl ElementType for VLangElementType {
15    type Role = UniversalElementRole;
16
17    fn role(&self) -> Self::Role {
18        match self {
19            Self::SourceFile => UniversalElementRole::Root,
20            Self::Token(_) => UniversalElementRole::None,
21        }
22    }
23}
24
25impl From<VLangTokenType> for VLangElementType {
26    fn from(token: VLangTokenType) -> Self {
27        Self::Token(token)
28    }
29}