Setup parser testing with various tests

This commit is contained in:
Gvidas Juknevičius 2024-12-21 23:09:10 +02:00
parent 77738f7e20
commit 9d243e33b6
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
12 changed files with 483 additions and 6 deletions

View File

@ -1,6 +1,33 @@
Program {
ast: Block(
[],
[
Statement(
Enum {
name: Ident(
"Foo",
),
fields: [],
},
),
Statement(
Enum {
name: Ident(
"Bar",
),
fields: [
Ident(
"A",
),
Ident(
"B",
),
Ident(
"C",
),
],
},
),
],
),
structs: {},
enums: {},

View File

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

View File

@ -1,6 +1,57 @@
Program {
ast: Block(
[],
[
Expr(
BinOp {
typ: Eq,
left: UnOp {
typ: Star,
right: Path(
Path(
[
Ident(
"a",
),
],
),
),
},
right: BinOp {
typ: EqEq,
left: BinOp {
typ: Star,
left: Literal(
Number(
Number {
val: 1,
base: 10,
signed: false,
},
),
),
right: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
},
right: Literal(
Number(
Number {
val: 4,
base: 10,
signed: false,
},
),
),
},
},
),
],
),
structs: {},
enums: {},

View File

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

View File

@ -1,6 +1,191 @@
Program {
ast: Block(
[],
[
Statement(
Fn {
struct_name: None,
name: Ident(
"main",
),
params: [
(
Ident(
"argc",
),
Owned(
Ident(
"i32",
),
),
),
(
Ident(
"argv",
),
Ref {
inner: Array {
inner: Owned(
Ident(
"Str",
),
),
},
mutable: false,
},
),
],
ret_type: Some(
Owned(
Ident(
"i32",
),
),
),
qual_const: false,
qual_extern: None,
body: Some(
Block(
[
Expr(
Return(
Some(
Literal(
Number(
Number {
val: 0,
base: 10,
signed: false,
},
),
),
),
),
),
],
),
),
},
),
Statement(
Fn {
struct_name: Some(
Ident(
"Baz",
),
),
name: Ident(
"main",
),
params: [
(
Ident(
"self",
),
Ref {
inner: Owned(
Ident(
"Baz",
),
),
mutable: true,
},
),
(
Ident(
"a",
),
Ref {
inner: Owned(
Ident(
"Foo",
),
),
mutable: false,
},
),
(
Ident(
"b",
),
Ref {
inner: Owned(
Ident(
"Bar",
),
),
mutable: true,
},
),
],
ret_type: Some(
Ref {
inner: Owned(
Ident(
"Nya",
),
),
mutable: false,
},
),
qual_const: false,
qual_extern: None,
body: None,
},
),
Statement(
Fn {
struct_name: Some(
Ident(
"Baz",
),
),
name: Ident(
"main",
),
params: [
(
Ident(
"a",
),
Ref {
inner: Owned(
Ident(
"Foo",
),
),
mutable: false,
},
),
(
Ident(
"b",
),
Ref {
inner: Owned(
Ident(
"Bar",
),
),
mutable: true,
},
),
],
ret_type: Some(
Ref {
inner: Owned(
Ident(
"Nya",
),
),
mutable: false,
},
),
qual_const: false,
qual_extern: None,
body: None,
},
),
],
),
structs: {},
enums: {},

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

@ -1,7 +1,39 @@
Program {
ast: Block(
[
Expr(
If(
IfExpr {
test: BinOp {
typ: Gt,
left: Path(
Path(
[
Ident(
"i",
),
],
),
),
right: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
},
body: Block(
[],
),
else_if: None,
},
),
),
],
),
structs: {},
enums: {},
types: {},

View File

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

View File

@ -1,7 +1,111 @@
Program {
ast: Block(
[
Expr(
ForLoop {
init: Statement(
Let {
name: Ident(
"i",
),
typ: None,
val: Some(
Literal(
Number(
Number {
val: 0,
base: 10,
signed: false,
},
),
),
),
},
),
test: BinOp {
typ: Lt,
left: Path(
Path(
[
Ident(
"i",
),
],
),
),
right: Literal(
Number(
Number {
val: 10,
base: 10,
signed: false,
},
),
),
},
on_loop: BinOp {
typ: AddEq,
left: Path(
Path(
[
Ident(
"i",
),
],
),
),
right: Literal(
Number(
Number {
val: 1,
base: 10,
signed: false,
},
),
),
},
body: Block(
[],
),
},
),
Expr(
WhileLoop {
test: BinOp {
typ: Gt,
left: Path(
Path(
[
Ident(
"i",
),
],
),
),
right: Literal(
Number(
Number {
val: 3,
base: 10,
signed: false,
},
),
),
},
body: Block(
[],
),
},
),
Expr(
InfLoop {
body: Block(
[],
),
},
),
],
),
structs: {},
enums: {},
types: {},

View File

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

View File

@ -1,6 +1,37 @@
Program {
ast: Block(
[],
[
Statement(
Struct {
name: Ident(
"foo_t",
),
fields: [],
},
),
Statement(
Struct {
name: Ident(
"bar_t",
),
fields: [
(
Ident(
"a",
),
Ref {
inner: Owned(
Ident(
"bar_t",
),
),
mutable: false,
},
),
],
},
),
],
),
structs: {},
enums: {},

View File

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