1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/// Source location for error reporting.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Span {
pub start: usize, // byte offset
pub end: usize, // byte offset
pub line: usize, // 1-based line number
pub col: usize, // 1-based column (byte offset within line)
}
impl Span {
/// Format an error message with file location.
pub fn fmt_error(&self, path: &str, msg: &str) -> String {
format!("{path}:{}:{}: error: {msg}", self.line, self.col)
}
/// Format a warning message with file location.
pub fn fmt_warning(&self, path: &str, msg: &str) -> String {
format!("{path}:{}:{}: warning: {msg}", self.line, self.col)
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum TokenKind {
// Keywords
Config, // config
Job, // job
Service, // service
Event, // event
Task, // task
If, // if
For, // for
In, // in
Env, // env
Run, // run
Wait, // wait
Watch, // watch
After, // after
OnFail, // on_fail
Spawn, // spawn
Http, // http
Connect, // connect
Exists, // exists
Contains, // contains
Running, // running
Glob, // glob
Arg, // arg
Import, // import
As, // as
True, // true
False, // false
None, // none
Module, // module
Procman, // procman
// Literals
String(String), // "..." (contents, escapes resolved)
Number(f64), // 42, 3.14
Duration(f64), // 5.0 (seconds) — suffix parsed into seconds
FencedString(String), // """ ... """ (raw contents)
// Identifiers and references
Ident(String), // bare identifier (e.g., job name, var name)
At, // @
Dot, // .
Args, // args (keyword for args namespace)
// Operators
Eq, // ==
Ne, // !=
Lt, // <
Gt, // >
Le, // <=
Ge, // >=
And, // &&
Or, // ||
Not, // !
Plus, // +
// Punctuation
Assign, // =
LBrace, // {
RBrace, // }
LBracket, // [
RBracket, // ]
LParen, // (
RParen, // )
Comma, // ,
DotDot, // ..
DotDotEq, // ..=
ColonColon, // ::
}
#[derive(Clone, Debug)]
pub struct Token {
pub kind: TokenKind,
pub span: Span,
}