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

1
tests/mod.rs Normal file
View File

@@ -0,0 +1 @@
mod parser;

View File

@@ -1,55 +0,0 @@
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

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

3
tests/parser/expr.rs Normal file
View File

@@ -0,0 +1,3 @@

View File

@@ -1,908 +0,0 @@
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

@@ -1,8 +0,0 @@
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

@@ -1,306 +0,0 @@
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

@@ -1,5 +0,0 @@
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,70 +0,0 @@
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

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

View File

@@ -1,212 +0,0 @@
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

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

3
tests/parser/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
mod expr;
mod stat;
mod typ;

0
tests/parser/stat.rs Normal file
View File

View File

@@ -1,66 +0,0 @@
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

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

190
tests/parser/typ.rs Normal file
View File

@@ -0,0 +1,190 @@
use std::vec;
use mclangc::{common::{Loc, loc::LocBox}, parser::{self, ast::{Ident, Keyword, Program, Punctuation, TokenType, statement::{Enum, Struct}, typ::Type}}, tokeniser::Token, validator::predefined::{BuiltinType, get_builtin_from_name, load_builtin}};
fn get_prog() -> Program {
let mut prog = Program::default();
load_builtin(&mut prog);
let loc = Loc::default();
prog.structs.insert(Ident::new("MyStruct"), LocBox::new(&loc, Struct {
name: Ident::new("MyStruct"),
fields: vec![
(Ident::new("foo"), LocBox::new(&loc, BuiltinType::usize())),
(Ident::new("bar"), LocBox::new(&loc, BuiltinType::bool())),
(Ident::new("baz"), LocBox::new(&loc, Type::Owned(Ident::new("str")).as_ref())),
]
}));
prog.enums.insert(Ident::new("MyEnum"), LocBox::new(&loc, Enum {
name: Ident::new("MyEnum"),
fields: vec![],
}));
prog
}
#[test]
fn parse_type_named_struct() {
let mut tokens = vec![
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct"))))
}
#[test]
fn parse_type_named_enum() {
let mut tokens = vec![
Token::new_test(TokenType::Ident(Ident::new("MyEnum")))
];
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyEnum"))))
}
#[test]
fn parse_type_ref() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref()))
}
#[test]
fn parse_type_ref2() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref().as_ref()))
}
#[test]
fn parse_type_ref3() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref().as_ref().as_ref()))
}
#[test]
fn parse_type_mut_ref() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref_mut()))
}
#[test]
fn parse_type_mut_ref2() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref_mut().as_ref_mut()))
}
#[test]
fn parse_type_mut_ref3() {
let mut tokens = vec![
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Punct(Punctuation::Ampersand)),
Token::new_test(TokenType::Keyword(Keyword::Mut)),
Token::new_test(TokenType::Ident(Ident::new("MyStruct")))
];
tokens.reverse();
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), Type::Owned(Ident::new("MyStruct")).as_ref_mut().as_ref_mut().as_ref_mut()))
}
fn test_builtin(s: &str) {
let mut tokens = vec![
Token::new_test(TokenType::Ident(Ident::new(s)))
];
let ret = parser::typ::parse_type(&mut tokens);
assert!(ret.is_ok());
assert_eq!(ret.unwrap(), LocBox::new(&Loc::default(), get_builtin_from_name(s).unwrap()))
}
#[test]
fn parse_type_builtin_usize() {
test_builtin("usize");
}
#[test]
fn parse_type_builtin_isize() {
test_builtin("isize");
}
#[test]
fn parse_type_builtin_u8() {
test_builtin("u8");
}
#[test]
fn parse_type_builtin_i8() {
test_builtin("i8");
}
#[test]
fn parse_type_builtin_u16() {
test_builtin("u16");
}
#[test]
fn parse_type_builtin_i16() {
test_builtin("i16");
}
#[test]
fn parse_type_builtin_u32() {
test_builtin("u32");
}
#[test]
fn parse_type_builtin_i32() {
test_builtin("i32");
}
#[test]
fn parse_type_builtin_u64() {
test_builtin("u64");
}
#[test]
fn parse_type_builtin_i64() {
test_builtin("i64");
}
#[test]
fn parse_type_builtin_void() {
test_builtin("void");
}
#[test]
fn parse_type_builtin_char() {
test_builtin("char");
}
#[test]
fn parse_type_builtin_bool() {
test_builtin("bool");
}

