Remove unwrap from FuncArgs

This commit is contained in:
ConnorSkees 2020-02-17 09:28:25 -05:00
parent dbe73fc2ac
commit 585011c621
4 changed files with 21 additions and 18 deletions

View File

@ -46,7 +46,7 @@ impl CallArgs {
pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
toks: &mut Peekable<I>,
scope: &Scope,
) -> FuncArgs {
) -> SassResult<FuncArgs> {
let mut args: Vec<FuncArg> = Vec::new();
devour_whitespace(toks);
@ -71,20 +71,20 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
toks.next();
args.push(FuncArg {
name,
default: Some(
Value::from_tokens(&mut default.into_iter().peekable(), scope)
.unwrap(),
),
default: Some(Value::from_tokens(
&mut default.into_iter().peekable(),
scope,
)?),
});
break;
}
TokenKind::Symbol(Symbol::CloseParen) => {
args.push(FuncArg {
name,
default: Some(
Value::from_tokens(&mut default.into_iter().peekable(), scope)
.unwrap(),
),
default: Some(Value::from_tokens(
&mut default.into_iter().peekable(),
scope,
)?),
});
break;
}
@ -102,9 +102,10 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
default: if default.is_empty() {
None
} else {
Some(
Value::from_tokens(&mut default.into_iter().peekable(), scope).unwrap(),
)
Some(Value::from_tokens(
&mut default.into_iter().peekable(),
scope,
)?)
},
});
break;
@ -126,7 +127,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
} else {
todo!("expected `{{` after args")
}
FuncArgs(args)
Ok(FuncArgs(args))
}
pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(

View File

@ -37,7 +37,7 @@ impl Function {
Some(Token {
kind: TokenKind::Symbol(Symbol::OpenParen),
..
}) => eat_func_args(toks, scope),
}) => eat_func_args(toks, scope)?,
_ => return Err("expected \"(\".".into()),
};
@ -78,7 +78,7 @@ impl Function {
Ok(self)
}
pub fn call(&self) -> Value {
pub fn call(&self) -> SassResult<Value> {
for rule in &self.body {
match rule {
AtRule::Return(toks) => {
@ -86,7 +86,6 @@ impl Function {
&mut toks.clone().into_iter().peekable(),
&self.scope,
)
.unwrap()
}
_ => todo!("unimplemented at rule in function body"),
}

View File

@ -38,7 +38,7 @@ impl Mixin {
Some(Token {
kind: TokenKind::Symbol(Symbol::OpenParen),
..
}) => eat_func_args(toks, scope),
}) => eat_func_args(toks, scope)?,
Some(Token {
kind: TokenKind::Symbol(Symbol::OpenCurlyBrace),
..

View File

@ -260,7 +260,10 @@ impl Value {
}
},
};
Ok(func.clone().args(&mut eat_call_args(toks, scope)?)?.call())
Ok(func
.clone()
.args(&mut eat_call_args(toks, scope)?)?
.call()?)
}
_ => {
if let Ok(c) = crate::color::ColorName::try_from(s.as_ref()) {