Add pipe operator, with-update, retry/fallback, reason, parallel, trace, contract, deploy

Implements 8 new language features:
- |> pipe operator: a |> f desugars to f(a), left-associative chains
- with record update: let b = a with { field: val } — non-destructive struct update
- retry/fallback: retry N times { ... } fallback { ... } with counter-based loop codegen
- reason: AI inference primitive calling soma /v1/chat/completions at runtime
- parallel: concurrent execution block returning a Map of named results via threads
- trace: zero-cost observability block emitting TraceBegin/TraceEnd with ms timing
- requires: precondition annotation on fn, emits ContractCheck bytecode at entry
- deploy: deployment-as-syntax posting to soma /v1/deploy at runtime

All features thread through lexer → parser/AST → codegen → runtime interpreter.
This commit is contained in:
Will Anderson
2026-04-28 12:04:45 -05:00
parent f2202e0e5e
commit afd99f5e0d
10 changed files with 868 additions and 59 deletions
+13
View File
@@ -190,6 +190,8 @@ impl<'src> Lexer<'src> {
'|' => {
if self.eat('|') {
Token::Or
} else if self.eat('>') {
Token::PipeOp
} else {
Token::Pipe
}
@@ -357,6 +359,17 @@ fn keyword_or_ident(s: String) -> Token {
"as" => Token::As,
"true" => Token::BoolLiteral(true),
"false" => Token::BoolLiteral(false),
"with" => Token::With,
"retry" => Token::Retry,
"times" => Token::Times,
"fallback" => Token::Fallback,
"reason" => Token::Reason,
"parallel" => Token::Parallel,
"trace" => Token::Trace,
"requires" => Token::Requires,
"deploy" => Token::Deploy,
"to" => Token::To,
"via" => Token::Via,
_ => Token::Ident(s),
}
}
+36
View File
@@ -91,6 +91,30 @@ pub enum Token {
From,
/// `as` — alias in import (`import X as Y`)
As,
/// `with` — record update syntax
With,
/// `retry` — retry block
Retry,
/// `times` — used in `retry N times`
Times,
/// `fallback` — fallback block in retry
Fallback,
/// `reason` — AI inference primitive
Reason,
/// `parallel` — concurrent execution block
Parallel,
/// `trace` — zero-cost observability block
Trace,
/// `requires` — precondition annotation on fn
Requires,
/// `deploy` — deployment primitive
Deploy,
/// `to` — used in `deploy fn to "/route"`
To,
/// `via` — used in `deploy fn to "/route" via soma`
Via,
/// `|>` — pipe operator
PipeOp,
/// `true` / `false`
BoolLiteral(bool),
@@ -198,6 +222,18 @@ impl std::fmt::Display for Token {
Token::Import => write!(f, "import"),
Token::From => write!(f, "from"),
Token::As => write!(f, "as"),
Token::With => write!(f, "with"),
Token::Retry => write!(f, "retry"),
Token::Times => write!(f, "times"),
Token::Fallback => write!(f, "fallback"),
Token::Reason => write!(f, "reason"),
Token::Parallel => write!(f, "parallel"),
Token::Trace => write!(f, "trace"),
Token::Requires => write!(f, "requires"),
Token::Deploy => write!(f, "deploy"),
Token::To => write!(f, "to"),
Token::Via => write!(f, "via"),
Token::PipeOp => write!(f, "|>"),
Token::At => write!(f, "@"),
Token::Pipe => write!(f, "|"),
Token::QuestionMark => write!(f, "?"),