Tokenizer work to support operators
work in progress but committing to transfer
This commit is contained in:
parent
31da25a66e
commit
f09a6e14ba
@ -10,6 +10,7 @@ pub enum Token {
|
|||||||
NumLiteral(f64),
|
NumLiteral(f64),
|
||||||
StrLiteral(String),
|
StrLiteral(String),
|
||||||
Identifier(String),
|
Identifier(String),
|
||||||
|
Op(String),
|
||||||
Keyword(Kw)
|
Keyword(Kw)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +98,18 @@ pub fn tokenize(input: &str) -> Option<Vec<Token>> {
|
|||||||
Ok(f) => NumLiteral(f),
|
Ok(f) => NumLiteral(f),
|
||||||
Err(_) => return None
|
Err(_) => return None
|
||||||
}
|
}
|
||||||
|
} else if !char::is_alphanumeric(c) { //TODO see if this what I want
|
||||||
|
let mut buffer = String::with_capacity(20);
|
||||||
|
buffer.push(c);
|
||||||
|
loop {
|
||||||
|
if iter.peek().map_or(false, |x| is_digit(x) || *x == '.') {
|
||||||
|
let n = iter.next().unwrap();
|
||||||
|
buffer.push(n);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Op(buffer)
|
||||||
} else {
|
} else {
|
||||||
let mut buffer = String::with_capacity(20);
|
let mut buffer = String::with_capacity(20);
|
||||||
buffer.push(c);
|
buffer.push(c);
|
||||||
|
Loading…
Reference in New Issue
Block a user