oak_typst/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 TypstElementType {
7 Root,
9 Heading,
11 Quote,
13 Math,
15 Strong,
17 Emphasis,
19 ListItem,
21 EnumItem,
23 Raw,
25}
26
27impl ElementType for TypstElementType {
28 type Role = UniversalElementRole;
29
30 fn role(&self) -> Self::Role {
31 match self {
32 Self::Root => UniversalElementRole::Root,
33 Self::Heading => UniversalElementRole::Statement,
34 Self::Math => UniversalElementRole::Expression,
35 _ => UniversalElementRole::None,
36 }
37 }
38}
39
40impl From<crate::lexer::token_type::TypstTokenType> for TypstElementType {
41 fn from(token: crate::lexer::token_type::TypstTokenType) -> Self {
42 use crate::lexer::token_type::TypstTokenType::*;
43 match token {
44 Heading => Self::Heading,
45 Quote => Self::Quote,
46 Math | InlineMath | DisplayMath => Self::Math,
47 Strong => Self::Strong,
48 Emphasis => Self::Emphasis,
49 ListItem => Self::ListItem,
50 EnumItem => Self::EnumItem,
51 Raw | Code => Self::Raw,
52 _ => Self::Root,
53 }
54 }
55}