From bbe6eb62893be93e418aa1c4104558d7a34be064 Mon Sep 17 00:00:00 2001 From: agentelement Date: Mon, 15 Apr 2024 18:55:25 -0700 Subject: [PATCH] fix: tokenize alphanumeric strings correctly --- src/parser.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index d72866d..a19463e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -100,11 +100,16 @@ pub fn tokenize_cla(input: &str) -> Result, 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))); } @@ -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]