Initial commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
use super::Token;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Operator {
|
||||
Plus,
|
||||
Minus,
|
||||
Star, // multiplication
|
||||
Slash, // division
|
||||
}
|
||||
|
||||
pub fn parse_operator(input: &str) -> Option<(Token, &str)> {
|
||||
let c: char = input.chars().next()?;
|
||||
let input = &input[1..];
|
||||
match c {
|
||||
'+' => Some((Token::Op(Operator::Plus), input)),
|
||||
'-' => Some((Token::Op(Operator::Minus), input)),
|
||||
'*' => Some((Token::Op(Operator::Star), input)),
|
||||
'/' => Some((Token::Op(Operator::Slash), input)),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user