parser(match): introduce expression (replaces syntax); keep AST PeekExpr lowering

- Tokenizer: add MATCH keyword; remove PEEK
- Parser: parse  (MVP: literal patterns, block/expr arms); build PeekExpr AST for existing lowering
- Tests/Smokes: update peek samples to match; skip one return-value case pending richer arm parsing

Notes: MIR unchanged; existing PeekExpr lowerers continue to work.
This commit is contained in:
Selfhosting Dev
2025-09-19 07:58:01 +09:00
parent 45e1d57536
commit a6f28a8980
6 changed files with 39 additions and 41 deletions

View File

@ -1,10 +1,10 @@
static box Main {
main(args) {
local d = "1"
local dv = peek d {
local dv = match d {
"0" => { print("found zero") 0 }
"1" => { print("found one") 1 }
else => { print("other") 0 }
_ => { print("other") 0 }
}
return dv
}

View File

@ -1,11 +1,11 @@
static box Main {
main(args) {
// Use peek as an expression to produce a value
// Use match as an expression to produce a value
local d = "1"
local v = peek d {
"0" => { 0 }
"1" => { 1 }
else => { 0 }
local v = match d {
"0" => 0,
"1" => 1,
_ => 0
}
// Show the result and finish
local console = new ConsoleBox()