From 74f8c165992261bd2547cf7323384d4651b59edd Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 8 Sep 2017 01:33:27 -0700 Subject: [PATCH] Fix bug with _ --- src/schala_lang/parsing.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 41efc96..7367e5f 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -92,6 +92,7 @@ pub fn tokenize(input: &str) -> Vec { 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 { '|' => 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() => {