I can see the light

This commit is contained in:
2025-05-02 18:18:13 -04:00
parent d7222cc7a4
commit 57c46b653e
35 changed files with 1247 additions and 1000 deletions

View File

@@ -1,7 +1,7 @@
use std::fmt::Debug;
use super::{
CompilerMsg, MaybeParsable, Node, PExpr, PIdent, PType, Parsable, ParseResult, ParserCtx,
CompilerMsg, Node, PExpr, PIdent, PType, Parsable, ParseResult, ParserCtx,
Symbol, Token,
};
@@ -55,28 +55,28 @@ pub enum SelfType {
Take,
}
impl MaybeParsable for SelfVar {
fn maybe_parse(ctx: &mut ParserCtx) -> Result<Option<Self>, CompilerMsg> {
if let Some(mut next) = ctx.peek() {
let mut ty = SelfType::Take;
if next.is_symbol(Symbol::Ampersand) {
ctx.next();
ty = SelfType::Ref;
next = ctx.expect_peek()?;
}
if let Token::Word(name) = &next.token {
if name == "self" {
ctx.next();
return Ok(Some(Self { ty }));
}
}
if ty != SelfType::Take {
return Err(CompilerMsg::unexpected_token(next, "self"));
}
}
Ok(None)
}
}
// impl Parsable for Option<SelfVar> {
// fn maybe_parse(ctx: &mut ParserCtx) -> Result<Option<Self>, CompilerMsg> {
// if let Some(mut next) = ctx.peek() {
// let mut ty = SelfType::Take;
// if next.is_symbol(Symbol::Ampersand) {
// ctx.next();
// ty = SelfType::Ref;
// next = ctx.expect_peek()?;
// }
// if let Token::Word(name) = &next.token {
// if name == "self" {
// ctx.next();
// return Ok(Some(Self { ty }));
// }
// }
// if ty != SelfType::Take {
// return Err(CompilerMsg::unexpected_token(next, "self"));
// }
// }
// Ok(None)
// }
// }
impl Debug for PVarDef {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {