Handle underscores in identifiers

This commit is contained in:
greg 2018-11-15 16:19:53 -08:00
parent 955c073174
commit 5147e1a3eb
2 changed files with 5 additions and 1 deletions

View File

@ -1231,6 +1231,7 @@ mod parse_tests {
#[test]
fn parsing_identifiers() {
parse_test!("a", AST(vec![exst!(val!("a"))]));
parse_test!("some_value", AST(vec![exst!(val!("some_value"))]));
parse_test!("a + b", AST(vec![exst!(binexp!("+", val!("a"), val!("b")))]));
//parse_test!("a[b]", AST(vec![Expression(
//parse_test!("a[]", <- TODO THIS NEEDS TO FAIL

View File

@ -217,7 +217,7 @@ fn handle_alphabetic(c: char, input: &mut Peekable<impl Iterator<Item=CharData>>
loop {
match input.peek().map(|&(_, _, c)| { c }) {
Some(c) if c.is_alphanumeric() => {
Some(c) if c.is_alphanumeric() || c == '_' => {
input.next();
buf.push(c);
},
@ -300,6 +300,9 @@ mod schala_tokenizer_tests {
fn underscores() {
let token_types: Vec<TokenType> = tokenize("4_8").into_iter().map(move |t| t.token_type).collect();
assert_eq!(token_types, vec![digit!("4"), Underscore, digit!("8")]);
let token_types2: Vec<TokenType> = tokenize("aba_yo").into_iter().map(move |t| t.token_type).collect();
assert_eq!(token_types2, vec![ident!("aba_yo")]);
}
#[test]