remove keywords

This commit is contained in:
ConnorSkees 2020-05-22 14:09:28 -04:00
parent b15740976c
commit 3e5abf0587
4 changed files with 26 additions and 59 deletions

View File

@ -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(

View File

@ -5,32 +5,6 @@ use std::fmt::{self, Display};
thread_local!(static STRINGS: RefCell<Rodeo<Spur>> = 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<InternedString> =
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 {

View File

@ -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<I: Iterator<Item = Token>>(
&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<I: Iterator<Item = Token>>(
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<I: Iterator<Item = Token>>(
&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<I: Iterator<Item = Token>>(
&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)?;

View File

@ -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<Spanned<IntermediateValue>> {
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,