oak_json/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8pub enum JsonElementType {
9 Root,
11 Value,
13 Object,
15 Array,
17 String,
19 Number,
21 Boolean,
23 Null,
25 ObjectEntry,
27 ArrayElement,
29 ErrorNode,
31 LeftBrace,
33 RightBrace,
35 LeftBracket,
37 RightBracket,
39 Comma,
41 Colon,
43 StringLiteral,
45 NumberLiteral,
47 BooleanLiteral,
49 NullLiteral,
51 BareKey,
53 Whitespace,
55 Comment,
57 Eof,
59 Error,
61}
62
63impl ElementType for JsonElementType {
64 type Role = UniversalElementRole;
65
66 fn role(&self) -> Self::Role {
67 match self {
68 Self::Root => UniversalElementRole::Root,
69
70 Self::Error => UniversalElementRole::Error,
71 _ => UniversalElementRole::None,
72 }
73 }
74}
75
76impl From<crate::lexer::token_type::JsonTokenType> for JsonElementType {
77 fn from(token: crate::lexer::token_type::JsonTokenType) -> Self {
78 unsafe { std::mem::transmute(token) }
79 }
80}