Skip to main content

oak_pascal/parser/
element_type.rs

1use oak_core::{ElementType, Parser, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7pub enum PascalElementType {
8    Root,
9    Program,
10    Unit,
11    Interface,
12    Implementation,
13    Initialization,
14    Finalization,
15    ConstSection,
16    TypeSection,
17    VarSection,
18    Procedure,
19    Function,
20    Block,
21    Statement,
22    Expression,
23    Error,
24}
25
26impl ElementType for PascalElementType {
27    type Role = UniversalElementRole;
28
29    fn role(&self) -> Self::Role {
30        match self {
31            _ => UniversalElementRole::None,
32        }
33    }
34}
35
36impl From<crate::lexer::token_type::PascalTokenType> for PascalElementType {
37    fn from(token: crate::lexer::token_type::PascalTokenType) -> Self {
38        use crate::lexer::token_type::PascalTokenType;
39        match token {
40            PascalTokenType::Root => PascalElementType::Root,
41            PascalTokenType::ProgramBlock => PascalElementType::Program,
42            PascalTokenType::VarSection => PascalElementType::VarSection,
43            PascalTokenType::ConstSection => PascalElementType::ConstSection,
44            PascalTokenType::TypeSection => PascalElementType::TypeSection,
45            PascalTokenType::ProcedureDef => PascalElementType::Procedure,
46            PascalTokenType::FunctionDef => PascalElementType::Function,
47            PascalTokenType::CompoundStmt => PascalElementType::Block,
48            PascalTokenType::Expression => PascalElementType::Expression,
49            _ => PascalElementType::Error,
50        }
51    }
52}