Handle underscores in identifiers
This commit is contained in:
parent
955c073174
commit
5147e1a3eb
@ -1231,6 +1231,7 @@ mod parse_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn parsing_identifiers() {
|
fn parsing_identifiers() {
|
||||||
parse_test!("a", AST(vec![exst!(val!("a"))]));
|
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![exst!(binexp!("+", val!("a"), val!("b")))]));
|
||||||
//parse_test!("a[b]", AST(vec![Expression(
|
//parse_test!("a[b]", AST(vec![Expression(
|
||||||
//parse_test!("a[]", <- TODO THIS NEEDS TO FAIL
|
//parse_test!("a[]", <- TODO THIS NEEDS TO FAIL
|
||||||
|
@ -217,7 +217,7 @@ fn handle_alphabetic(c: char, input: &mut Peekable<impl Iterator<Item=CharData>>
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
match input.peek().map(|&(_, _, c)| { c }) {
|
match input.peek().map(|&(_, _, c)| { c }) {
|
||||||
Some(c) if c.is_alphanumeric() => {
|
Some(c) if c.is_alphanumeric() || c == '_' => {
|
||||||
input.next();
|
input.next();
|
||||||
buf.push(c);
|
buf.push(c);
|
||||||
},
|
},
|
||||||
@ -300,6 +300,9 @@ mod schala_tokenizer_tests {
|
|||||||
fn underscores() {
|
fn underscores() {
|
||||||
let token_types: Vec<TokenType> = tokenize("4_8").into_iter().map(move |t| t.token_type).collect();
|
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")]);
|
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]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user