Lexing of keywords now uses is_ascii_alphabetic instead of is_alphabetic

This commit is contained in:
Kasper 2020-01-13 15:50:54 +01:00
parent 73861a1848
commit 388825f9ac
3 changed files with 7 additions and 3 deletions

View File

@ -41,7 +41,7 @@ pub fn lex(input: &str) -> Result<TokenVector, String> {
'\'' => 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() => {},
value if value.is_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;
@ -52,7 +52,7 @@ pub fn lex(input: &str) -> Result<TokenVector, String> {
return Err(format!("Invalid string starting with: {}", string)); return Err(format!("Invalid string starting with: {}", string));
} }
if current_char.is_alphabetic() { if current_char.is_ascii_alphabetic() {
byte_index += current_char.len_utf8(); byte_index += current_char.len_utf8();
chars.next(); chars.next();
end_index += 1; end_index += 1;

View File

@ -88,12 +88,13 @@ mod evaluator;
mod lookup; mod lookup;
fn main() { fn main() {
let lex_start = Instant::now();
use std::env; use std::env;
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let s = if args.len() >= 2 { &args[1] } else { "0.1" }; let s = if args.len() >= 2 { &args[1] } else { "0.1" };
let lex_start = Instant::now();
match lexer::lex(s) { match lexer::lex(s) {
Ok(tokens) => { Ok(tokens) => {
let lex_time = Instant::now().duration_since(lex_start).as_nanos() as f32; let lex_time = Instant::now().duration_since(lex_start).as_nanos() as f32;

View File

@ -71,6 +71,7 @@ create_units!(
Foot: (Length, d128!(304.8)), Foot: (Length, d128!(304.8)),
Yard: (Length, d128!(914.4)), Yard: (Length, d128!(914.4)),
Mile: (Length, d128!(1609344)), Mile: (Length, d128!(1609344)),
// 1-dimensional only:
NauticalMile: (Length, d128!(1852000)), NauticalMile: (Length, d128!(1852000)),
LightYear: (Length, d128!(9460730472580800000)), LightYear: (Length, d128!(9460730472580800000)),
LightSecond: (Length, d128!(299792458000)), LightSecond: (Length, d128!(299792458000)),
@ -84,6 +85,7 @@ create_units!(
SquareFoot: (Area, d128!(92903.04)), SquareFoot: (Area, d128!(92903.04)),
SquareYard: (Area, d128!(836127.36)), SquareYard: (Area, d128!(836127.36)),
SquareMile: (Area, d128!(2589988110336.00)), SquareMile: (Area, d128!(2589988110336.00)),
// 2-dimensional only
Are: (Area, d128!(100000000)), Are: (Area, d128!(100000000)),
Decare: (Area, d128!(1000000000)), Decare: (Area, d128!(1000000000)),
Hectare: (Area, d128!(10000000000)), Hectare: (Area, d128!(10000000000)),
@ -98,6 +100,7 @@ create_units!(
CubicFoot: (Volume, d128!(28316846.592)), CubicFoot: (Volume, d128!(28316846.592)),
CubicYard: (Volume, d128!(764554857.984)), CubicYard: (Volume, d128!(764554857.984)),
CubicMile: (Volume, d128!(4168181825440579584)), CubicMile: (Volume, d128!(4168181825440579584)),
// 3-dimensional only
Milliliter: (Volume, d128!(1000)), Milliliter: (Volume, d128!(1000)),
Centiliter: (Volume, d128!(10000)), Centiliter: (Volume, d128!(10000)),
Deciliter: (Volume, d128!(100000)), Deciliter: (Volume, d128!(100000)),