From 6a01eeb1d87c3147a10cac72fb30aed555f57e46 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 21 Apr 2020 18:01:35 -0400 Subject: [PATCH] Remove format module This was code leftover from before there were proper unit tests. It remained for some time as a debugging tool, but as more features have been added, it has become a maintenance burden and no longer provides a tangible benefit. --- src/format.rs | 55 --------------------------------------------------- src/lib.rs | 17 ---------------- 2 files changed, 72 deletions(-) delete mode 100644 src/format.rs diff --git a/src/format.rs b/src/format.rs deleted file mode 100644 index 89a60e1..0000000 --- a/src/format.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::fmt::Write; - -use crate::atrule::AtRule; -use crate::error::SassResult; -use crate::{RuleSet, Stmt, StyleSheet}; - -pub(crate) struct PrettyPrinter { - buf: W, - scope: usize, -} - -impl PrettyPrinter { - pub(crate) fn new(buf: W) -> Self { - PrettyPrinter { buf, scope: 0 } - } - - /// Pretty print `crate::Stmt` - /// Throws away super selectors and variables - fn pretty_print_stmt(&mut self, stmt: &Stmt) -> SassResult<()> { - let padding = vec![' '; self.scope * 2].iter().collect::(); - match stmt { - Stmt::MultilineComment(s) => writeln!(self.buf, "{}/*{}*/", padding, s)?, - Stmt::RuleSet(RuleSet { - selector, rules, .. - }) => { - writeln!(self.buf, "{}{} {{", padding, selector)?; - self.scope += 1; - for rule in rules { - self.pretty_print_stmt(rule)?; - } - writeln!(self.buf, "{}}}", padding)?; - self.scope -= 1; - } - Stmt::Style(s) => { - writeln!(self.buf, "{}{}", padding, s.to_string()?)?; - } - Stmt::AtRule(r) => match r { - AtRule::Unknown(..) => todo!("Display @rules properly"), - _ => todo!(), - }, - } - Ok(()) - } - - /// Pretty print SCSS - /// - /// The result should be an exact copy of the SCSS input - /// Empty rules are included - pub fn pretty_print(&mut self, s: &StyleSheet) -> SassResult<()> { - for rule in &s.0 { - self.pretty_print_stmt(rule)?; - } - Ok(()) - } -} diff --git a/src/lib.rs b/src/lib.rs index 889839b..6d06e7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,6 @@ grass input.scss clippy::or_fun_call, )] #![cfg_attr(feature = "nightly", feature(track_caller))] -use std::fmt::{self, Display}; use std::fs; use std::iter::Iterator; use std::path::Path; @@ -90,7 +89,6 @@ use peekmore::{PeekMore, PeekMoreIterator}; use crate::atrule::{eat_include, AtRule, AtRuleKind, Function, Mixin}; pub use crate::error::{SassError, SassResult}; -use crate::format::PrettyPrinter; use crate::imports::import; use crate::lexer::Lexer; use crate::output::Css; @@ -110,7 +108,6 @@ mod builtin; mod color; mod common; mod error; -mod format; mod imports; mod lexer; mod output; @@ -182,20 +179,6 @@ enum Expr { AtRule(AtRule), } -/// Print the internal representation of a parsed stylesheet -/// -/// Very closely resembles the original SASS, but contains only things translatable -/// to pure CSS: functions, variables, values, and mixins have all been evaluated. -/// -/// Use `StyleSheet::print_as_css` to properly convert to CSS. -impl Display for StyleSheet { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - PrettyPrinter::new(f).pretty_print(self).unwrap(); - Ok(()) - } -} - fn raw_to_parse_error(map: &CodeMap, err: SassError) -> SassError { let (message, span) = err.raw(); SassError::from_loc(message, map.look_up_span(span))