From 33244c34d7b2149ff5cf0c792c8df191331001bd Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 20 Jan 2020 08:36:06 -0500 Subject: [PATCH] Rename AtRule enum to AtRuleKind --- src/common.rs | 6 +++--- src/lexer.rs | 4 ++-- src/main.rs | 25 +++++++++++++------------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/common.rs b/src/common.rs index f74b9e4..2d83332 100644 --- a/src/common.rs +++ b/src/common.rs @@ -139,7 +139,7 @@ impl TryFrom for Symbol { pub struct MediaQuery {} #[derive(Clone, Debug, Eq, PartialEq)] -pub enum AtRule { +pub enum AtRuleKind { // SASS specific @rules /// Loads mixins, functions, and variables from other Sass stylesheets, and combines CSS from multiple stylesheets together Use, @@ -206,7 +206,7 @@ pub enum AtRule { CounterStyle, } -impl TryFrom<&str> for AtRule { +impl TryFrom<&str> for AtRuleKind { type Error = &'static str; fn try_from(c: &str) -> Result { @@ -248,7 +248,7 @@ impl TryFrom<&str> for AtRule { } } -impl Display for AtRule { +impl Display for AtRuleKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Use => write!(f, "@use"), diff --git a/src/lexer.rs b/src/lexer.rs index 97be80b..b1271c5 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -2,7 +2,7 @@ use std::convert::TryFrom; use std::iter::Peekable; use std::str::Chars; -use crate::common::{AtRule, Keyword, Op, Pos, Symbol}; +use crate::common::{AtRuleKind, Keyword, Op, Pos, Symbol}; use crate::selector::{Attribute, AttributeKind}; use crate::units::Unit; use crate::{Token, TokenKind, Whitespace}; @@ -150,7 +150,7 @@ impl<'a> Lexer<'a> { string.push(tok); } - if let Ok(rule) = AtRule::try_from(string.as_ref()) { + if let Ok(rule) = AtRuleKind::try_from(string.as_ref()) { TokenKind::AtRule(rule) } else { panic!("expected ident after `@`") diff --git a/src/main.rs b/src/main.rs index ed8a448..b176047 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ use std::io::{self, stdout, BufWriter, Write}; use std::iter::{Iterator, Peekable}; use std::path::Path; -use crate::common::{AtRule, Keyword, Op, Pos, Printer, Scope, Symbol, Whitespace}; +use crate::common::{AtRuleKind, Keyword, Op, Pos, Printer, Scope, Symbol, Whitespace}; use crate::css::Css; use crate::error::SassError; use crate::format::PrettyPrinter; @@ -104,7 +104,7 @@ pub enum TokenKind { Ident(String), Symbol(Symbol), String(String), - AtRule(AtRule), + AtRule(AtRuleKind), Keyword(Keyword), Number(String), Unit(Unit), @@ -317,7 +317,7 @@ impl<'a> StyleSheetParser<'a> { }; rules.push(Stmt::MultilineComment(comment)); } - TokenKind::AtRule(AtRule::Import) => { + TokenKind::AtRule(AtRuleKind::Import) => { let Token { pos, .. } = self .lexer .next() @@ -360,7 +360,7 @@ impl<'a> StyleSheetParser<'a> { rules.extend(new_rules); self.global_scope.merge(new_scope); } - TokenKind::AtRule(AtRule::Mixin) => { + TokenKind::AtRule(AtRuleKind::Mixin) => { let (name, mixin) = Mixin::from_tokens(&mut self.lexer, &self.global_scope).unwrap(); self.global_scope.mixins.insert(name, mixin); @@ -430,40 +430,41 @@ impl<'a> StyleSheetParser<'a> { } fn eat_at_rule>( - rule: &AtRule, + rule: &AtRuleKind, pos: Pos, toks: &mut Peekable, scope: &Scope, ) -> Result { devour_whitespace(toks); match rule { - AtRule::Error => { + AtRuleKind::Error => { let message = toks .take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon)) .map(|x| x.kind.to_string()) .collect::(); Err(Printer::Error(pos, message)) } - AtRule::Warn => { + AtRuleKind::Warn => { let message = toks .take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon)) .map(|x| x.kind.to_string()) .collect::(); + devour_whitespace(toks); Err(Printer::Warn(pos, message)) } - AtRule::Debug => { + AtRuleKind::Debug => { let message = toks .by_ref() .take_while(|x| x.kind != TokenKind::Symbol(Symbol::SemiColon)) .map(|x| x.kind.to_string()) .collect::(); + devour_whitespace(toks); Err(Printer::Debug(pos, message)) } - AtRule::Mixin => { + AtRuleKind::Mixin => { let (name, mixin) = Mixin::from_tokens(toks, scope)?; Ok(Expr::MixinDecl(name, mixin)) } - // AtRule::Include => return Some(self.eat_include()), _ => todo!("encountered unimplemented at rule"), } } @@ -531,14 +532,14 @@ pub(crate) fn eat_expr>( values.push(tok); } } - TokenKind::AtRule(AtRule::Include) => { + TokenKind::AtRule(AtRuleKind::Include) => { return Ok(Some(Expr::Include(eat_include( toks, scope, super_selector, )?))); } - TokenKind::AtRule(AtRule::Mixin) => { + TokenKind::AtRule(AtRuleKind::Mixin) => { toks.next(); let (name, mixin) = Mixin::from_tokens(toks, scope).unwrap(); return Ok(Some(Expr::MixinDecl(name, mixin)));