This commit is contained in:
2026-05-19 12:35:23 +01:00
commit 9101eeefa0
5 changed files with 159 additions and 0 deletions
+103
View File
@@ -0,0 +1,103 @@
struct Type {
name: String,
params: Vec<Type>,
}
struct Decl {
name: String,
typed: Option<Type>,
default: Option<Expr>,
}
struct Param {
borrow: bool,
decl: Decl,
}
struct Call {
name: String,
params: Vec<Param>,
}
struct StructEntry {
name: Option<String>,
value: Expr
}
struct FuncEntry {
name: Option<String>,
value: Expr,
borrow: bool,
}
struct Class {
name: String,
entries: Vec<Decl>,
methods: Vec<Function>,
}
struct Block(Vec<Statement>);
struct Function {
annotations: Vec<Annotation>,
name: String,
params: Vec<FuncEntry>,
result: Type,
}
enum Overloaded {
Plus,
Get,
Set,
GetIndex,
SetIndex,
}
enum Annotation {
Inline,
Native,
Overload(Overloaded),
Expr(String),
}
enum Statement {
DeclLet(Decl),
DeclVar(Decl),
Assignment {
name: String,
expr: Expr,
},
Call(Call),
Return(Expr),
Block(Block),
While(Expr,Box<Statement>),
Loop(Box<Statement>),
Function(Function),
Break,
}
enum Expr {
Paren(Box<Expr>),
Call(Call),
Add {
left: Box<Expr>,
right: Box<Expr>,
},
String(String),
Number(String),
}
enum TopLevel {
Class(Class),
Statement(Statement)
}
struct Program(Vec<TopLevel>);
struct ParseError(String);
struct Reader(String);
impl Reader {
}
trait Parsed {
fn enter(reader: &mut Reader) -> ;
fn exit(reader: &mut Reader) -> Result<(), ParseError>;
}
impl Parsed for TopLevel {
}
impl Parsed for Statement {
}
impl Parsed for Expr {
}
fn parse(source: String) -> Result<Program,ParseError> {
Ok(Program(Vec::new()))
}