/// Horizontal whitespace (spaces and tabs)
WHITESPACE = _{ " " | "\t" }
/// Newline characters (supports Unix and Windows)
ln = _{ "\r\n" | "\n" }
/// Single line comments starting with '#'
comment = @{ "#" ~ (!ln ~ ANY)* }
/// Documentation lines (comments immediately preceding a definition)
doc_line = { comment ~ ln }
/// Standard alphanumeric identifier starting with a letter
ident = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
/// String literal for imports
string_literal = { "\"" ~ (!"\"" ~ ANY)* ~ "\"" }
// --- Keywords ---
kw_constant = { "constant" }
kw_variable = { "variable" }
kw_error = { "error" }
kw_group = { "group" }
kw_function = { "function" }
kw_import = { "import" }
// --- Tokens ---
token = { collection | unitary }
collection = { "[" ~ ident ~ "]" }
unitary = { ident }
// --- Definitions ---
/// Import statement
import_stmt = { kw_import ~ string_literal }
/// Global constant definition
const_def = { doc_line* ~ kw_constant ~ ident }
/// Global variable definition
var_def = { doc_line* ~ kw_variable ~ ident }
/// Architectural error definition
err_def = { doc_line* ~ kw_error ~ ident }
/// Logical group definition
group_def = { doc_line* ~ kw_group ~ ident }
/// Comma-separated list of tokens (arguments/results)
token_list = { token ~ ("," ~ token)* }
/// A single output branch (starts with > for primary or | for alternate)
output_line = { (">" | "|") ~ token_list }
/// Function Contract Definition
func_def = {
doc_line* ~ (!kw_function ~ ident)? ~ kw_function ~ ident ~ token_list? ~ (ln | WHITESPACE)* ~ func_outputs?
}
/// The block of output branches associated with a function
func_outputs = { output_line ~ ((ln | WHITESPACE)* ~ output_line)* }
// --- Flow ---
/// An execution step referencing a function name
flow_step = { !keyword ~ ident }
/// Keywords reserved by the language to avoid identifier collisions
keyword = {
kw_constant
| kw_variable
| kw_error
| kw_group
| kw_function
| kw_import
}
// --- Root ---
/// Top-level statement types
statement = _{
import_stmt
| const_def
| var_def
| err_def
| group_def
| func_def
| flow_step
| comment
| ln
}
/// The complete Tect source file entry point
program = { SOI ~ (statement)* ~ EOI }