Skip to main content

flutmax_parser/
tokens.rs

1/// Token types for the flutmax lexer.
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum TokenType {
5    // Keywords
6    Wire,
7    In,
8    Out,
9    State,
10    Msg,
11    Feedback,
12    Signal,
13    Float,
14    Int,
15    Bang,
16    List,
17    Symbol,
18
19    // Delimiters
20    LParen,
21    RParen,
22    LBracket,
23    RBracket,
24    Comma,
25    Semicolon,
26    Colon,
27    Dot,
28    Eq,
29    Tilde,
30
31    // Identifiers & Literals
32    /// Plain identifier: `foo`, `drunk-walk`, `node_a`
33    Identifier,
34    /// Operator name used as Max/gen~ object name: `?`, `*`, `+`, `-`, `/`, `%`, `==`, etc.
35    Operator,
36    /// Numeric literal: `42`, `3.14`, `-7`, `1e-6`, `100.`
37    NumberLit,
38    /// String literal: `"hello"`
39    StringLit,
40
41    // Special
42    /// `.attr(` — recognized as a single token for simplicity
43    DotAttrLParen,
44
45    /// Line comment: `// ...`
46    Comment,
47
48    // Misc
49    Eof,
50}
51
52#[derive(Debug, Clone, PartialEq)]
53pub struct Token {
54    pub token_type: TokenType,
55    pub lexeme: String,
56    pub line: usize,
57    pub column: usize,
58}
59
60impl Token {
61    pub fn new(
62        token_type: TokenType,
63        lexeme: impl Into<String>,
64        line: usize,
65        column: usize,
66    ) -> Self {
67        Self {
68            token_type,
69            lexeme: lexeme.into(),
70            line,
71            column,
72        }
73    }
74}