Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ filetime = "0.2"
fnv = "1.0"
getopts = "0.2"
glob = "0.3"
lazy_static = "1.4"
indexmap = "2"
num-traits = "0.2"
packedvec = "1.2"
Expand Down
1 change: 0 additions & 1 deletion cfgrammar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ path = "src/lib/mod.rs"

[dependencies]
bincode = { workspace = true, optional = true, features = ["derive"] }
lazy_static.workspace = true
indexmap.workspace = true
num-traits.workspace = true
regex.workspace = true
Expand Down
18 changes: 9 additions & 9 deletions cfgrammar/src/lib/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use crate::{
YaccGrammarError, YaccGrammarErrorKind, YaccKind, YaccOriginalActionKind, parser::SpansKind,
},
};
use lazy_static::lazy_static;
use regex::{Regex, RegexBuilder};
use std::{error::Error, fmt};
use std::{error::Error, fmt, sync::LazyLock};

/// An error regarding the `%grmtools` header section.
///
Expand Down Expand Up @@ -247,15 +246,16 @@ impl<T> Value<T> {
}
}

lazy_static! {
static ref RE_LEADING_WS: Regex = Regex::new(r"^[\p{Pattern_White_Space}]*").unwrap();
static ref RE_NAME: Regex = RegexBuilder::new(r"^[A-Z][A-Z_]*")
static RE_LEADING_WS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[\p{Pattern_White_Space}]*").unwrap());
static RE_NAME: LazyLock<Regex> = LazyLock::new(|| {
RegexBuilder::new(r"^[A-Z][A-Z_]*")
.case_insensitive(true)
.build()
.unwrap();
static ref RE_DIGITS: Regex = Regex::new(r"^[0-9]+").unwrap();
static ref RE_STRING: Regex = Regex::new(r#"^\"(\\.|[^"\\])*\""#).unwrap();
}
.unwrap()
});
static RE_DIGITS: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^[0-9]+").unwrap());
static RE_STRING: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"^\"(\\.|[^"\\])*\""#).unwrap());

const MAGIC: &str = "%grmtools";

Expand Down
11 changes: 5 additions & 6 deletions cfgrammar/src/lib/yacc/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#[cfg(feature = "bincode")]
use bincode::{Decode, Encode};
use lazy_static::lazy_static;
use num_traits::PrimInt;
use regex::Regex;
#[cfg(feature = "serde")]
Expand All @@ -12,6 +11,7 @@ use std::{
error::Error,
fmt,
str::FromStr,
sync::LazyLock,
};

use crate::{
Expand Down Expand Up @@ -286,11 +286,10 @@ pub(crate) struct YaccParser<'a> {
global_actiontype: Option<(String, Span)>,
}

lazy_static! {
static ref RE_NAME: Regex = Regex::new(r"^[a-zA-Z_.][a-zA-Z0-9_.]*").unwrap();
static ref RE_TOKEN: Regex =
Regex::new("^(?:(\".+?\")|('.+?')|([a-zA-Z_][a-zA-Z_0-9]*))").unwrap();
}
static RE_NAME: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[a-zA-Z_.][a-zA-Z0-9_.]*").unwrap());
static RE_TOKEN: LazyLock<Regex> =
LazyLock::new(|| Regex::new("^(?:(\".+?\")|('.+?')|([a-zA-Z_][a-zA-Z_0-9]*))").unwrap());

fn add_duplicate_occurrence(
errs: &mut Vec<YaccGrammarError>,
Expand Down
1 change: 0 additions & 1 deletion lrlex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ cfgrammar = { path = "../cfgrammar", version = "0.13" }
lrpar = { path = "../lrpar", version = "0.13" }

getopts.workspace = true
lazy_static.workspace = true
regex.workspace = true
regex-syntax.workspace = true
num-traits.workspace = true
Expand Down
12 changes: 6 additions & 6 deletions lrlex/src/lib/ctbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
hash::Hash,
io::Write,
path::{Path, PathBuf},
sync::Mutex,
sync::{LazyLock, Mutex},
};

