diff --git a/Cargo.lock b/Cargo.lock index 54eaf62..872cc92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,7 +203,6 @@ name = "sybil" version = "0.1.0" dependencies = [ "gc", - "lazy_static", "regex", "structopt", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index a7deb8f..73eec29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,4 @@ edition = "2021" thiserror = "1.0" structopt = "0.3" regex = "1.5" -lazy_static = "1.4" gc = { version = "0.4", features = ["derive"] } \ No newline at end of file diff --git a/src/syn/lexer.rs b/src/syn/lexer.rs index 6d6cc56..7dc1414 100644 --- a/src/syn/lexer.rs +++ b/src/syn/lexer.rs @@ -1,10 +1,9 @@ use crate::syn::{error::*, span::*, token::*}; -use lazy_static::lazy_static; use regex::{Regex, RegexBuilder}; use std::rc::Rc; -lazy_static! { - static ref LEX_PAT: Regex = RegexBuilder::new( +thread_local! { + static LEX_PAT: Regex = RegexBuilder::new( r#"^( (?P[-+]?[0-9]+\.[0-9]+([eE][+\-][0-9]+)?) | (?P[-+]?[0-9]+) @@ -88,39 +87,41 @@ impl<'t> Lexer<'t> { return Ok(None); } - if let Some(cap) = LEX_PAT.captures(&self.text[self.start.byte..]) { - self.end = self.end.next_str(cap.get(0).unwrap().as_str()); - let sp_token = if let Some(_) = cap.name("assign") { - self.make_token(Token::Assign) - } else if let Some(_) = cap.name("meta") { - self.make_token(Token::Meta) - } else if let Some(_) = cap.name("word") { - self.make_token(Token::Word) - } else if let Some(_) = cap.name("float") { - self.make_token(Token::Float) - } else if let Some(_) = cap.name("int") { - self.make_token(Token::Int) - } else if let Some(_) = cap.name("str") { - self.make_token(Token::Str) - } else if let Some(_) = cap.name("lquote") { - self.make_token(Token::LQuote) - } else if let Some(_) = cap.name("rquote") { - self.make_token(Token::RQuote) - } else if let Some(_) = cap.name("apply") { - self.make_token(Token::Apply) + LEX_PAT.with(|lex| { + if let Some(cap) = lex.captures(&self.text[self.start.byte..]) { + self.end = self.end.next_str(cap.get(0).unwrap().as_str()); + let sp_token = if let Some(_) = cap.name("assign") { + self.make_token(Token::Assign) + } else if let Some(_) = cap.name("meta") { + self.make_token(Token::Meta) + } else if let Some(_) = cap.name("word") { + self.make_token(Token::Word) + } else if let Some(_) = cap.name("float") { + self.make_token(Token::Float) + } else if let Some(_) = cap.name("int") { + self.make_token(Token::Int) + } else if let Some(_) = cap.name("str") { + self.make_token(Token::Str) + } else if let Some(_) = cap.name("lquote") { + self.make_token(Token::LQuote) + } else if let Some(_) = cap.name("rquote") { + self.make_token(Token::RQuote) + } else if let Some(_) = cap.name("apply") { + self.make_token(Token::Apply) + } else { + panic!( + "matched lex pattern, but did not catch this capture: {:?}", + cap + ) + }; + Ok(Some(sp_token)) } else { - panic!( - "matched lex pattern, but did not catch this capture: {:?}", - cap - ) - }; - Ok(Some(sp_token)) - } else { - Err(SyntaxError::ExpectedGot { - expected: "word, literal, or quote".into(), - got: expected_got_char(self.curr().unwrap()), - }) - } + Err(SyntaxError::ExpectedGot { + expected: "word, literal, or quote".into(), + got: expected_got_char(self.curr().unwrap()), + }) + } + }) } }