mirror of
https://github.com/imjasonh/loom
synced 2026-07-06 22:52:57 +00:00
Implement a Python-based bootstrap compiler for the Loom language, plus self-hosting lexer and parser written in Loom itself. Bootstrap compiler (Python): - Lexer: tokenizes all Loom syntax including multi-char operators - Parser: recursive descent with proper operator precedence - AST: dataclass-based node definitions - VM: executes Loom programs with main() as entry point - Stdlib: string, array, math, and file I/O functions - CLI: run command for executing .loom files Self-hosting components (Loom): - lexer.loom: complete lexer that can tokenize itself (298 tokens) - parser.loom: recursive descent parser producing dict-based AST - loom_compiler.loom: integrated lexer+parser for end-to-end compilation Example programs: - simple.loom, refund.loom: basic Loom syntax demos - arrays.loom: iteration constructs (@map, @filter, @reduce) - stdlib_test.loom, file_test.loom, unary_test.loom: feature tests Key language features implemented: - Nodes ($name), pipes (->), commits (!var), guards (?), journals (~>) - Branch expressions: (condition) true_expr : false_expr - Iteration: @each, @map, @filter, @reduce - Arrays, dicts, property access, function calls
23 lines
706 B
Text
23 lines
706 B
Text
@origin "Process a refund while checking for fraud"
|
|
@should "Only refund if original payment exists"
|
|
@should "Flag refunds over $500 for human review"
|
|
|
|
$refund_logic(user_id: str, tx_id: str, amount: f64):
|
|
~> "Verify transaction exists"
|
|
api.get_tx(tx_id) -> !tx
|
|
?(tx.status == "paid")
|
|
|
|
~> "Calculate fraud risk"
|
|
model.fraud_score(user_id, amount) -> !p_fraud
|
|
|
|
%95 {
|
|
~> "High confidence path"
|
|
(amount > 500) gateway.refund(tx_id, amount) : human.review(tx) -> !result
|
|
} : {
|
|
~> "Model confidence low, forcing manual check"
|
|
human.review(tx) -> !result
|
|
}
|
|
|
|
~> "Verify final integrity"
|
|
?(result.success == true)
|
|
result -> !final_result
|