Removed regex dependency from kalk crate and made 'test-case' a dev-dependency

This commit is contained in:
PaddiM8 2021-01-03 00:07:30 +01:00
parent 80afcca049
commit dd63bace58
2 changed files with 8 additions and 7 deletions

View File

@ -15,13 +15,13 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
rug = { version = "1.11.0", features = ["float"], optional = true }
test-case = "1.0.0"
regex = "1"
lazy_static = "1.4.0"
wasm-bindgen = "0.2.69"
[dev-dependencies]
wasm-bindgen-test = "0.3.19"
test-case = "1.0.0"
regex = "1"
[features]
default = ["rug"]

View File

@ -149,7 +149,6 @@ impl<'a> Lexer<'a> {
fn next_identifier(&mut self) -> Token {
let start = self.index;
let mut end = start;
let letter_reg = regex::Regex::new(r"[A-z'_]").unwrap();
let mut value = String::new();
while is_valid_identifier(self.peek()) {
@ -167,7 +166,7 @@ impl<'a> Lexer<'a> {
// Only allow identifiers with a special character to have *one* character. No more.
// Break the loop if it isn't the first run and the current character is a special character.
if end - start > 0 && !letter_reg.is_match(&c.to_string()) {
if end - start > 0 && !(c.is_ascii_alphabetic() || c == '\'' || c == '_') {
break;
}
@ -209,9 +208,11 @@ fn build(kind: TokenKind, value: &str, span: (usize, usize)) -> Token {
fn is_valid_identifier(c: Option<&char>) -> bool {
if let Some(c) = c {
regex::Regex::new(r"[^\s\n\r0-9\+-/%\*\^!\(\)=\.,;|⌊⌋⌈⌉]")
.unwrap()
.is_match(&c.to_string())
match c {
'+' | '-' | '/' | '*' | '%' | '^' | '!' | '(' | ')' | '=' | '.' | ',' | ';' | '|'
| '⌊' | '⌋' | '⌈' | '⌉' | ']' => false,
_ => !c.is_digit(10),
}
} else {
false
}