better parser errors
This commit is contained in:
parent
f83a8e3ca1
commit
dde1da8656
7 changed files with 93 additions and 113 deletions
|
|
@ -1,47 +1,50 @@
|
|||
# Bracket and parenthesis mismatch errors
|
||||
|
||||
# Missing closing parenthesis in function call
|
||||
fn test() -> int
|
||||
fn test() -> int do
|
||||
let f = lambda(x) x
|
||||
f(5
|
||||
42
|
||||
end
|
||||
|
||||
# Missing closing bracket in array access
|
||||
fn test() -> int
|
||||
fn test() -> int do
|
||||
let arr = [1, 2, 3]
|
||||
arr[0
|
||||
42
|
||||
end
|
||||
|
||||
struct Point
|
||||
x: int,
|
||||
y: int
|
||||
end
|
||||
|
||||
# Missing closing brace in struct literal
|
||||
fn test() -> int
|
||||
struct Point
|
||||
x: int
|
||||
y: int
|
||||
end
|
||||
fn test() -> int do
|
||||
let p = Point { x: 5, y: 10
|
||||
p.x
|
||||
end
|
||||
|
||||
# Missing closing parenthesis in tuple
|
||||
fn test() -> int
|
||||
fn test() -> int do
|
||||
let t = (1, 2, 3
|
||||
42
|
||||
end
|
||||
|
||||
# Missing closing angle bracket in generic
|
||||
fn test() -> int
|
||||
fn test() -> int do
|
||||
let v = Vec<int
|
||||
42
|
||||
end
|
||||
|
||||
# Extra closing parenthesis
|
||||
fn test() -> int
|
||||
fn test() -> int do
|
||||
let x = (5))
|
||||
x
|
||||
|
||||
# Mismatched brackets
|
||||
fn test() -> int
|
||||
let x = [1, 2, 3}
|
||||
x[0]
|
||||
end
|
||||
|
||||
# Missing opening parenthesis in expression
|
||||
fn test() -> int
|
||||
fn test() -> int do
|
||||
let x = 5 + 3)
|
||||
x
|
||||
x
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,19 +17,16 @@ fn test() -> int
|
|||
fn test() -> int
|
||||
for in [1, 2, 3]
|
||||
item
|
||||
0
|
||||
|
||||
# Missing 'in' keyword in for loop
|
||||
fn test() -> int
|
||||
for item [1, 2, 3]
|
||||
item
|
||||
0
|
||||
|
||||
# Missing iterable in for loop
|
||||
fn test() -> int
|
||||
for item in
|
||||
item
|
||||
0
|
||||
|
||||
# Invalid while syntax
|
||||
fn test() -> int
|
||||
|
|
@ -40,10 +37,8 @@ fn test() -> int
|
|||
fn test() -> int
|
||||
let f = lambda
|
||||
42
|
||||
f()
|
||||
|
||||
# Missing closing parenthesis in lambda
|
||||
fn test() -> int
|
||||
let f = lambda(x
|
||||
x
|
||||
f(5)
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
# Enum syntax errors
|
||||
|
||||
# Missing enum name
|
||||
enum
|
||||
Red
|
||||
Green
|
||||
end
|
||||
|
||||
# Missing variant name
|
||||
enum Color
|
||||
Red
|
||||
Green
|
||||
end
|
||||
|
||||
# Invalid variant syntax (missing parentheses for tuple variant)
|
||||
enum Result
|
||||
Ok int
|
||||
Err string
|
||||
end
|
||||
|
||||
# Missing comma between variants
|
||||
enum Color
|
||||
Red Green
|
||||
end
|
||||
|
||||
# Missing end keyword
|
||||
enum Color
|
||||
Red
|
||||
Green
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
# Expression and statement errors
|
||||
|
||||
# Missing variable name in let
|
||||
fn test() -> int
|
||||
let = 5
|
||||
42
|
||||
|
||||
# Missing equals in assignment
|
||||
fn test() -> int
|
||||
let x 5
|
||||
x
|
||||
|
||||
# Missing expression after operator
|
||||
fn test() -> int
|
||||
5 +
|
||||
|
||||
# Invalid array syntax (missing comma)
|
||||
fn test() -> int
|
||||
let arr = [1 2 3]
|
||||
arr[0]
|
||||
|
||||
# Missing closing bracket in array
|
||||
fn test() -> int
|
||||
let arr = [1, 2, 3
|
||||
arr[0]
|
||||
|
||||
# Invalid struct literal (missing field value)
|
||||
fn test() -> int
|
||||
struct Point
|
||||
x: int
|
||||
y: int
|
||||
end
|
||||
let p = Point { x: 5, y }
|
||||
p.x
|
||||
|
||||
# Missing colon in struct literal
|
||||
fn test() -> int
|
||||
struct Point
|
||||
x: int
|
||||
y: int
|
||||
end
|
||||
let p = Point { x 5, y: 10 }
|
||||
p.x
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Missing struct name
|
||||
struct
|
||||
x: int
|
||||
x: int,
|
||||
y: int
|
||||
end
|
||||
|
||||
|
|
@ -14,17 +14,17 @@ end
|
|||
|
||||
# Missing colon in field
|
||||
struct Point
|
||||
x int
|
||||
x int,
|
||||
y: int
|
||||
end
|
||||
|
||||
# Missing end keyword
|
||||
struct Point
|
||||
x: int
|
||||
y: int
|
||||
x: int,
|
||||
y: int,
|
||||
|
||||
# Invalid field separator (semicolon instead of comma)
|
||||
struct Point
|
||||
x: int;
|
||||
y: int
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue