Working parser

This commit is contained in:
2026-04-13 14:17:14 +02:00
parent 032d7761d8
commit 6b908754e3
3 changed files with 21 additions and 4 deletions
+1
View File
@@ -48,6 +48,7 @@ fn cmd_build(path: &str) {
match parser::parse(&source) {
Ok(ast) => {
println!("parsed {} top-level items", ast.statements.len());
println!("{:#?}", ast.statements)
// codegen will go here
}
Err(e) => {
+16 -4
View File
@@ -16,12 +16,24 @@ pub fn parse(source: &str) -> Result<Program, ParseError> {
let pairs = MistParser::parse(Rule::program, source)?;
let mut statements = vec![];
// pairs is an iterator over the top-level program pair
// we need to get its inner children
for pair in pairs {
match pair.as_rule() {
Rule::function_decl => statements.push(TopLevel::Function(parse_function(pair))),
Rule::struct_decl => statements.push(TopLevel::Struct(parse_struct(pair))),
Rule::class_decl => statements.push(TopLevel::Class(parse_class(pair))),
Rule::import_decl => statements.push(TopLevel::Import(parse_import(pair))),
Rule::program => {
for inner in pair.into_inner() {
match inner.as_rule() {
Rule::function_decl => {
statements.push(TopLevel::Function(parse_function(inner)))
}
Rule::struct_decl => statements.push(TopLevel::Struct(parse_struct(inner))),
Rule::class_decl => statements.push(TopLevel::Class(parse_class(inner))),
Rule::import_decl => statements.push(TopLevel::Import(parse_import(inner))),
Rule::EOI => {}
_ => {}
}
}
}
Rule::EOI => {}
_ => {}
}
+4
View File
@@ -0,0 +1,4 @@
fn main() {
let message: string = "Hello, World!"
print(message)
}