use bincode::Encode;
Expand All @@ -24,7 +24,6 @@ use cfgrammar::{
span::{Location, Span},
};
use glob::glob;
use lazy_static::lazy_static;
use lrpar::{
CTParserBuilder, LexerTypes,
diagnostics::{DiagnosticFormatter, SpannedDiagnosticFormatter},
Expand All @@ -41,10 +40,11 @@ const RUST_FILE_EXT: &str = "rs";
const ERROR: &str = "[Error]";
const WARNING: &str = "[Warning]";

lazy_static! {
static ref RE_TOKEN_ID: Regex = Regex::new(r"^[a-zA-Z_][a-zA-Z_0-9]*$").unwrap();
static ref GENERATED_PATHS: Mutex<HashSet<PathBuf>> = Mutex::new(HashSet::new());
}
static RE_TOKEN_ID: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[a-zA-Z_][a-zA-Z_0-9]*$").unwrap());

static GENERATED_PATHS: LazyLock<Mutex<HashSet<PathBuf>>> =
LazyLock::new(|| Mutex::new(HashSet::new()));

#[non_exhaustive]
pub enum LexerKind {
Expand Down
45 changes: 25 additions & 20 deletions lrlex/src/lib/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use cfgrammar::Span;
use lazy_static::lazy_static;
use lrpar::LexerTypes;
use num_traits::AsPrimitive;
use proc_macro2::TokenStream;
Expand All @@ -12,28 +11,34 @@ use crate::{
};
use std::borrow::{Borrow as _, Cow};
use std::ops::Not;
use std::sync::LazyLock;

type LexInternalBuildResult<T> = Result<T, LexBuildError>;

lazy_static! {
static ref RE_START_STATE_NAME: Regex = Regex::new(r"^[a-zA-Z][a-zA-Z0-9_.]*$").unwrap();
static ref RE_INCLUSIVE_START_STATE_DECLARATION: Regex =
Regex::new(r"^%[sS][a-zA-Z0-9]*$").unwrap();
static ref RE_EXCLUSIVE_START_STATE_DECLARATION: Regex =
Regex::new(r"^%[xX][a-zA-Z0-9]*$").unwrap();
// Documented in `Escape sequences` in lexcompatibility.m
static ref RE_LEX_ESC_LITERAL: Regex =
Regex::new(r"^(([xuU][[:xdigit:]])|[[:digit:]]|[afnrtv\\]|[pP]|[dDsSwW]|[Az])").unwrap();
// Vertical line separators.
static ref RE_LINE_SEP: Regex = Regex::new(r"[\p{Pattern_White_Space}&&[\p{Zl}\p{Zp}\n\r\v]]").unwrap();
static ref RE_LEADING_LINE_SEPS: Regex = Regex::new(r"^[\p{Pattern_White_Space}&&[\p{Zl}\p{Zp}\n\r\v]]*").unwrap();
// Horizontal space separators
static ref RE_SPACE_SEP: Regex = Regex::new(r"[\p{Pattern_White_Space}&&[\p{Zs}\t]]").unwrap();
static ref RE_LEADING_SPACE_SEPS: Regex = Regex::new(r"^[\p{Pattern_White_Space}&&[\p{Zs}\t]]*").unwrap();
static ref RE_LEADING_WS: Regex = Regex::new(r"^[\p{Pattern_White_Space}]*").unwrap();
static ref RE_WS: Regex = Regex::new(r"\p{Pattern_White_Space}").unwrap();
static ref RE_LEADING_DIGITS: Regex = Regex::new(r"^[0-9]+").unwrap();
}
static RE_START_STATE_NAME: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[a-zA-Z][a-zA-Z0-9_.]*$").unwrap());
static RE_INCLUSIVE_START_STATE_DECLARATION: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^%[sS][a-zA-Z0-9]*$").unwrap());
static RE_EXCLUSIVE_START_STATE_DECLARATION: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^%[xX][a-zA-Z0-9]*$").unwrap());
// Documented in `Escape sequences` in lexcompatibility.m
static RE_LEX_ESC_LITERAL: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"^(([xuU][[:xdigit:]])|[[:digit:]]|[afnrtv\\]|[pP]|[dDsSwW]|[Az])").unwrap()
});
// Vertical line separators.
static RE_LINE_SEP: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"[\p{Pattern_White_Space}&&[\p{Zl}\p{Zp}\n\r\v]]").unwrap());
static RE_LEADING_LINE_SEPS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[\p{Pattern_White_Space}&&[\p{Zl}\p{Zp}\n\r\v]]*").unwrap());
// Horizontal space separators
static RE_SPACE_SEP: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"[\p{Pattern_White_Space}&&[\p{Zs}\t]]").unwrap());
static RE_LEADING_SPACE_SEPS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[\p{Pattern_White_Space}&&[\p{Zs}\t]]*").unwrap());
static RE_LEADING_WS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[\p{Pattern_White_Space}]*").unwrap());
static RE_WS: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\p{Pattern_White_Space}").unwrap());

const INITIAL_START_STATE_NAME: &str = "INITIAL";

#[derive(Debug, Clone)]
Expand Down
1 change: 0 additions & 1 deletion lrpar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ bincode = { workspace = true, features = ["derive"] }
cactus.workspace = true
filetime.workspace = true
indexmap.workspace = true
lazy_static.workspace = true
num-traits.workspace = true
packedvec.workspace = true
proc-macro2.workspace = true
Expand Down
10 changes: 3 additions & 7 deletions lrpar/src/lib/ctbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
io::Write,
marker::PhantomData,
path::{Path, PathBuf},
sync::Mutex,
sync::{LazyLock, Mutex},
};

use crate::{
Expand All @@ -30,12 +30,10 @@ use cfgrammar::{
yacc::{YaccGrammar, YaccKind, YaccOriginalActionKind, ast::ASTWithValidityInfo},
};
use filetime::FileTime;
use lazy_static::lazy_static;
use lrtable::{Minimiser, StateGraph, StateTable, from_yacc, statetable::Conflicts};
use num_traits::{AsPrimitive, PrimInt, Unsigned};
use proc_macro2::{Literal, TokenStream};
use quote::{ToTokens, TokenStreamExt, format_ident, quote};
use regex::Regex;

const ACTION_PREFIX: &str = "__gt_";
const GLOBAL_PREFIX: &str = "__GT_";
Expand All @@ -48,10 +46,8 @@ const RUST_FILE_EXT: &str = "rs";
const WARNING: &str = "[Warning]";
const ERROR: &str = "[Error]";

lazy_static! {
static ref RE_DOL_NUM: Regex = Regex::new(r"\$([0-9]+)").unwrap();
static ref GENERATED_PATHS: Mutex<HashSet<PathBuf>> = Mutex::new(HashSet::new());
}
static GENERATED_PATHS: LazyLock<Mutex<HashSet<PathBuf>>> =
LazyLock::new(|| Mutex::new(HashSet::new()));

struct CTConflictsError<StorageT: Eq + Hash> {
conflicts_diagnostic: String,
Expand Down