better parser errors

This commit is contained in:
Masashi 2025-12-15 21:26:39 +05:30
commit dde1da8656
7 changed files with 93 additions and 113 deletions

View file

@ -1,5 +1,14 @@
# Pattern matching errors
struct Point
x: int,
y: int,
end
enum Result
Ok(int)
Err(string)
end
# Invalid pattern in match
fn test() -> int
match 42
@ -7,26 +16,20 @@ fn test() -> int
end
# Missing colon in struct pattern
fn test() -> int
struct Point
x: int
y: int
end
let p = Point { x: 5, y: 10 }
fn test() -> int do
let p = Point { x: 5, y: 10 }
match p
Point { x 5, y: 10 } => 1
end
end
# Invalid enum pattern
fn test() -> int
enum Result
Ok(int)
Err(string)
end
let r = Result::Ok(42)
fn test() -> int do
let r = Result::Ok(42)
match r
Result::Ok value => value
end
end
# Missing pattern in match arm
fn test() -> int
@ -38,4 +41,4 @@ fn test() -> int
fn test() -> int
match 42
x 0
end
end