From eda78fc924e9c861171515a4a9ea9493f457c952 Mon Sep 17 00:00:00 2001 From: sofia Date: Thu, 24 Jul 2025 12:23:19 +0300 Subject: [PATCH] Add binop impl lexing --- examples/custom_binop.reid | 12 ++++++++++++ reid/src/ast/mod.rs | 9 +++++++++ reid/src/ast/process.rs | 1 + reid/src/lexer.rs | 10 +++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 examples/custom_binop.reid diff --git a/examples/custom_binop.reid b/examples/custom_binop.reid new file mode 100644 index 0000000..f337312 --- /dev/null +++ b/examples/custom_binop.reid @@ -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; +} diff --git a/reid/src/ast/mod.rs b/reid/src/ast/mod.rs index 3995f95..937e773 100644 --- a/reid/src/ast/mod.rs +++ b/reid/src/ast/mod.rs @@ -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)] diff --git a/reid/src/ast/process.rs b/reid/src/ast/process.rs index 466297f..e843c49 100644 --- a/reid/src/ast/process.rs +++ b/reid/src/ast/process.rs @@ -97,6 +97,7 @@ impl ast::Module { }; typedefs.push(def); } + BinopDefinition(binop_definition) => todo!(), } } diff --git a/reid/src/lexer.rs b/reid/src/lexer.rs index 97f1f6f..4a06b0a 100644 --- a/reid/src/lexer.rs +++ b/reid/src/lexer.rs @@ -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>(to_tokenize: T) -> Result, Error "for" => Token::For, "while" => Token::While, "in" => Token::In, + "impl" => Token::Impl, + "binop" => Token::Binop, _ => Token::Identifier(value), }; variant