Calls to undefined functions should be treated as idents
This commit is contained in:
parent
e37179cfd7
commit
4c70b84ed7
@ -76,7 +76,7 @@ impl Display for Symbol {
|
|||||||
Self::At => write!(f, "@"),
|
Self::At => write!(f, "@"),
|
||||||
Self::Dollar => write!(f, "$"),
|
Self::Dollar => write!(f, "$"),
|
||||||
Self::OpenParen => write!(f, "("),
|
Self::OpenParen => write!(f, "("),
|
||||||
Self::CloseParen => write!(f, "),"),
|
Self::CloseParen => write!(f, ")"),
|
||||||
Self::OpenCurlyBrace => write!(f, "{{"),
|
Self::OpenCurlyBrace => write!(f, "{{"),
|
||||||
Self::CloseCurlyBrace => write!(f, "}}"),
|
Self::CloseCurlyBrace => write!(f, "}}"),
|
||||||
Self::OpenSquareBrace => write!(f, "["),
|
Self::OpenSquareBrace => write!(f, "["),
|
||||||
|
@ -81,7 +81,7 @@ impl Display for Number {
|
|||||||
let mut frac = self.val.fract();
|
let mut frac = self.val.fract();
|
||||||
if frac != BigRational::from_integer(BigInt::from(0)) {
|
if frac != BigRational::from_integer(BigInt::from(0)) {
|
||||||
f.write_char('.')?;
|
f.write_char('.')?;
|
||||||
for _ in 0..(PRECISION-1) {
|
for _ in 0..(PRECISION - 1) {
|
||||||
frac *= BigRational::from_integer(BigInt::from(10));
|
frac *= BigRational::from_integer(BigInt::from(10));
|
||||||
write!(f, "{}", frac.to_integer())?;
|
write!(f, "{}", frac.to_integer())?;
|
||||||
frac = frac.fract();
|
frac = frac.fract();
|
||||||
|
@ -22,6 +22,13 @@ impl Add for Value {
|
|||||||
},
|
},
|
||||||
Self::Dimension(num, unit) => match other {
|
Self::Dimension(num, unit) => match other {
|
||||||
Self::Dimension(num2, unit2) => Value::Dimension(num + num2, unit),
|
Self::Dimension(num2, unit2) => Value::Dimension(num + num2, unit),
|
||||||
|
Self::Ident(s, q) => {
|
||||||
|
let quotes = match q {
|
||||||
|
QuoteKind::Double | QuoteKind::Single => QuoteKind::Double,
|
||||||
|
QuoteKind::None => QuoteKind::None,
|
||||||
|
};
|
||||||
|
Value::Ident(format!("{}{}{}", num, unit, s), quotes)
|
||||||
|
}
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
},
|
},
|
||||||
// Self::List(..) => todo!(),
|
// Self::List(..) => todo!(),
|
||||||
|
@ -219,15 +219,47 @@ impl Value {
|
|||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
toks.next();
|
toks.next();
|
||||||
let args = eat_call_args(toks, scope);
|
|
||||||
let func = match scope.get_fn(&s) {
|
let func = match scope.get_fn(&s) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(_) => match GLOBAL_FUNCTIONS.get(&s) {
|
Err(_) => match GLOBAL_FUNCTIONS.get(&s) {
|
||||||
Some(f) => return f(&args, scope),
|
Some(f) => return f(&eat_call_args(toks, scope), scope),
|
||||||
None => todo!("called undefined function"),
|
None => {
|
||||||
|
s.push('(');
|
||||||
|
let mut unclosed_parens = 0;
|
||||||
|
while let Some(t) = toks.next() {
|
||||||
|
match &t.kind {
|
||||||
|
TokenKind::Symbol(Symbol::OpenParen) => {
|
||||||
|
unclosed_parens += 1;
|
||||||
|
}
|
||||||
|
TokenKind::Interpolation => s.push_str(
|
||||||
|
&parse_interpolation(toks, scope)
|
||||||
|
.iter()
|
||||||
|
.map(|x| x.kind.to_string())
|
||||||
|
.collect::<String>(),
|
||||||
|
),
|
||||||
|
TokenKind::Variable(v) => s.push_str(
|
||||||
|
&scope
|
||||||
|
.get_var(v)
|
||||||
|
.expect("expected variable to exist")
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
|
TokenKind::Symbol(Symbol::CloseParen) => {
|
||||||
|
if unclosed_parens <= 1 {
|
||||||
|
s.push(')');
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
unclosed_parens -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
s.push_str(&t.kind.to_string());
|
||||||
|
}
|
||||||
|
return Some(Value::Ident(s, QuoteKind::None));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Some(func.clone().args(&args).call())
|
Some(func.clone().args(&eat_call_args(toks, scope)).call())
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let Ok(c) = crate::color::ColorName::try_from(s.as_ref()) {
|
if let Ok(c) = crate::color::ColorName::try_from(s.as_ref()) {
|
||||||
|
@ -294,3 +294,12 @@ test!(
|
|||||||
"a {\n color: 'foo' - 1px;\n}\n",
|
"a {\n color: 'foo' - 1px;\n}\n",
|
||||||
"a {\n color: \"foo\"-1px;\n}\n"
|
"a {\n color: \"foo\"-1px;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
undefined_function_call_is_ident,
|
||||||
|
"a {\n color: foo();\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
undefined_function_call_is_ident_adds,
|
||||||
|
"a {\n color: 1 + foo();\n}\n",
|
||||||
|
"a {\n color: 1foo();\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user