ERR/E0.2: raise / try / catch / onfail + precedence + consumer-aware pipe (parser)
Parser-only second step of the error-handling stream. No sema/codegen.
- token: 4 keywords — `raise`, `try`, `catch`, `onfail`.
- ast: RaiseStmt, TryExpr, CatchExpr {operand, binding?, body, is_match_body},
OnFailStmt {binding?, body}.
- parser:
- `try` is a unary prefix (binds tighter than `or`; right-recursive so it
stacks under `xx`/`@`/etc).
- `or` is already left-associative (precedence-climbing loop) — no change.
- `catch` is a postfix with four body shapes (no-binding block / block /
bare-expr / `== { case }` match-body, the latter reusing parseMatchBody
with the binding as subject).
- `raise EXPR;` and `onfail [e] { } | onfail EXPR;` statements; `error`
parses in expression position so `raise error.X` works; raise rejected
in expression position and inside an onfail body (in_onfail_body flag).
- consumer-aware `|>`: pipes the LHS into the head call through a
try/catch/or wrapper, preserving the wrapper.
- print: printExpr + match-arm printing for round-trips (anyerror!void to
break the printExpr<->printMatchArms inferred-error-set loop).
- sema/lsp: exhaustive switch arms for the 4 nodes + 4 keyword tokens.
- tests: ~22 inline parser tests (precedence, all catch forms, both
rejections, pipe cases, round-trip prints incl. match-body).
zig build, zig build test (264), and 254/254 examples green.
This commit is contained in:
@@ -14,6 +14,10 @@ pub const Tag = enum {
|
||||
kw_false,
|
||||
kw_enum,
|
||||
kw_error, // error (error-set declaration)
|
||||
kw_raise, // raise (error propagation statement)
|
||||
kw_try, // try (failable-attempt prefix)
|
||||
kw_catch, // catch (failable handler postfix)
|
||||
kw_onfail, // onfail (error-exit cleanup statement)
|
||||
kw_case,
|
||||
kw_break,
|
||||
kw_continue,
|
||||
@@ -224,6 +228,10 @@ pub const keywords = std.StaticStringMap(Tag).initComptime(.{
|
||||
.{ "false", .kw_false },
|
||||
.{ "enum", .kw_enum },
|
||||
.{ "error", .kw_error },
|
||||
.{ "raise", .kw_raise },
|
||||
.{ "try", .kw_try },
|
||||
.{ "catch", .kw_catch },
|
||||
.{ "onfail", .kw_onfail },
|
||||
.{ "case", .kw_case },
|
||||
.{ "break", .kw_break },
|
||||
.{ "continue", .kw_continue },
|
||||
|
||||
Reference in New Issue
Block a user