Add binop impl lexing

This commit is contained in:
Sofia 2025-07-24 12:23:19 +03:00
parent 89002f34e4
commit eda78fc924
4 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,12 @@
// Arithmetic, function calls and imports!
impl binop (lhs: u32) + (rhs: u32) -> u32 {
}
fn main() -> u32 {
let value = 6;
let other = 15;
return value * other + 7 * -value;
}

View File

@ -207,6 +207,15 @@ pub enum TopLevelStatement {
ExternFunction(FunctionSignature),
FunctionDefinition(FunctionDefinition),
TypeDefinition(TypeDefinition),
BinopDefinition(BinopDefinition),
}
#[derive(Debug)]
pub struct BinopDefinition {
lhs: (String, Type),
rhs: (String, Type),
return_ty: Type,
block: Block,
}
#[derive(Debug)]

View File

@ -97,6 +97,7 @@ impl ast::Module {
};
typedefs.push(def);
}
BinopDefinition(binop_definition) => todo!(),
}
}

View File

@ -46,8 +46,12 @@ pub enum Token {
While,
/// `for`
For,
/// `In`
/// `in`
In,
/// `impl`
Impl,
/// `binop`
Binop,
// Symbols
/// `;`
@ -145,6 +149,8 @@ impl ToString for Token {
Token::For => String::from("for"),
Token::In => String::from("in"),
Token::While => String::from("while"),
Token::Impl => String::from("impl"),
Token::Binop => String::from("binop"),
Token::Semi => String::from(';'),
Token::Equals => String::from('='),
Token::Colon => String::from(':'),
@ -334,6 +340,8 @@ pub fn tokenize<T: Into<String>>(to_tokenize: T) -> Result<Vec<FullToken>, Error
"for" => Token::For,
"while" => Token::While,
"in" => Token::In,
"impl" => Token::Impl,
"binop" => Token::Binop,
_ => Token::Identifier(value),
};
variant