remove keywords
This commit is contained in:
parent
b15740976c
commit
3e5abf0587
@ -9,7 +9,7 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
|||||||
use crate::args::CallArgs;
|
use crate::args::CallArgs;
|
||||||
use crate::common::QuoteKind;
|
use crate::common::QuoteKind;
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::interner::{keywords::EMPTY_STRING, InternedString};
|
use crate::interner::InternedString;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::selector::Selector;
|
use crate::selector::Selector;
|
||||||
use crate::unit::Unit;
|
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 {
|
if start > end || start > str_len {
|
||||||
Ok(Value::Ident(EMPTY_STRING.with(|f| **f), quotes))
|
Ok(Value::Ident(InternedString::get_or_intern(""), quotes))
|
||||||
} else {
|
} else {
|
||||||
Ok(Value::Ident(
|
Ok(Value::Ident(
|
||||||
InternedString::get_or_intern(
|
InternedString::get_or_intern(
|
||||||
|
@ -5,32 +5,6 @@ use std::fmt::{self, Display};
|
|||||||
|
|
||||||
thread_local!(static STRINGS: RefCell<Rodeo<Spur>> = RefCell::new(Rodeo::default()));
|
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)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub(crate) struct InternedString(Spur);
|
pub(crate) struct InternedString(Spur);
|
||||||
|
|
||||||
@ -44,7 +18,7 @@ impl InternedString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(self) -> bool {
|
pub fn is_empty(self) -> bool {
|
||||||
EMPTY_STRING.with(|f| self == **f)
|
self.resolve_ref() == ""
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_ref<'a>(self) -> &'a str {
|
pub fn resolve_ref<'a>(self) -> &'a str {
|
||||||
|
10
src/lib.rs
10
src/lib.rs
@ -90,7 +90,7 @@ use peekmore::{PeekMore, PeekMoreIterator};
|
|||||||
|
|
||||||
use crate::atrule::{AtRule, AtRuleKind, Function, Mixin};
|
use crate::atrule::{AtRule, AtRuleKind, Function, Mixin};
|
||||||
pub use crate::error::{SassError, SassResult};
|
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::scope::{insert_global_var, Scope};
|
||||||
use crate::selector::Selector;
|
use crate::selector::Selector;
|
||||||
use crate::style::Style;
|
use crate::style::Style;
|
||||||
@ -200,7 +200,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
&mut values.into_iter().peekmore(),
|
&mut values.into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
EMPTY_STRING.with(|f| **f),
|
InternedString::get_or_intern(""),
|
||||||
tok.pos,
|
tok.pos,
|
||||||
)?;
|
)?;
|
||||||
return Ok(Some(Spanned {
|
return Ok(Some(Spanned {
|
||||||
@ -220,7 +220,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
return Ok(Some(Spanned {
|
return Ok(Some(Spanned {
|
||||||
node: Expr::Style(Box::new(Style {
|
node: Expr::Style(Box::new(Style {
|
||||||
property: EMPTY_STRING.with(|f| **f),
|
property: InternedString::get_or_intern(""),
|
||||||
value: Value::Null.span(span),
|
value: Value::Null.span(span),
|
||||||
})),
|
})),
|
||||||
span,
|
span,
|
||||||
@ -230,7 +230,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
&mut v,
|
&mut v,
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
EMPTY_STRING.with(|f| **f),
|
InternedString::get_or_intern(""),
|
||||||
span_before,
|
span_before,
|
||||||
)?;
|
)?;
|
||||||
let value = Style::parse_value(&mut v, scope, super_selector)?;
|
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,
|
&mut v,
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
EMPTY_STRING.with(|f| **f),
|
InternedString::get_or_intern(""),
|
||||||
tok.pos,
|
tok.pos,
|
||||||
)?;
|
)?;
|
||||||
let value = Style::parse_value(&mut v, scope, super_selector)?;
|
let value = Style::parse_value(&mut v, scope, super_selector)?;
|
||||||
|
@ -16,7 +16,7 @@ use crate::builtin::GLOBAL_FUNCTIONS;
|
|||||||
use crate::color::{Color, NAMED_COLORS};
|
use crate::color::{Color, NAMED_COLORS};
|
||||||
use crate::common::{Brackets, ListSeparator, Op, QuoteKind};
|
use crate::common::{Brackets, ListSeparator, Op, QuoteKind};
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::interner::{keywords, InternedString};
|
use crate::interner::InternedString;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::selector::Selector;
|
use crate::selector::Selector;
|
||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
@ -599,9 +599,9 @@ impl Value {
|
|||||||
) -> SassResult<Spanned<IntermediateValue>> {
|
) -> SassResult<Spanned<IntermediateValue>> {
|
||||||
let Spanned { node: mut s, span } = eat_ident(toks, scope, super_selector, span_before)?;
|
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().is_some()
|
||||||
&& toks.peek().unwrap().kind == ':'
|
&& toks.peek().unwrap().kind == ':'
|
||||||
{
|
{
|
||||||
@ -634,25 +634,19 @@ impl Value {
|
|||||||
.span(span))
|
.span(span))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
match lower {
|
match lower.resolve_ref() {
|
||||||
_ if keywords::CALC.with(|f| lower == **f)
|
"calc" | "element" | "expression" => {
|
||||||
|| keywords::ELEMENT.with(|f| lower == **f)
|
|
||||||
|| keywords::EXPRESSION.with(|f| lower == **f) =>
|
|
||||||
{
|
|
||||||
s = lower.resolve().to_string();
|
s = lower.resolve().to_string();
|
||||||
eat_calc_args(toks, scope, super_selector, &mut s)?;
|
eat_calc_args(toks, scope, super_selector, &mut s)?;
|
||||||
}
|
}
|
||||||
// "min" => {}
|
// "min" => {}
|
||||||
// "max" => {}
|
// "max" => {}
|
||||||
_ if keywords::URL.with(|f| lower == **f) => {
|
"url" => match try_eat_url(toks, scope, super_selector)? {
|
||||||
match try_eat_url(toks, scope, super_selector)? {
|
Some(val) => s = val,
|
||||||
Some(val) => s = val,
|
None => s.push_str(
|
||||||
None => s.push_str(
|
&eat_call_args(toks)?.to_css_string(scope, super_selector)?,
|
||||||
&eat_call_args(toks)?
|
),
|
||||||
.to_css_string(scope, super_selector)?,
|
},
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => s.push_str(
|
_ => s.push_str(
|
||||||
&eat_call_args(toks)?.to_css_string(scope, super_selector)?,
|
&eat_call_args(toks)?.to_css_string(scope, super_selector)?,
|
||||||
),
|
),
|
||||||
@ -680,14 +674,13 @@ impl Value {
|
|||||||
.span(span));
|
.span(span));
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg!(&lower);
|
Ok(match dbg!(lower.resolve_ref()) {
|
||||||
Ok(match lower {
|
"true" => IntermediateValue::Value(Value::True),
|
||||||
_ if keywords::TRUE.with(|f| lower == **f) => IntermediateValue::Value(Value::True),
|
"false" => IntermediateValue::Value(Value::False),
|
||||||
_ if keywords::FALSE.with(|f| lower == **f) => IntermediateValue::Value(Value::False),
|
"null" => IntermediateValue::Value(Value::Null),
|
||||||
_ if keywords::NULL.with(|f| lower == **f) => IntermediateValue::Value(Value::Null),
|
"not" => IntermediateValue::Op(Op::Not),
|
||||||
_ if keywords::NOT.with(|f| lower == **f) => IntermediateValue::Op(Op::Not),
|
"and" => IntermediateValue::Op(Op::And),
|
||||||
_ if keywords::AND.with(|f| lower == **f) => IntermediateValue::Op(Op::And),
|
"or" => IntermediateValue::Op(Op::Or),
|
||||||
_ if keywords::OR.with(|f| lower == **f) => IntermediateValue::Op(Op::Or),
|
|
||||||
_ => IntermediateValue::Value(Value::Ident(
|
_ => IntermediateValue::Value(Value::Ident(
|
||||||
InternedString::get_or_intern(s),
|
InternedString::get_or_intern(s),
|
||||||
QuoteKind::None,
|
QuoteKind::None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user