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.
This commit is contained in:
parent
d480e60628
commit
6a01eeb1d8
@ -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<W: Write> {
|
||||
buf: W,
|
||||
scope: usize,
|
||||
}
|
||||
|
||||
impl<W: Write> PrettyPrinter<W> {
|
||||
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::<String>();
|
||||
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(())
|
||||
}
|
||||
}
|
17
src/lib.rs
17
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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user