22 lines
479 B
Rust
22 lines
479 B
Rust
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
|
|
}
|
|
}
|