toml_parse/tkn_tree/kinds.rs
1use rowan::SmolStr;
2
3/// An enum representing either a `Node` or a `Token`.
4#[derive(Clone, Debug, PartialEq, Eq, Hash)]
5pub enum Element {
6 #[allow(dead_code)]
7 Node(TomlNode),
8 Token(TomlToken),
9}
10
11impl PartialEq<TomlNode> for Element {
12 fn eq(&self, other: &TomlNode) -> bool {
13 match self {
14 Element::Node(n) => n == other,
15 Element::Token(_) => false,
16 }
17 }
18}
19
20impl PartialEq<TomlToken> for Element {
21 fn eq(&self, other: &TomlToken) -> bool {
22 match self {
23 Element::Token(tkn) => tkn == other,
24 Element::Node(_) => false,
25 }
26 }
27}
28
29#[derive(Clone, Debug, PartialEq, Eq, Hash)]
30pub struct TomlNode {
31 pub(crate) kind: TomlKind,
32 pub(crate) text: SmolStr,
33}
34
35#[derive(Clone, Debug, PartialEq, Eq, Hash)]
36pub struct TomlToken {
37 pub(crate) kind: TomlKind,
38 pub(crate) text: SmolStr,
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
42#[repr(u16)]
43pub enum TomlKind {
44 //
45 // TOKENS
46 // these are considered tokens from
47 // here down
48 /// the text of a comment.
49 CommentText = 0,
50 /// A signed 64 bit number.
51 Integer,
52 /// True or false.
53 Bool,
54 /// The token when a key is not surrounded by quotes.
55 Ident,
56
57 /// Single quote.
58 SingleQuote,
59 /// Double quote, used for keys and strings.
60 DoubleQuote,
61 /// Triple quote, used for literal strings.
62 TripleQuote,
63
64 /// `+`
65 Plus,
66 /// `-`
67 Minus,
68 /// `=`
69 Equal,
70 /// `#`
71 Hash,
72 /// `,`
73 Dot,
74 /// `,`
75 Comma,
76 /// `:`
77 Colon,
78
79 /// opening brace `{`.
80 OpenCurly,
81 /// closing brace `}`.
82 CloseCurly,
83 /// opening brace `[`.
84 OpenBrace,
85 /// closing brace `]`.
86 CloseBrace,
87
88 /// All whitespace tokens, newline, indent,
89 /// space and tab are all represented by this token.
90 Whitespace,
91 /// End of file token.
92 EoF,
93
94 // NODES
95 // these are nodes
96 //
97 Table,
98 /// A table heading surounded by brackets.
99 Heading,
100 /// An array of tables heading
101 ArrayHeading,
102 /// A segmented `Heading` Ident.
103 SegIdent,
104 /// An inline table where the key is the "heading" and
105 /// key value pairs inside of curly braces.
106 InlineTable,
107 /// A key and a value, any other valid toml type.
108 KeyValue,
109 /// A key either `Ident` or double quoted.
110 Key,
111 /// Any valid toml type after a key.
112 Value,
113 /// A toml array.
114 Array,
115 ///
116 ArrayItem,
117 /// Toml date
118 /// TODO this is one of with offset, without, local,
119 /// time, date and datetime.
120 Date,
121 /// A toml table consisting of a heading and key
122 /// value pairs.
123 /// An signed 64 bit EEE 754-2008 "binary64" number.
124 Float,
125 /// One of three string types, literal single quote,
126 /// normal double quote and literal triple double quote.
127 /// (like python doc comments)
128 Str,
129 /// A comment in the toml file, a `Hash` token followed by `CommentText`.
130 Comment,
131 /// the "empty" root node representing a whole file.
132 Root,
133}