mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-31 17:09:13 +01:00
Removed regex dependency from kalk crate and made 'test-case' a dev-dependency
This commit is contained in:
parent
f352d93ef5
commit
c0210d7c3f
@ -15,13 +15,13 @@ crate-type = ["cdylib", "rlib"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rug = { version = "1.11.0", features = ["float"], optional = true }
|
rug = { version = "1.11.0", features = ["float"], optional = true }
|
||||||
test-case = "1.0.0"
|
|
||||||
regex = "1"
|
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
wasm-bindgen = "0.2.69"
|
wasm-bindgen = "0.2.69"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
wasm-bindgen-test = "0.3.19"
|
wasm-bindgen-test = "0.3.19"
|
||||||
|
test-case = "1.0.0"
|
||||||
|
regex = "1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["rug"]
|
default = ["rug"]
|
||||||
|
@ -149,7 +149,6 @@ impl<'a> Lexer<'a> {
|
|||||||
fn next_identifier(&mut self) -> Token {
|
fn next_identifier(&mut self) -> Token {
|
||||||
let start = self.index;
|
let start = self.index;
|
||||||
let mut end = start;
|
let mut end = start;
|
||||||
let letter_reg = regex::Regex::new(r"[A-z'_]").unwrap();
|
|
||||||
let mut value = String::new();
|
let mut value = String::new();
|
||||||
|
|
||||||
while is_valid_identifier(self.peek()) {
|
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.
|
// 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.
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,9 +208,11 @@ fn build(kind: TokenKind, value: &str, span: (usize, usize)) -> Token {
|
|||||||
|
|
||||||
fn is_valid_identifier(c: Option<&char>) -> bool {
|
fn is_valid_identifier(c: Option<&char>) -> bool {
|
||||||
if let Some(c) = c {
|
if let Some(c) = c {
|
||||||
regex::Regex::new(r"[^\s\n\r0-9\+-/%\*\^!\(\)=\.,;|⌊⌋⌈⌉]")
|
match c {
|
||||||
.unwrap()
|
'+' | '-' | '/' | '*' | '%' | '^' | '!' | '(' | ')' | '=' | '.' | ',' | ';' | '|'
|
||||||
.is_match(&c.to_string())
|
| '⌊' | '⌋' | '⌈' | '⌉' | ']' => false,
|
||||||
|
_ => !c.is_digit(10),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user