ded6af238286c7c3cc257a6473c0de807ff5f4df
Add the second pipeline stage: a hand-written recursive-descent parser with a
cascade expression layer, plus the AST it builds. Chosen over chumsky for precise
control of the specification's sync-point error recovery and plain-English errors;
the AST and later checkers are agnostic to this choice.
- legis-ast: full AST for declarations, statements, the precedence-encoded
expression grammar, match/when in statement and expression forms, attempt,
ranges, actions, tags, and conditional blocks. Spans on items, statements,
expressions, and types.
- legis-parser: parses the whole grammar (minus the web route DSL, deferred to
the web phase), with error recovery to synchronization points and a 20-error
cap. Generic-call vs comparison is disambiguated by a restoring trial parse of
`<Type,...>(`. Non-associative equality is rejected.
- legis-cli: new `parse` command dumping the syntax tree.
- Reference-program-over-grammar decisions, all exercised by the calculator:
match arms may test a direct value (`is "+"`); arm bodies may be `{ }` blocks;
a `when` expression arm may hold a bare `give back`; a `contract` may describe
a constructor.
- legis-lexer: add the `while` keyword; make `value` a plain identifier (the
reference program uses it as a name), with `has value` matched contextually.
27 tests pass (6 diag + 12 lexer + 9 parser); fmt and clippy clean. The reference
calculator parses to a correct AST with no problems.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Legis
Code that reads.
Legis is a programming language designed to be readable by an adult with no
programming background, while staying honest about ownership, absence, and
failure. This repository holds the legis compiler and toolchain, written in
Rust, built from Legis Language Specification v1.0.txt.
See PLAN.md for the full implementation roadmap.
Status
Early construction. The pipeline is being built front-to-back, measured against
running the reference calculator program (examples/calculator.lgi).
| Phase | Area | State |
|---|---|---|
| 0 | Workspace + plain-English diagnostics guard | done |
| 1 | Lexer | done |
| 2 | Parser + AST | done |
| 3 | Name resolution | next |
| 4 | Type checker | planned |
| 5 | Purity / ownership / secret checkers | planned |
| 6 | LLVM codegen + minimal standard library (MVP) | planned |
| 7 | Toolchain CLI + formatter | planned |
| 8+ | Collections, config, database, web, concurrency, lpm, docs | planned |
Layout
crates/
legis-diag shared diagnostics + the banned-jargon guard
legis-lexer logos-based lexer
legis-ast abstract syntax tree types
legis-parser hand-written recursive-descent parser
legis-cli the `legis` binary
examples/
calculator.lgi the specification's reference program
Building
cargo test # run the suite
cargo run -p legis-cli -- tokens FILE # dump a file's token stream
cargo run -p legis-cli -- parse FILE # dump a file's syntax tree
Toolchain
- Rust (stable). The codebase uses tab indentation (
rustfmt.tomlsetshard_tabs = true), matching the Legis source convention. - LLVM is required from Phase 6 onward (native code generation via
inkwell); it is not needed for the front-end work in phases 0–5.
Description
Languages
Rust
100%