Added units of resistance (ohm)

This commit is contained in:
Kasper 2020-11-21 01:22:25 +01:00
parent 5371f8d5ac
commit 5da0c5e3d7
2 changed files with 16 additions and 2 deletions

View File

@ -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)),
"" | "milliohm" => tokens.push(Token::Unit(Milliohm)),
"Ω" | "ohm" => tokens.push(Token::Unit(Ohm)),
"" | "kiloohm" => tokens.push(Token::Unit(Kiloohm)),
// for pound-force per square inch
"lbf" => tokens.push(Token::LexerKeyword(PoundForce)),
"force" => tokens.push(Token::LexerKeyword(Force)),

View File

@ -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)),