Skip to main content

oak_cobol/parser/
element_type.rs

1use crate::lexer::token_type::CobolTokenType;
2use oak_core::{ElementType, UniversalElementRole};
3
4/// COBOL element types.
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub enum CobolElementType {
8    /// End of file.
9    Eof,
10    /// Whitespace.
11    Whitespace,
12    /// Comment.
13    Comment,
14    /// Identifier.
15    Identifier,
16    /// String literal.
17    String,
18    /// Number literal.
19    Number,
20    /// "IDENTIFICATION" keyword.
21    Identification,
22    /// "DIVISION" keyword.
23    Division,
24
25    /// Root element.
26    Root,
27    /// Division element.
28    DivisionElement,
29    /// Paragraph element.
30    Paragraph,
31}
32
33impl ElementType for CobolElementType {
34    type Role = UniversalElementRole;
35
36    fn role(&self) -> Self::Role {
37        match self {
38            Self::Root => UniversalElementRole::Root,
39            _ => UniversalElementRole::None,
40        }
41    }
42}
43
44impl From<CobolTokenType> for CobolElementType {
45    fn from(token: CobolTokenType) -> Self {
46        match token {
47            CobolTokenType::Eof => Self::Eof,
48            CobolTokenType::Whitespace => Self::Whitespace,
49            CobolTokenType::Comment => Self::Comment,
50            CobolTokenType::Identifier => Self::Identifier,
51            CobolTokenType::String => Self::String,
52            CobolTokenType::Number => Self::Number,
53            CobolTokenType::Identification => Self::Identification,
54            CobolTokenType::Division => Self::Division,
55        }
56    }
57}