View File

@@ -1 +0,0 @@
[]

View File

@@ -1,7 +0,0 @@
// Hello, this is a single line comment
/*
And this is a multiline comment, which is
useful for longer documentation
*/

View File

@@ -1,62 +0,0 @@
[
Token {
loc: Loc {
file: "tokeniser/delimiters.mcl",
line: 3,
col: 4,
},
tt: Delim(
ParenR,
),
},
Token {
loc: Loc {
file: "tokeniser/delimiters.mcl",
line: 3,
col: 2,
},
tt: Delim(
ParenL,
),
},
Token {
loc: Loc {
file: "tokeniser/delimiters.mcl",
line: 2,
col: 4,
},
tt: Delim(
CurlyR,
),
},
Token {
loc: Loc {
file: "tokeniser/delimiters.mcl",
line: 2,
col: 2,
},
tt: Delim(
CurlyL,
),
},
Token {
loc: Loc {
file: "tokeniser/delimiters.mcl",
line: 1,
col: 4,
},
tt: Delim(
SquareR,
),
},
Token {
loc: Loc {
file: "tokeniser/delimiters.mcl",
line: 1,
col: 2,
},
tt: Delim(
SquareL,
),
},
]

View File

@@ -1,3 +0,0 @@
[ ]
{ }
( )

View File

@@ -1,212 +0,0 @@
[
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 21,
col: 5,
},
tt: Keyword(
Loop,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 20,
col: 3,
},
tt: Keyword(
As,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 19,
col: 7,
},
tt: Keyword(
Return,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 18,
col: 7,
},
tt: Keyword(
Extern,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 17,
col: 8,
},
tt: Keyword(
Include,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 16,
col: 6,
},
tt: Keyword(
False,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 15,
col: 5,
},
tt: Keyword(
True,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 14,
col: 7,
},
tt: Keyword(
Static,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 13,
col: 4,
},
tt: Keyword(
Mut,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 12,
col: 6,
},
tt: Keyword(
Const,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 11,
col: 4,
},
tt: Keyword(
Let,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 10,
col: 9,
},
tt: Keyword(
Continue,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 9,
col: 6,
},
tt: Keyword(
Break,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 8,
col: 4,
},
tt: Keyword(
For,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 7,
col: 6,
},
tt: Keyword(
While,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 6,
col: 5,
},
tt: Keyword(
Type,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 5,
col: 5,
},
tt: Keyword(
Enum,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 4,
col: 7,
},
tt: Keyword(
Struct,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 3,
col: 5,
},
tt: Keyword(
Else,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 2,
col: 3,
},
tt: Keyword(
If,
),
},
Token {
loc: Loc {
file: "tokeniser/keywords.mcl",
line: 1,
col: 3,
},
tt: Keyword(
Fn,
),
},
]

View File

@@ -1,21 +0,0 @@
fn
if
else
struct
enum
type
while
for
break
continue
let
const
mut
static
true
false
include
extern
return
as
loop

View File

