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),
|
ExternFunction(FunctionSignature),
|
||||||
FunctionDefinition(FunctionDefinition),
|
FunctionDefinition(FunctionDefinition),
|
||||||
TypeDefinition(TypeDefinition),
|
TypeDefinition(TypeDefinition),
|
||||||
|
BinopDefinition(BinopDefinition),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct BinopDefinition {
|
||||||
|
lhs: (String, Type),
|
||||||
|
rhs: (String, Type),
|
||||||
|
return_ty: Type,
|
||||||
|
block: Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -97,6 +97,7 @@ impl ast::Module {
|
|||||||
};
|
};
|
||||||
typedefs.push(def);
|
typedefs.push(def);
|
||||||
}
|
}
|
||||||
|
BinopDefinition(binop_definition) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,12 @@ pub enum Token {
|
|||||||
While,
|
While,
|
||||||
/// `for`
|
/// `for`
|
||||||
For,
|
For,
|
||||||
/// `In`
|
/// `in`
|
||||||
In,
|
In,
|
||||||
|
/// `impl`
|
||||||
|
Impl,
|
||||||
|
/// `binop`
|
||||||
|
Binop,
|
||||||
|
|
||||||
// Symbols
|
// Symbols
|
||||||
/// `;`
|
/// `;`
|
||||||
@ -145,6 +149,8 @@ impl ToString for Token {
|
|||||||
Token::For => String::from("for"),
|
Token::For => String::from("for"),
|
||||||
Token::In => String::from("in"),
|
Token::In => String::from("in"),
|
||||||
Token::While => String::from("while"),
|
Token::While => String::from("while"),
|
||||||
|
Token::Impl => String::from("impl"),
|
||||||
|
Token::Binop => String::from("binop"),
|
||||||
Token::Semi => String::from(';'),
|
Token::Semi => String::from(';'),
|
||||||
Token::Equals => String::from('='),
|
Token::Equals => String::from('='),
|
||||||
Token::Colon => 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,
|
"for" => Token::For,
|
||||||
"while" => Token::While,
|
"while" => Token::While,
|
||||||
"in" => Token::In,
|
"in" => Token::In,
|
||||||
|
"impl" => Token::Impl,
|
||||||
|
"binop" => Token::Binop,
|
||||||
_ => Token::Identifier(value),
|
_ => Token::Identifier(value),
|
||||||
};
|
};
|
||||||
variant
|
variant
|
||||||
|
Loading…
Reference in New Issue
Block a user