From 99943ecacd21c09c491e03c2bd08de364345ccea Mon Sep 17 00:00:00 2001 From: Kasper Date: Wed, 7 Jul 2021 05:36:57 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20`=CE=A9`=20lexing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + src/lexer.rs | 4 ++-- src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7545292..cbcf6ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Disallow named number followed by smaller named number (like 1 million thousand) - Fix/improve parsing of multi-word units - Fix light second parsed as light year +- Fix `Ω` lexing ## 1.6.0 - 2021 Jul 3 - Add support for non-US "metre" and "litre" spellings diff --git a/src/lexer.rs b/src/lexer.rs index 6c83958..4f9cf9e 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -136,7 +136,6 @@ fn parse_token(c: &str, lexer: &mut Lexer) -> Result<(), String> { "π" => tokens.push(Token::Constant(Pi)), "'" => tokens.push(Token::Unit(Foot)), "\"" | "“" | "”" | "″" => tokens.push(Token::LexerKeyword(DoubleQuotes)), - "Ω" | "Ω" => tokens.push(Token::Unit(Ohm)), _ => { return Err(format!("Invalid character: {}", c)); }, @@ -597,7 +596,7 @@ struct Lexer<'a> { /// Lex an input string and returns [`Token`]s pub fn lex(input: &str, remove_trailing_operator: bool, default_degree: Unit) -> Result, String> { - let mut input = input.replace(",", "").to_lowercase(); + let mut input = input.replace(",", "").to_ascii_lowercase(); if remove_trailing_operator { match &input.chars().last().unwrap_or('x') { @@ -977,5 +976,6 @@ mod tests { run_lex("12 pound+", vec![numtok!(12), Token::Unit(Pound), Token::Operator(Plus)]); run_lex("5 π m", vec![numtok!(5), Token::Constant(Pi), Token::Unit(Meter)]); + run_lex("5 Ω + 2 mΩ", vec![numtok!(5), Token::Unit(Ohm), Token::Operator(Plus), numtok!(2), Token::Unit(Milliohm)]); } } diff --git a/src/lib.rs b/src/lib.rs index 7274707..a3eb2f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ //! ``` use std::fmt::{self, Display}; -use std::time::{Instant}; +use std::time::Instant; use decimal::d128; use crate::units::Unit;