@@ -1,96 +0,0 @@
[
Token {
loc: Loc {
file: "tokeniser/literals.mcl",
line: 7,
col: 11,
},
tt: Number(
Number {
val: 173,
base: 2,
signed: false,
},
),
},
Token {
loc: Loc {
file: "tokeniser/literals.mcl",
line: 6,
col: 8,
},
tt: Number(
Number {
val: 13633,
base: 8,
signed: false,
},
),
},
Token {
loc: Loc {
file: "tokeniser/literals.mcl",
line: 5,
col: 9,
},
tt: Number(
Number {
val: 16759299,
base: 16,
signed: false,
},
),
},
Token {
loc: Loc {
file: "tokeniser/literals.mcl",
line: 4,
col: 3,
},
tt: Number(
Number {
val: 21,
base: 10,
signed: false,
},
),
},
Token {
loc: Loc {
file: "tokeniser/literals.mcl",
line: 3,
col: 22,
},
tt: String(
TString {
val: "this is a c string!",
cstr: true,
},
),
},
Token {
loc: Loc {
file: "tokeniser/literals.mcl",
line: 2,
col: 27,
},
tt: String(
TString {
val: "this is a normal string!",
cstr: false,
},
),
},
Token {
loc: Loc {
file: "tokeniser/literals.mcl",
line: 1,
col: 4,
},
tt: Char(
Char(
'c',
),
),
},
]

View File

@@ -1,8 +0,0 @@
'c'
"this is a normal string!"
c"this is a c string!"
21
0xFfbA03
0o32501
0b10101101

View File

@@ -1,382 +0,0 @@
[
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 38,
col: 2,
},
tt: Punct(
Pathaccess,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 37,
col: 2,
},
tt: Punct(
Fieldaccess,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 36,
col: 2,
},
tt: Punct(
Neq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 35,
col: 2,
},
tt: Punct(
EqEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 34,
col: 2,
},
tt: Punct(
Eq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 33,
col: 2,
},
tt: Punct(
XorEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 32,
col: 2,
},
tt: Punct(
OrEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 31,
col: 2,
},
tt: Punct(
AndEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 30,
col: 2,
},
tt: Punct(
ShrEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 29,
col: 2,
},
tt: Punct(
ShlEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 28,
col: 2,
},
tt: Punct(
ModEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 27,
col: 2,
},
tt: Punct(
MulEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 26,
col: 2,
},
tt: Punct(
DivEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 25,
col: 2,
},
tt: Punct(
SubEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 24,
col: 2,
},
tt: Punct(
AddEq,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 23,
col: 2,
},
tt: Punct(
Xor,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 22,
col: 2,
},
tt: Punct(
Le,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 21,
col: 2,
},
tt: Punct(
Ge,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 20,
col: 2,
},
tt: Punct(
Lt,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 19,
col: 2,
},
tt: Punct(
Gt,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 18,
col: 2,
},
tt: Punct(
Or,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 17,
col: 2,
},
tt: Punct(
OrOr,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 16,
col: 2,
},
tt: Punct(
AndAnd,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 15,
col: 2,
},
tt: Punct(
Shr,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 14,
col: 2,
},
tt: Punct(
Shl,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 13,
col: 2,
},
tt: Punct(
Mod,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 12,
col: 2,
},
tt: Punct(
Div,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 11,
col: 2,
},
tt: Punct(
Not,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 10,
col: 2,
},
tt: Punct(
Star,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 9,
col: 2,
},
tt: Punct(
Ampersand,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 8,
col: 2,
},
tt: Punct(
Comma,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 7,
col: 2,
},
tt: Punct(
Minus,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 6,
col: 2,
},
tt: Punct(
Plus,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 5,
col: 2,
},
tt: Punct(
FatArrow,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 4,
col: 2,
},
tt: Punct(
Arrow,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 3,
col: 2,
},
tt: Punct(
Pathaccess,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 2,
col: 2,
},
tt: Punct(
Colon,
),
},
Token {
loc: Loc {
file: "tokeniser/punctuation.mcl",
line: 1,
col: 2,
},
tt: Punct(
Semi,
),
},
]

View File

@@ -1,39 +0,0 @@
;
:
::
->
=>
+
-
,
&
*
!
/
%
<<
>>
&&
||
|
>
<
>=
<=
^
+=
-=
/=
*=
%=
<<=
>>=
&=
|=
^=
=
==
!=
.
::