Added units of resistance (ohm)
This commit is contained in:
parent
5371f8d5ac
commit
5da0c5e3d7
12
src/lexer.rs
12
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::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)),
|
||||||
value if value.is_ascii_alphabetic() => {
|
value if value.is_ascii_alphabetic() => {
|
||||||
|
|
||||||
let start_index = byte_index;
|
let start_index = byte_index;
|
||||||
let mut end_index = byte_index;
|
let mut end_index = byte_index;
|
||||||
while let Some(current_char) = chars.peek() {
|
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() {
|
if current_char.is_ascii_alphabetic() {
|
||||||
byte_index += current_char.len_utf8();
|
byte_index += current_char.len_utf8();
|
||||||
chars.next();
|
|
||||||
end_index += 1;
|
end_index += 1;
|
||||||
|
chars.next();
|
||||||
|
} else if current_char == &'Ω' {
|
||||||
|
byte_index += current_char.len_utf8();
|
||||||
|
end_index += current_char.len_utf8();
|
||||||
|
chars.next();
|
||||||
} else {
|
} else {
|
||||||
let string = &input[start_index..=end_index];
|
let string = &input[start_index..=end_index];
|
||||||
match string.trim_end() {
|
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)),
|
"ka" | "kiloamp" | "Kiloampere" => tokens.push(Token::Unit(Kiloampere)),
|
||||||
"bi" | "biot" | "biots" | "aba" | "abampere" => tokens.push(Token::Unit(Abampere)),
|
"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
|
// for pound-force per square inch
|
||||||
"lbf" => tokens.push(Token::LexerKeyword(PoundForce)),
|
"lbf" => tokens.push(Token::LexerKeyword(PoundForce)),
|
||||||
"force" => tokens.push(Token::LexerKeyword(Force)),
|
"force" => tokens.push(Token::LexerKeyword(Force)),
|
||||||
|
|||||||
@ -25,6 +25,8 @@ pub enum UnitType {
|
|||||||
Power,
|
Power,
|
||||||
/// A unit of electrical current, for example `Ampere`
|
/// A unit of electrical current, for example `Ampere`
|
||||||
ElectricCurrent,
|
ElectricCurrent,
|
||||||
|
/// A unit of electric resistance, for example `Ohm`
|
||||||
|
Resistance,
|
||||||
/// A unit of pressure, for example `Bar`
|
/// A unit of pressure, for example `Bar`
|
||||||
Pressure,
|
Pressure,
|
||||||
/// A unit of frequency, for example `Hertz`
|
/// A unit of frequency, for example `Hertz`
|
||||||
@ -216,6 +218,10 @@ create_units!(
|
|||||||
Kiloampere: (ElectricCurrent, d128!(1000000)),
|
Kiloampere: (ElectricCurrent, d128!(1000000)),
|
||||||
Abampere: (ElectricCurrent, d128!(10000)),
|
Abampere: (ElectricCurrent, d128!(10000)),
|
||||||
|
|
||||||
|
Milliohm: (Resistance, d128!(1)),
|
||||||
|
Ohm: (Resistance, d128!(1000)),
|
||||||
|
Kiloohm: (Resistance, d128!(1000000)),
|
||||||
|
|
||||||
Pascal: (Pressure, d128!(1)),
|
Pascal: (Pressure, d128!(1)),
|
||||||
Kilopascal: (Pressure, d128!(1000)),
|
Kilopascal: (Pressure, d128!(1000)),
|
||||||
Atmosphere: (Pressure, d128!(101325)),
|
Atmosphere: (Pressure, d128!(101325)),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user