feat: remove lazy_static in favor of LazyLock

This switches to the built-in `std::sync::LazyLock`
This commit is contained in:
Yuri Astrakhan 2025-01-20 19:44:59 -05:00 committed by Amaan Qureshi
parent f23a52f410
commit 48059b72a8
20 changed files with 234 additions and 215 deletions

View file

@ -2,10 +2,9 @@ use std::{
cmp::Ordering,
fmt,
hash::{Hash, Hasher},
sync::LazyLock,
};
use lazy_static::lazy_static;
use crate::{
grammars::{
LexicalGrammar, Production, ProductionStep, ReservedWordSetId, SyntaxGrammar,
@ -14,22 +13,20 @@ use crate::{
rules::{Associativity, Precedence, Symbol, SymbolType, TokenSet},
};
lazy_static! {
static ref START_PRODUCTION: Production = Production {
dynamic_precedence: 0,
steps: vec![ProductionStep {
symbol: Symbol {
index: 0,
kind: SymbolType::NonTerminal,
},
precedence: Precedence::None,
associativity: None,
alias: None,
field_name: None,
reserved_word_set_id: NO_RESERVED_WORDS,
}],
};
}
static START_PRODUCTION: LazyLock<Production> = LazyLock::new(|| Production {
dynamic_precedence: 0,
steps: vec![ProductionStep {
symbol: Symbol {
index: 0,
kind: SymbolType::NonTerminal,
},
precedence: Precedence::None,
associativity: None,
alias: None,
field_name: None,
reserved_word_set_id: NO_RESERVED_WORDS,
}],
});
/// A [`ParseItem`] represents an in-progress match of a single production in a grammar.
#[derive(Clone, Copy, Debug)]

View file

@ -3,12 +3,12 @@ use std::{
io::Write,
path::{Path, PathBuf},
process::{Command, Stdio},
sync::LazyLock,
};
use anyhow::Result;
use build_tables::build_tables;
use grammars::InputGrammar;
use lazy_static::lazy_static;
pub use node_types::VariableInfoError;
use parse_grammar::parse_grammar;
pub use parse_grammar::ParseGrammarError;
@ -34,12 +34,12 @@ pub use build_tables::ParseTableBuilderError;
use serde::Serialize;
use thiserror::Error;
lazy_static! {
static ref JSON_COMMENT_REGEX: Regex = RegexBuilder::new("^\\s*//.*")
static JSON_COMMENT_REGEX: LazyLock<Regex> = LazyLock::new(|| {
RegexBuilder::new("^\\s*//.*")
.multi_line(true)
.build()
.unwrap();
}
.unwrap()
});
struct GeneratedParser {
c_code: String,