From 3e5abf058753df0940889980f0c41f29f9f34396 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Fri, 22 May 2020 14:09:28 -0400 Subject: [PATCH] remove keywords --- src/builtin/string.rs | 4 ++-- src/interner.rs | 28 +--------------------------- src/lib.rs | 10 +++++----- src/value/parse.rs | 43 ++++++++++++++++++------------------------- 4 files changed, 26 insertions(+), 59 deletions(-) diff --git a/src/builtin/string.rs b/src/builtin/string.rs index 24d0dce..2add066 100644 --- a/src/builtin/string.rs +++ b/src/builtin/string.rs @@ -9,7 +9,7 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng}; use crate::args::CallArgs; use crate::common::QuoteKind; use crate::error::SassResult; -use crate::interner::{keywords::EMPTY_STRING, InternedString}; +use crate::interner::InternedString; use crate::scope::Scope; use crate::selector::Selector; use crate::unit::Unit; @@ -198,7 +198,7 @@ fn str_slice(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa } if start > end || start > str_len { - Ok(Value::Ident(EMPTY_STRING.with(|f| **f), quotes)) + Ok(Value::Ident(InternedString::get_or_intern(""), quotes)) } else { Ok(Value::Ident( InternedString::get_or_intern( diff --git a/src/interner.rs b/src/interner.rs index 32de6e7..e197f3d 100644 --- a/src/interner.rs +++ b/src/interner.rs @@ -5,32 +5,6 @@ use std::fmt::{self, Display}; thread_local!(static STRINGS: RefCell> = RefCell::new(Rodeo::default())); -use keywords::EMPTY_STRING; - -pub(crate) mod keywords { - use super::InternedString; - use once_cell::sync::Lazy; - macro_rules! keyword { - ($ident:ident, $val:literal) => { - thread_local!(pub(crate) static $ident: Lazy = - Lazy::new(|| InternedString::get_or_intern($val))); - }; - } - - keyword!(EMPTY_STRING, ""); - keyword!(TRUE, "true"); - keyword!(FALSE, "false"); - keyword!(AND, "and"); - keyword!(OR, "or"); - keyword!(NOT, "not"); - keyword!(NULL, "null"); - keyword!(CALC, "calc"); - keyword!(URL, "url"); - keyword!(PROGID, "progid"); - keyword!(ELEMENT, "element"); - keyword!(EXPRESSION, "expression"); -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) struct InternedString(Spur); @@ -44,7 +18,7 @@ impl InternedString { } pub fn is_empty(self) -> bool { - EMPTY_STRING.with(|f| self == **f) + self.resolve_ref() == "" } pub fn resolve_ref<'a>(self) -> &'a str { diff --git a/src/lib.rs b/src/lib.rs index f4bb9af..da3034b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,7 +90,7 @@ use peekmore::{PeekMore, PeekMoreIterator}; use crate::atrule::{AtRule, AtRuleKind, Function, Mixin}; pub use crate::error::{SassError, SassResult}; -use crate::interner::keywords::EMPTY_STRING; +use crate::interner::InternedString; use crate::scope::{insert_global_var, Scope}; use crate::selector::Selector; use crate::style::Style; @@ -200,7 +200,7 @@ pub(crate) fn eat_expr>( &mut values.into_iter().peekmore(), scope, super_selector, - EMPTY_STRING.with(|f| **f), + InternedString::get_or_intern(""), tok.pos, )?; return Ok(Some(Spanned { @@ -220,7 +220,7 @@ pub(crate) fn eat_expr>( devour_whitespace(toks); return Ok(Some(Spanned { node: Expr::Style(Box::new(Style { - property: EMPTY_STRING.with(|f| **f), + property: InternedString::get_or_intern(""), value: Value::Null.span(span), })), span, @@ -230,7 +230,7 @@ pub(crate) fn eat_expr>( &mut v, scope, super_selector, - EMPTY_STRING.with(|f| **f), + InternedString::get_or_intern(""), span_before, )?; let value = Style::parse_value(&mut v, scope, super_selector)?; @@ -257,7 +257,7 @@ pub(crate) fn eat_expr>( &mut v, scope, super_selector, - EMPTY_STRING.with(|f| **f), + InternedString::get_or_intern(""), tok.pos, )?; let value = Style::parse_value(&mut v, scope, super_selector)?; diff --git a/src/value/parse.rs b/src/value/parse.rs index c7f30f1..608787f 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -16,7 +16,7 @@ use crate::builtin::GLOBAL_FUNCTIONS; use crate::color::{Color, NAMED_COLORS}; use crate::common::{Brackets, ListSeparator, Op, QuoteKind}; use crate::error::SassResult; -use crate::interner::{keywords, InternedString}; +use crate::interner::InternedString; use crate::scope::Scope; use crate::selector::Selector; use crate::unit::Unit; @@ -599,9 +599,9 @@ impl Value { ) -> SassResult> { let Spanned { node: mut s, span } = eat_ident(toks, scope, super_selector, span_before)?; - let lower = InternedString::get_or_intern(s.to_ascii_lowercase()); + let lower = dbg!(InternedString::get_or_intern(s.to_ascii_lowercase())); - if keywords::PROGID.with(|f| lower == **f) + if lower.resolve_ref() == "progid" && toks.peek().is_some() && toks.peek().unwrap().kind == ':' { @@ -634,25 +634,19 @@ impl Value { .span(span)) } None => { - match lower { - _ if keywords::CALC.with(|f| lower == **f) - || keywords::ELEMENT.with(|f| lower == **f) - || keywords::EXPRESSION.with(|f| lower == **f) => - { + match lower.resolve_ref() { + "calc" | "element" | "expression" => { s = lower.resolve().to_string(); eat_calc_args(toks, scope, super_selector, &mut s)?; } // "min" => {} // "max" => {} - _ if keywords::URL.with(|f| lower == **f) => { - match try_eat_url(toks, scope, super_selector)? { - Some(val) => s = val, - None => s.push_str( - &eat_call_args(toks)? - .to_css_string(scope, super_selector)?, - ), - } - } + "url" => match try_eat_url(toks, scope, super_selector)? { + Some(val) => s = val, + None => s.push_str( + &eat_call_args(toks)?.to_css_string(scope, super_selector)?, + ), + }, _ => s.push_str( &eat_call_args(toks)?.to_css_string(scope, super_selector)?, ), @@ -680,14 +674,13 @@ impl Value { .span(span)); } - dbg!(&lower); - Ok(match lower { - _ if keywords::TRUE.with(|f| lower == **f) => IntermediateValue::Value(Value::True), - _ if keywords::FALSE.with(|f| lower == **f) => IntermediateValue::Value(Value::False), - _ if keywords::NULL.with(|f| lower == **f) => IntermediateValue::Value(Value::Null), - _ if keywords::NOT.with(|f| lower == **f) => IntermediateValue::Op(Op::Not), - _ if keywords::AND.with(|f| lower == **f) => IntermediateValue::Op(Op::And), - _ if keywords::OR.with(|f| lower == **f) => IntermediateValue::Op(Op::Or), + Ok(match dbg!(lower.resolve_ref()) { + "true" => IntermediateValue::Value(Value::True), + "false" => IntermediateValue::Value(Value::False), + "null" => IntermediateValue::Value(Value::Null), + "not" => IntermediateValue::Op(Op::Not), + "and" => IntermediateValue::Op(Op::And), + "or" => IntermediateValue::Op(Op::Or), _ => IntermediateValue::Value(Value::Ident( InternedString::get_or_intern(s), QuoteKind::None,