Added more keywords for units of current and resistance
This commit is contained in:
parent
50cac79d7a
commit
f03850f006
18
src/lexer.rs
18
src/lexer.rs
@ -13,7 +13,7 @@ use crate::units::Unit::*;
|
|||||||
|
|
||||||
pub const fn is_alphabetic_extended(input: &char) -> bool {
|
pub const fn is_alphabetic_extended(input: &char) -> bool {
|
||||||
match input {
|
match input {
|
||||||
'A'..='Z' | 'a'..='z' | 'Ω' | 'µ' | 'μ' | 'π' => true,
|
'A'..='Z' | 'a'..='z' | 'Ω' | 'Ω' | 'µ' | 'μ' | 'π' => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
|
|||||||
'\'' => tokens.push(Token::Unit(Foot)),
|
'\'' => tokens.push(Token::Unit(Foot)),
|
||||||
'"' | '“' | '”' | '″' => tokens.push(Token::LexerKeyword(DoubleQuotes)),
|
'"' | '“' | '”' | '″' => tokens.push(Token::LexerKeyword(DoubleQuotes)),
|
||||||
value if value.is_whitespace() => {},
|
value if value.is_whitespace() => {},
|
||||||
'Ω' => tokens.push(Token::Unit(Ohm)),
|
'Ω' | 'Ω' => tokens.push(Token::Unit(Ohm)),
|
||||||
value if is_alphabetic_extended(&value) => {
|
value if is_alphabetic_extended(&value) => {
|
||||||
let start_index = byte_index;
|
let start_index = byte_index;
|
||||||
// account for chars longer than one byte
|
// account for chars longer than one byte
|
||||||
@ -327,14 +327,14 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
|
|||||||
"hp" | "hps" | "horsepower" | "horsepowers" => tokens.push(Token::Unit(Horsepower)),
|
"hp" | "hps" | "horsepower" | "horsepowers" => tokens.push(Token::Unit(Horsepower)),
|
||||||
"mhp" | "hpm" | "metric hp" | "metric hps" | "metric horsepower" | "metric horsepowers" => tokens.push(Token::Unit(MetricHorsepower)),
|
"mhp" | "hpm" | "metric hp" | "metric hps" | "metric horsepower" | "metric horsepowers" => tokens.push(Token::Unit(MetricHorsepower)),
|
||||||
|
|
||||||
"ma" | "milliamp" | "milliampere" => tokens.push(Token::Unit(Milliampere)),
|
"ma" | "milliamp" | "milliamps" | "milliampere" | "milliamperes" => tokens.push(Token::Unit(Milliampere)),
|
||||||
"a" | "amp" | "ampere" => tokens.push(Token::Unit(Ampere)),
|
"a" | "amp" | "amps" | "ampere" | "amperes" => tokens.push(Token::Unit(Ampere)),
|
||||||
"ka" | "kiloamp" | "Kiloampere" => tokens.push(Token::Unit(Kiloampere)),
|
"ka" | "kiloamp" | "kiloamps" | "kiloampere" | "kiloamperes" => tokens.push(Token::Unit(Kiloampere)),
|
||||||
"bi" | "biot" | "biots" | "aba" | "abampere" => tokens.push(Token::Unit(Abampere)),
|
"bi" | "biot" | "biots" | "aba" | "abampere" | "abamperes" => tokens.push(Token::Unit(Abampere)),
|
||||||
|
|
||||||
"mΩ" | "milliohm" => tokens.push(Token::Unit(Milliohm)),
|
"mΩ" | "mΩ" | "milliohm" | "milliohms" => tokens.push(Token::Unit(Milliohm)),
|
||||||
"Ω" | "ohm" => tokens.push(Token::Unit(Ohm)),
|
"Ω" | "Ω" | "ohm" | "ohms" => tokens.push(Token::Unit(Ohm)),
|
||||||
"kΩ" | "kiloohm" => tokens.push(Token::Unit(Kiloohm)),
|
"kΩ" | "kΩ" | "kiloohm" | "kiloohms" => tokens.push(Token::Unit(Kiloohm)),
|
||||||
|
|
||||||
// for pound-force per square inch
|
// for pound-force per square inch
|
||||||
"lbf" => tokens.push(Token::LexerKeyword(PoundForce)),
|
"lbf" => tokens.push(Token::LexerKeyword(PoundForce)),
|
||||||
|
|||||||
@ -681,6 +681,9 @@ mod tests {
|
|||||||
assert_eq!(convert_test(1000.0, Ampere, Kiloampere), 1.0);
|
assert_eq!(convert_test(1000.0, Ampere, Kiloampere), 1.0);
|
||||||
assert_eq!(convert_test(10.0, Ampere, Abampere), 1.0);
|
assert_eq!(convert_test(10.0, Ampere, Abampere), 1.0);
|
||||||
|
|
||||||
|
assert_eq!(convert_test(1000.0, Milliohm, Ohm), 1.0);
|
||||||
|
assert_eq!(convert_test(1000.0, Ohm, Kiloohm), 1.0);
|
||||||
|
|
||||||
assert_eq!(convert_test(1000.0, Pascal, Kilopascal), 1.0);
|
assert_eq!(convert_test(1000.0, Pascal, Kilopascal), 1.0);
|
||||||
assert_eq!(convert_test(101325.0, Pascal, Atmosphere), 1.0);
|
assert_eq!(convert_test(101325.0, Pascal, Atmosphere), 1.0);
|
||||||
assert_eq!(convert_test(100.0, Pascal, Millibar), 1.0);
|
assert_eq!(convert_test(100.0, Pascal, Millibar), 1.0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user