diff --git a/src/lexer.rs b/src/lexer.rs index 5e34cd9..adf480f 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -54,8 +54,8 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> '\'' => tokens.push(Token::Unit(Foot)), '"' | '“' | '”' | '″' => tokens.push(Token::LexerKeyword(DoubleQuotes)), value if value.is_whitespace() => {}, + 'Ω' => tokens.push(Token::Unit(Ohm)), value if value.is_ascii_alphabetic() => { - let start_index = byte_index; let mut end_index = byte_index; while let Some(current_char) = chars.peek() { @@ -67,8 +67,12 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> if current_char.is_ascii_alphabetic() { byte_index += current_char.len_utf8(); - chars.next(); end_index += 1; + chars.next(); + } else if current_char == &'Ω' { + byte_index += current_char.len_utf8(); + end_index += current_char.len_utf8(); + chars.next(); } else { let string = &input[start_index..=end_index]; match string.trim_end() { @@ -323,6 +327,10 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> "ka" | "kiloamp" | "Kiloampere" => tokens.push(Token::Unit(Kiloampere)), "bi" | "biot" | "biots" | "aba" | "abampere" => tokens.push(Token::Unit(Abampere)), + "mΩ" | "milliohm" => tokens.push(Token::Unit(Milliohm)), + "Ω" | "ohm" => tokens.push(Token::Unit(Ohm)), + "kΩ" | "kiloohm" => tokens.push(Token::Unit(Kiloohm)), + // for pound-force per square inch "lbf" => tokens.push(Token::LexerKeyword(PoundForce)), "force" => tokens.push(Token::LexerKeyword(Force)), diff --git a/src/units.rs b/src/units.rs index d3c70c6..bb03fc7 100644 --- a/src/units.rs +++ b/src/units.rs @@ -25,6 +25,8 @@ pub enum UnitType { Power, /// A unit of electrical current, for example `Ampere` ElectricCurrent, + /// A unit of electric resistance, for example `Ohm` + Resistance, /// A unit of pressure, for example `Bar` Pressure, /// A unit of frequency, for example `Hertz` @@ -216,6 +218,10 @@ create_units!( Kiloampere: (ElectricCurrent, d128!(1000000)), Abampere: (ElectricCurrent, d128!(10000)), + Milliohm: (Resistance, d128!(1)), + Ohm: (Resistance, d128!(1000)), + Kiloohm: (Resistance, d128!(1000000)), + Pascal: (Pressure, d128!(1)), Kilopascal: (Pressure, d128!(1000)), Atmosphere: (Pressure, d128!(101325)),