Fix bugs, add propper tests

This commit is contained in:
2026-02-03 13:20:23 +02:00
parent 081ff9a27a
commit 4b61adea5d
58 changed files with 1103 additions and 285 deletions

View File

@@ -0,0 +1,55 @@
Program {
ast: Block(
[
Statement(
LocBox {
inner: Enum(
Enum {
name: Ident(
"Foo",
),
fields: [],
},
),
loc: Loc {
file: "parser/enumerations.mcl",
line: 1,
col: 5,
},
},
),
Statement(
LocBox {
inner: Enum(
Enum {
name: Ident(
"Bar",
),
fields: [
Ident(
"A",
),
Ident(
"B",
),
Ident(
"C",
),
],
},
),
loc: Loc {
file: "parser/enumerations.mcl",
line: 3,
col: 5,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -0,0 +1,7 @@
enum Foo {}
enum Bar {
A,
B,
C,
}

View File

@@ -0,0 +1,908 @@
Program {
ast: Block(
[
Statement(
LocBox {
inner: Let {
name: Ident(
"a",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: EqEq,
left: LocBox {
inner: BinOp {
typ: Star,
left: LocBox {
inner: Literal(
Number(
Number {
val: 1,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 10,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 14,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 12,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 4,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 18,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 16,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 1,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"b",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: EqEq,
left: LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 10,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 4,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 12,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 11,
},
},
right: LocBox {
inner: UnOp {
typ: Star,
right: LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 17,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 14,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 2,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"c",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: Group(
LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 11,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 13,
},
},
),
right: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 15,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"d",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 17,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 14,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 12,
},
},
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 10,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 2,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 22,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 20,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 3,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"d",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: Literal(
Number(
Number {
val: 2,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 10,
},
},
right: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 14,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 16,
},
},
),
right: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 18,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"d",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 20,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 19,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 17,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 15,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 12,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 4,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"e",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 10,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 12,
},
},
),
right: LocBox {
inner: PtrFieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 14,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"d",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 15,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 13,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 11,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 2,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 20,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 18,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 5,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"f",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Div,
left: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 10,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 12,
},
},
),
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 14,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"d",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 15,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 13,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 11,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 2,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 20,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 18,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 6,
col: 4,
},
},
),
Statement(
LocBox {
inner: Let {
name: Ident(
"g",
),
typ: None,
val: Some(
LocBox {
inner: BinOp {
typ: Star,
left: LocBox {
inner: ArrayIndex {
name: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 10,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"b",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 12,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 11,
},
},
index: LocBox {
inner: UnOp {
typ: Star,
right: LocBox {
inner: FieldAccess {
left: Some(
LocBox {
inner: Path(
Path(
[
Ident(
"a",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 15,
},
},
),
right: LocBox {
inner: Path(
Path(
[
Ident(
"c",
),
],
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 17,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 16,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 14,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 13,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 5,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 22,
},
},
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 20,
},
},
),
},
loc: Loc {
file: "parser/expressions.mcl",
line: 7,
col: 4,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -0,0 +1,8 @@
let a = 1 * 3 == 4;
let b = 3/4 == *a;
let c = (a->b.c->d) / 2;
let d = 2 / a->b.c->d;
let e = a->b.c->d / 2;
let f = a.b.c.d / 2;
let g = a.b[*a.c] * 5;

View File

@@ -0,0 +1,306 @@
Program {
ast: Block(
[
Statement(
LocBox {
inner: Fn(
Function {
struct_name: None,
name: Ident(
"main",
),
params: [
(
Ident(
"argc",
),
LocBox {
inner: Owned(
Ident(
"i32",
),
),
loc: Loc {
file: "parser/functions.mcl",
line: 1,
col: 18,
},
},
),
(
Ident(
"argv",
),
LocBox {
inner: Ref {
inner: Array {
inner: Owned(
Ident(
"Str",
),
),
},
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 1,
col: 27,
},
},
),
],
ret_type: Some(
LocBox {
inner: Owned(
Ident(
"i32",
),
),
loc: Loc {
file: "parser/functions.mcl",
line: 1,
col: 39,
},
},
),
qual_const: false,
qual_extern: None,
body: Some(
Block(
[
Expr(
LocBox {
inner: Return(
Some(
LocBox {
inner: Literal(
Number(
Number {
val: 0,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/functions.mcl",
line: 2,
col: 13,
},
},
),
),
loc: Loc {
file: "parser/functions.mcl",
line: 2,
col: 11,
},
},
),
],
),
),
},
),
loc: Loc {
file: "parser/functions.mcl",
line: 1,
col: 3,
},
},
),
Statement(
LocBox {
inner: Fn(
Function {
struct_name: Some(
Ident(
"Baz",
),
),
name: Ident(
"main",
),
params: [
(
Ident(
"self",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Baz",
),
),
mutable: true,
},
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 20,
},
},
),
(
Ident(
"a",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Foo",
),
),
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 33,
},
},
),
(
Ident(
"b",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Bar",
),
),
mutable: true,
},
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 42,
},
},
),
],
ret_type: Some(
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Nya",
),
),
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 54,
},
},
),
qual_const: false,
qual_extern: None,
body: None,
},
),
loc: Loc {
file: "parser/functions.mcl",
line: 4,
col: 3,
},
},
),
Statement(
LocBox {
inner: Fn(
Function {
struct_name: Some(
Ident(
"Baz",
),
),
name: Ident(
"main",
),
params: [
(
Ident(
"a",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Foo",
),
),
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 5,
col: 17,
},
},
),
(
Ident(
"b",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Bar",
),
),
mutable: true,
},
loc: Loc {
file: "parser/functions.mcl",
line: 5,
col: 26,
},
},
),
],
ret_type: Some(
LocBox {
inner: Ref {
inner: Owned(
Ident(
"Nya",
),
),
mutable: false,
},
loc: Loc {
file: "parser/functions.mcl",
line: 5,
col: 38,
},
},
),
qual_const: false,
qual_extern: None,
body: None,
},
),
loc: Loc {
file: "parser/functions.mcl",
line: 5,
col: 3,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -0,0 +1,5 @@
fn main(argc: i32, argv: &[Str]) -> i32 {
return 0;
}
fn Baz.main(self: &mut Baz, a: &Foo, b: &mut Bar) -> &Nya;
fn Baz.main(a: &Foo, b: &mut Bar) -> &Nya;

View File

@@ -0,0 +1,70 @@
Program {
ast: Block(
[
Expr(
LocBox {
inner: If(
IfExpr {
test: LocBox {
inner: BinOp {
typ: Gt,
left: LocBox {
inner: Path(
Path(
[
Ident(
"i",
),
],
),
),
loc: Loc {
file: "parser/if-statements.mcl",
line: 2,
col: 5,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/if-statements.mcl",
line: 2,
col: 9,
},
},
},
loc: Loc {
file: "parser/if-statements.mcl",
line: 2,
col: 7,
},
},
body: Block(
[],
),
else_if: None,
},
),
loc: Loc {
file: "parser/if-statements.mcl",
line: 2,
col: 3,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -0,0 +1,18 @@
if i > 3 {
}
if 1 {
} else {
}
if 1 {
} else if a > 3 {
} else {
}

212
old_tests/parser/loops.exp Normal file
View File

@@ -0,0 +1,212 @@
Program {
ast: Block(
[
Expr(
LocBox {
inner: ForLoop {
init: Statement(
LocBox {
inner: Let {
name: Ident(
"i",
),
typ: None,
val: Some(
LocBox {
inner: Literal(
Number(
Number {
val: 0,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 14,
},
},
),
},
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 8,
},
},
),
test: LocBox {
inner: BinOp {
typ: Lt,
left: LocBox {
inner: Path(
Path(
[
Ident(
"i",
),
],
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 17,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 10,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 22,
},
},
},
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 19,
},
},
on_loop: LocBox {
inner: BinOp {
typ: AddEq,
left: LocBox {
inner: Path(
Path(
[
Ident(
"i",
),
],
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 25,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 1,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 29,
},
},
},
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 27,
},
},
body: Block(
[],
),
},
loc: Loc {
file: "parser/loops.mcl",
line: 1,
col: 4,
},
},
),
Expr(
LocBox {
inner: WhileLoop {
test: LocBox {
inner: BinOp {
typ: Gt,
left: LocBox {
inner: Path(
Path(
[
Ident(
"i",
),
],
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 2,
col: 8,
},
},
right: LocBox {
inner: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
loc: Loc {
file: "parser/loops.mcl",
line: 2,
col: 12,
},
},
},
loc: Loc {
file: "parser/loops.mcl",
line: 2,
col: 10,
},
},
body: Block(
[],
),
},
loc: Loc {
file: "parser/loops.mcl",
line: 2,
col: 6,
},
},
),
Expr(
LocBox {
inner: InfLoop {
body: Block(
[],
),
},
loc: Loc {
file: "parser/loops.mcl",
line: 3,
col: 5,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -0,0 +1,3 @@
for let i = 0; i < 10; i += 1 {}
while i > 3 {}
loop {}

View File

@@ -0,0 +1,66 @@
Program {
ast: Block(
[
Statement(
LocBox {
inner: Struct(
Struct {
name: Ident(
"foo_t",
),
fields: [],
},
),
loc: Loc {
file: "parser/structs.mcl",
line: 2,
col: 7,
},
},
),
Statement(
LocBox {
inner: Struct(
Struct {
name: Ident(
"bar_t",
),
fields: [
(
Ident(
"a",
),
LocBox {
inner: Ref {
inner: Owned(
Ident(
"bar_t",
),
),
mutable: false,
},
loc: Loc {
file: "parser/structs.mcl",
line: 5,
col: 9,
},
},
),
],
},
),
loc: Loc {
file: "parser/structs.mcl",
line: 4,
col: 7,
},
},
),
],
),
structs: {},
enums: {},
types: {},
functions: {},
member_functions: {},
}

View File

@@ -0,0 +1,6 @@
struct foo_t {}
struct bar_t {
a: &bar_t
}