Skip to main content

caddyfile_rs/
token.rs

1//! Token types and source spans produced by the lexer.
2//!
3//! Used as the intermediate representation between lexing and parsing.
4
5/// Source location for error reporting.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct Span {
8    pub line: usize,
9    pub column: usize,
10}
11
12/// Token kinds produced by the lexer.
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum TokenKind {
15    /// Unquoted word.
16    Word,
17    /// Double-quoted string (`"..."`).
18    QuotedString,
19    /// Backtick-quoted string (`` `...` ``).
20    BacktickString,
21    /// Heredoc (`<<MARKER ... MARKER`).
22    Heredoc { marker: String },
23    /// Comment (`# ...`).
24    Comment,
25    /// Opening brace `{`.
26    OpenBrace,
27    /// Closing brace `}`.
28    CloseBrace,
29    /// Newline (line separator).
30    Newline,
31    /// Environment variable `{$VAR}` or `{$VAR:default}`.
32    EnvVar {
33        name: String,
34        default: Option<String>,
35    },
36}
37
38/// A single token with its kind, text, and source location.
39#[derive(Debug, Clone, PartialEq, Eq)]
40pub struct Token {
41    pub kind: TokenKind,
42    pub text: String,
43    pub span: Span,
44}