Fix bug with _

This commit is contained in:
greg 2017-09-08 01:33:27 -07:00
parent a82f24a158
commit 74f8c16599
1 changed files with 6 additions and 1 deletions

View File

@ -92,6 +92,7 @@ pub fn tokenize(input: &str) -> Vec<Token> {
let mut input: CharIter = input.chars().enumerate().peekable();
while let Some((idx, c)) = input.next() {
println!("C: {}", c);
let cur_tok_type = match c {
'#' => {
if let Some(&(_, '{')) = input.peek() {
@ -114,7 +115,7 @@ pub fn tokenize(input: &str) -> Vec<Token> {
'|' => Pipe,
'"' => handle_quote(&mut input),
c if is_digit(&c) => handle_digit(c, &mut input),
c @ '_' | c if c.is_alphabetic() => handle_alphabetic(c, &mut input), //TODO I'll probably have to rewrite this if I care about types being uppercase, also type parameterization
c if c.is_alphabetic() || c == '_' => handle_alphabetic(c, &mut input), //TODO I'll probably have to rewrite this if I care about types being uppercase, also type parameterization
c => handle_operator(c, &mut input),
};
tokens.push(Token { token_type: cur_tok_type, offset: idx });
@ -166,6 +167,10 @@ fn handle_quote(input: &mut CharIter) -> TokenType {
fn handle_alphabetic(c: char, input: &mut CharIter) -> TokenType {
let mut buf = String::new();
buf.push(c);
if c == '_' && input.peek().map(|&(_, c)| { !c.is_alphabetic() }).unwrap_or(true) {
return TokenType::Identifier(Rc::new(format!("_")))
}
loop {
match input.peek().map(|&(_, c)| { c }) {
Some(c) if c.is_alphanumeric() => {