Change return type and name of Mixin::from_tokens

This commit is contained in:
ConnorSkees 2020-01-20 09:39:06 -05:00
parent 6efb4141f6
commit f23dec81ec
2 changed files with 12 additions and 9 deletions

View File

@ -362,7 +362,7 @@ impl<'a> StyleSheetParser<'a> {
}
TokenKind::AtRule(AtRuleKind::Mixin) => {
let (name, mixin) =
Mixin::from_tokens(&mut self.lexer, &self.global_scope).unwrap();
Mixin::decl_from_tokens(&mut self.lexer, &self.global_scope).unwrap();
self.global_scope.mixins.insert(name, mixin);
}
TokenKind::AtRule(_) => {
@ -462,7 +462,10 @@ fn eat_at_rule<I: Iterator<Item = Token>>(
Err(Printer::Debug(pos, message))
}
AtRuleKind::Mixin => {
let (name, mixin) = Mixin::from_tokens(toks, scope)?;
let (name, mixin) = match Mixin::decl_from_tokens(toks, scope) {
Ok(m) => m,
Err(e) => return Err(Printer::Error(e.0, e.1)),
};
Ok(Expr::MixinDecl(name, mixin))
}
_ => todo!("encountered unimplemented at rule"),
@ -541,7 +544,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
}
TokenKind::AtRule(AtRuleKind::Mixin) => {
toks.next();
let (name, mixin) = Mixin::from_tokens(toks, scope).unwrap();
let (name, mixin) = Mixin::decl_from_tokens(toks, scope)?;
return Ok(Some(Expr::MixinDecl(name, mixin)));
}
TokenKind::AtRule(_) => {

View File

@ -1,7 +1,7 @@
use std::iter::Peekable;
use std::vec::IntoIter;
use crate::common::{Pos, Printer, Scope, Symbol};
use crate::common::{Pos, Scope, Symbol};
use crate::function::{eat_call_args, eat_func_args, CallArgs, FuncArgs};
use crate::selector::Selector;
use crate::utils::devour_whitespace;
@ -20,10 +20,10 @@ impl Mixin {
Mixin { scope, args, body }
}
pub fn from_tokens<I: Iterator<Item = Token>>(
pub fn decl_from_tokens<I: Iterator<Item = Token>>(
toks: &mut Peekable<I>,
scope: &Scope,
) -> Result<(String, Mixin), Printer> {
) -> Result<(String, Mixin), (Pos, String)> {
let Token { pos, .. } = toks
.next()
.expect("this must exist because we have already peeked");
@ -34,7 +34,7 @@ impl Mixin {
..
}) => s,
_ => {
return Err(Printer::Error(
return Err((
pos,
String::from("expected identifier after mixin declaration"),
))
@ -50,7 +50,7 @@ impl Mixin {
kind: TokenKind::Symbol(Symbol::OpenCurlyBrace),
..
}) => FuncArgs::new(),
_ => return Err(Printer::Error(pos, String::from("expected `(` or `{`"))),
_ => return Err((pos, String::from("expected `(` or `{`"))),
};
let mut nesting = 1;
@ -67,7 +67,7 @@ impl Mixin {
}
body.push(tok)
} else {
return Err(Printer::Error(pos, String::from("unexpected EOF")));
return Err((pos, String::from("unexpected EOF")));
}
}