oak_rst/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u16)]
7pub enum RstElementType {
8 Root,
10 Paragraph,
12 Heading1,
14 Heading2,
16 Heading3,
18 Heading4,
20 Heading5,
22 Heading6,
24 Comment,
26 Directive,
28 SubstitutionReference,
30 Role,
32 FootnoteReference,
34 FootnoteDefinition,
36 CitationReference,
38 CitationDefinition,
40 BulletList,
42 EnumeratedList,
44 ListItem,
46 DefinitionList,
48 DefinitionTerm,
50 DefinitionDefinition,
52 Blockquote,
54 CodeBlock,
56 HorizontalRule,
58 Table,
60 TableRow,
62 TableCell,
64 Emphasis,
66 Strong,
68 Literal,
70 Link,
72 ReferenceName,
74 ReferenceTarget,
76 Admonition,
78 Text,
80 Whitespace,
82 Newline,
84 Error,
86}
87
88impl ElementType for RstElementType {
89 type Role = UniversalElementRole;
90
91 fn role(&self) -> <Self as ElementType>::Role {
92 match self {
93 _ => UniversalElementRole::None,
94 }
95 }
96}
97
98impl From<crate::lexer::token_type::RstTokenType> for RstElementType {
99 fn from(token: crate::lexer::token_type::RstTokenType) -> Self {
100 match token {
101 crate::lexer::token_type::RstTokenType::Text => RstElementType::Text,
102 crate::lexer::token_type::RstTokenType::Whitespace => RstElementType::Whitespace,
103 crate::lexer::token_type::RstTokenType::Newline => RstElementType::Newline,
104 crate::lexer::token_type::RstTokenType::Comment => RstElementType::Comment,
105 crate::lexer::token_type::RstTokenType::Directive => RstElementType::Directive,
106 crate::lexer::token_type::RstTokenType::SubstitutionReference => RstElementType::SubstitutionReference,
107 crate::lexer::token_type::RstTokenType::Role => RstElementType::Role,
108 crate::lexer::token_type::RstTokenType::FootnoteReference => RstElementType::FootnoteReference,
109 crate::lexer::token_type::RstTokenType::FootnoteDefinition => RstElementType::FootnoteDefinition,
110 crate::lexer::token_type::RstTokenType::CitationReference => RstElementType::CitationReference,
111 crate::lexer::token_type::RstTokenType::CitationDefinition => RstElementType::CitationDefinition,
112 crate::lexer::token_type::RstTokenType::BulletListMarker => RstElementType::ListItem,
113 crate::lexer::token_type::RstTokenType::EnumeratedListMarker => RstElementType::ListItem,
114 crate::lexer::token_type::RstTokenType::DefinitionTerm => RstElementType::DefinitionTerm,
115 crate::lexer::token_type::RstTokenType::DefinitionDefinition => RstElementType::DefinitionDefinition,
116 crate::lexer::token_type::RstTokenType::BlockquoteMarker => RstElementType::Blockquote,
117 crate::lexer::token_type::RstTokenType::CodeBlock => RstElementType::CodeBlock,
118 crate::lexer::token_type::RstTokenType::Heading1 => RstElementType::Heading1,
119 crate::lexer::token_type::RstTokenType::Heading2 => RstElementType::Heading2,
120 crate::lexer::token_type::RstTokenType::Heading3 => RstElementType::Heading3,
121 crate::lexer::token_type::RstTokenType::Heading4 => RstElementType::Heading4,
122 crate::lexer::token_type::RstTokenType::Heading5 => RstElementType::Heading5,
123 crate::lexer::token_type::RstTokenType::Heading6 => RstElementType::Heading6,
124 crate::lexer::token_type::RstTokenType::HorizontalRule => RstElementType::HorizontalRule,
125 crate::lexer::token_type::RstTokenType::Table => RstElementType::Table,
126 crate::lexer::token_type::RstTokenType::TableCell => RstElementType::TableCell,
127 crate::lexer::token_type::RstTokenType::Emphasis => RstElementType::Emphasis,
128 crate::lexer::token_type::RstTokenType::Strong => RstElementType::Strong,
129 crate::lexer::token_type::RstTokenType::Literal => RstElementType::Literal,
130 crate::lexer::token_type::RstTokenType::Link => RstElementType::Link,
131 crate::lexer::token_type::RstTokenType::ReferenceName => RstElementType::ReferenceName,
132 crate::lexer::token_type::RstTokenType::ReferenceTarget => RstElementType::ReferenceTarget,
133 _ => RstElementType::Error,
134 }
135 }
136}