From f23dec81ecb46e75bbcb9ecbf09bb0aecae88965 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 20 Jan 2020 09:39:06 -0500 Subject: [PATCH] Change return type and name of Mixin::from_tokens --- src/main.rs | 9 ++++++--- src/mixin.rs | 12 ++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index b176047..b7e0195 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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>( 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>( } 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(_) => { diff --git a/src/mixin.rs b/src/mixin.rs index 45de8b8..55dc1d0 100644 --- a/src/mixin.rs +++ b/src/mixin.rs @@ -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>( + pub fn decl_from_tokens>( toks: &mut Peekable, 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"))); } }