From 6d682d745244b47ceae8037b43610f8e1b331967 Mon Sep 17 00:00:00 2001 From: Antal Spector-Zabusky Date: Thu, 9 Jan 2025 01:10:49 -0500 Subject: [PATCH] fix!: don't parse `NaN`, `inf`, and `infinity` as floats We could have resolved this the other way, by marking these keywords as reserved, but the Quil spec doesn't allow for `NaN` or `Infinity` and I think this is more useful for our purposes. --- quil-rs/src/parser/lexer/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/quil-rs/src/parser/lexer/mod.rs b/quil-rs/src/parser/lexer/mod.rs index 4f22ea93..4102ec82 100644 --- a/quil-rs/src/parser/lexer/mod.rs +++ b/quil-rs/src/parser/lexer/mod.rs @@ -170,9 +170,12 @@ fn lex_token(input: LexInput) -> InternalLexResult { token_with_location(lex_string), // Operator must come before number (or it may be parsed as a prefix) token_with_location(lex_operator), - token_with_location(lex_number), token_with_location(lex_variable), + // Identifiers must come before numbers so that `NaN`, `Inf`, and `Infinity` aren't + // parsed as floats; Nom, as of version 7.1.1, will parse those strings, + // case-insensitively, as floats token_with_location(lex_keyword_or_identifier), + token_with_location(lex_number), ), )(input) }