Add binop impl lexing
This commit is contained in:
		
							parent
							
								
									89002f34e4
								
							
						
					
					
						commit
						eda78fc924
					
				
							
								
								
									
										12
									
								
								examples/custom_binop.reid
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								examples/custom_binop.reid
									
									
									
									
									
										Normal 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; | ||||
| } | ||||
| @ -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)] | ||||
|  | ||||
| @ -97,6 +97,7 @@ impl ast::Module { | ||||
|                     }; | ||||
|                     typedefs.push(def); | ||||
|                 } | ||||
|                 BinopDefinition(binop_definition) => todo!(), | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user