Skip to content

Commit

Permalink
fix: tokenize alphanumeric strings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentElement committed Apr 16, 2024
1 parent 0a613d8 commit bbe6eb6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ pub fn tokenize_cla(input: &str) -> Result<Vec<CToken>, ParseError> {
match c {
'\\' | 'λ' => {
let mut name = String::new();
let mut first_char = true;
for (i, c) in &mut chars {
if c == '.' {
break;
} else if c.is_alphabetic() {
name.push(c)
} else if first_char && c.is_alphabetic() {
first_char = false;
name.push(c);
}
else if !first_char && c.is_alphanumeric() {
name.push(c);
} else {
return Err(InvalidCharacter((i, c)));
}
Expand Down Expand Up @@ -302,6 +307,7 @@ mod tests {
fn tokenization_error() {
assert_eq!(tokenize_dbr("λλx2"), Err(InvalidCharacter((2, 'x'))));
assert_eq!(tokenize_cla("λa.λb a"), Err(InvalidCharacter((5, ' '))));
assert_eq!(tokenize_cla("λa1.λb a1"), Err(InvalidCharacter((6, ' '))));
}

#[test]
Expand Down

0 comments on commit bbe6eb6

Please sign in to comment.