Skip to main content

oak_json/parser/
element_type.rs

1use oak_core::{ElementType, 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 JsonElementType {
8    Root,
9    Value,
10    Object,
11    Array,
12    String,
13    Number,
14    Boolean,
15    Null,
16    ObjectEntry,
17    ArrayElement,
18    ErrorNode,
19    LeftBrace,
20    RightBrace,
21    LeftBracket,
22    RightBracket,
23    Comma,
24    Colon,
25    StringLiteral,
26    NumberLiteral,
27    BooleanLiteral,
28    NullLiteral,
29    BareKey,
30    Whitespace,
31    Comment,
32    Eof,
33    Error,
34}
35
36impl ElementType for JsonElementType {
37    type Role = UniversalElementRole;
38
39    fn role(&self) -> Self::Role {
40        match self {
41            Self::Root => UniversalElementRole::Root,
42
43            Self::Error => UniversalElementRole::Error,
44            _ => UniversalElementRole::None,
45        }
46    }
47}
48
49impl From<crate::lexer::token_type::JsonTokenType> for JsonElementType {
50    fn from(token: crate::lexer::token_type::JsonTokenType) -> Self {
51        unsafe { std::mem::transmute(token) }
52    }
53}