-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(parser): made PATTERN_SET regex lazy_static
- Loading branch information
1 parent
ae85619
commit a3f9b1e
Showing
4 changed files
with
27 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
use regex::Regex; | ||
use crate::parser::structs::IntermediateToken; | ||
use regex::{Regex, RegexSet}; | ||
|
||
lazy_static::lazy_static! { | ||
pub static ref SHOULD_END_LITERAL: Regex = Regex::new(r"[^-_a-zA-Z0-9]").unwrap(); | ||
pub static ref LITERAL_IDENTIFIER: Regex = Regex::new(r"[-_a-zA-Z0-9]+").unwrap(); | ||
static ref LITERAL_IDENTIFIER: Regex = Regex::new(r"[-_a-zA-Z0-9]+").unwrap(); | ||
|
||
pub static ref PATTERN_SET: RegexSet = RegexSet::new(IntermediateToken::ALL_TOKEN_PATTERNS_FROM_LONGEST | ||
.iter() | ||
.map(|pattern| { | ||
format!( | ||
r"(?i)^{}{}", | ||
// escape the pattern so that e.g. "^" is not treated as regex, but as a literal character for the And operation | ||
regex::escape(pattern), | ||
if LITERAL_IDENTIFIER.is_match(pattern) { | ||
"([^-_a-zA-Z0-9]|$)" | ||
} else { | ||
"" | ||
} | ||
) | ||
})) | ||
.unwrap(); | ||
} |