oak_pascal/parser/
element_type.rs1use oak_core::{ElementType, Parser, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum PascalElementType {
7 Root,
9 Program,
11 Unit,
13 Interface,
15 Implementation,
17 Initialization,
19 Finalization,
21 ConstSection,
23 TypeSection,
25 VarSection,
27 Procedure,
29 Function,
31 Block,
33 Statement,
35 Expression,
37 Error,
39}
40
41impl ElementType for PascalElementType {
42 type Role = UniversalElementRole;
43
44 fn role(&self) -> Self::Role {
45 match self {
46 _ => UniversalElementRole::None,
47 }
48 }
49}
50
51impl From<crate::lexer::token_type::PascalTokenType> for PascalElementType {
52 fn from(token: crate::lexer::token_type::PascalTokenType) -> Self {
53 use crate::lexer::token_type::PascalTokenType;
54 match token {
55 PascalTokenType::Root => PascalElementType::Root,
56 PascalTokenType::ProgramBlock => PascalElementType::Program,
57 PascalTokenType::VarSection => PascalElementType::VarSection,
58 PascalTokenType::ConstSection => PascalElementType::ConstSection,
59 PascalTokenType::TypeSection => PascalElementType::TypeSection,
60 PascalTokenType::ProcedureDef => PascalElementType::Procedure,
61 PascalTokenType::FunctionDef => PascalElementType::Function,
62 PascalTokenType::CompoundStmt => PascalElementType::Block,
63 PascalTokenType::Expression => PascalElementType::Expression,
64 _ => PascalElementType::Error,
65 }
66 }
67}