shape_ast/error/parse_error/
tokens.rs1#[derive(Debug, Clone, PartialEq)]
5pub struct TokenInfo {
6 pub text: String,
8 pub kind: Option<TokenKind>,
10}
11
12impl TokenInfo {
13 pub fn new(text: impl Into<String>) -> Self {
14 Self {
15 text: text.into(),
16 kind: None,
17 }
18 }
19
20 pub fn with_kind(mut self, kind: TokenKind) -> Self {
21 self.kind = Some(kind);
22 self
23 }
24
25 pub fn end_of_input() -> Self {
26 Self {
27 text: String::new(),
28 kind: Some(TokenKind::EndOfInput),
29 }
30 }
31}
32
33#[derive(Debug, Clone, PartialEq)]
35pub enum TokenKind {
36 Identifier,
37 Keyword(String),
38 Number,
39 String,
40 Operator,
41 Punctuation,
42 EndOfInput,
43 Whitespace,
44 Comment,
45 Unknown,
46}
47
48#[derive(Debug, Clone, PartialEq)]
50pub enum ExpectedToken {
51 Literal(String),
53 Rule(String),
55 Category(TokenCategory),
57}
58
59impl ExpectedToken {
60 pub fn literal(s: impl Into<String>) -> Self {
61 Self::Literal(s.into())
62 }
63
64 pub fn rule(s: impl Into<String>) -> Self {
65 Self::Rule(s.into())
66 }
67
68 pub fn category(c: TokenCategory) -> Self {
69 Self::Category(c)
70 }
71}
72
73#[derive(Debug, Clone, Copy, PartialEq)]
75pub enum TokenCategory {
76 Expression,
77 Statement,
78 Type,
79 Pattern,
80 Identifier,
81 Literal,
82 Operator,
83 Delimiter,
84}