structs r a lot more sane in code, can now actually assign & stuff

This commit is contained in:
2025-04-08 20:00:16 -04:00
parent cb9a366f43
commit 26e7a4da4a
21 changed files with 405 additions and 197 deletions
+5
View File
@@ -22,6 +22,7 @@ pub enum PExpr {
If(BoxNode, BoxNode),
Loop(BoxNode),
Break,
Continue,
}
impl Parsable for PExpr {
@@ -57,6 +58,9 @@ impl Parsable for PExpr {
} else if next.is_keyword(Keyword::Break) {
ctx.next();
Self::Break
} else if next.is_keyword(Keyword::Continue) {
ctx.next();
Self::Continue
} else if next.is_keyword(Keyword::Asm) {
ctx.next();
Self::AsmBlock(ctx.parse()?)
@@ -165,6 +169,7 @@ impl Debug for PExpr {
PExpr::If(cond, res) => write!(f, "if {cond:?} then {res:?}")?,
PExpr::Loop(res) => write!(f, "loop -> {res:?}")?,
PExpr::Break => write!(f, "break")?,
PExpr::Continue => write!(f, "continue")?,
}
Ok(())
}
+7 -3
View File
@@ -1,8 +1,8 @@
use super::{PExpr, Keyword, Node, Parsable, ParseResult, ParserCtx, Symbol, Token, PVarDef};
use super::{Keyword, Node, PExpr, PVarDef, Parsable, ParseResult, ParserCtx, Symbol, Token};
pub enum PStatement {
Let(Node<PVarDef>, Node<PExpr>),
Return(Node<PExpr>),
Return(Option<Node<PExpr>>),
Expr(Node<PExpr>),
}
@@ -18,7 +18,11 @@ impl Parsable for PStatement {
}
Token::Keyword(Keyword::Return) => {
ctx.next();
ctx.parse().map(Self::Return)
if ctx.peek().is_some_and(|t| t.is_symbol(Symbol::Semicolon)) {
ParseResult::Ok(Self::Return(None))
} else {
ctx.parse().map(|res| Self::Return(Some(res)))
}
}
_ => ctx.parse().map(Self::Expr),
}