clippy & rustfmt

This commit is contained in:
ConnorSkees 2020-01-05 12:52:50 -05:00
parent b2eb96963c
commit 3d0ae02b0a
4 changed files with 20 additions and 15 deletions

View File

@ -1,7 +1,6 @@
//! # Convert from SCSS AST to CSS //! # Convert from SCSS AST to CSS
use crate::{RuleSet, Selector, Stmt, Style, StyleSheet};
use std::io; use std::io;
use crate::{Selector, Style, StyleSheet, Stmt, RuleSet};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Block { pub struct Block {
@ -10,7 +9,7 @@ pub struct Block {
} }
impl Block { impl Block {
fn new(selector: Selector) -> Self { const fn new(selector: Selector) -> Self {
Block { Block {
selector, selector,
styles: Vec::new(), styles: Vec::new(),
@ -29,7 +28,7 @@ pub struct Css {
} }
impl Css { impl Css {
pub fn new() -> Self { pub const fn new() -> Self {
Css { Css {
blocks: Vec::new(), blocks: Vec::new(),
idx: 0, idx: 0,
@ -91,4 +90,4 @@ impl Css {
} }
Ok(()) Ok(())
} }
} }

View File

@ -99,7 +99,10 @@ impl<W: Write> PrettyPrinter<W> {
/// Pretty print a special form of SCSS that shows what the full selectors are for children /// Pretty print a special form of SCSS that shows what the full selectors are for children
/// Meant for debugging /// Meant for debugging
/// Empty rules are included /// Empty rules are included
pub(crate) fn pretty_print_preserve_super_selectors(&mut self, s: &StyleSheet) -> io::Result<()> { pub(crate) fn pretty_print_preserve_super_selectors(
&mut self,
s: &StyleSheet,
) -> io::Result<()> {
for rule in &s.rules { for rule in &s.rules {
self.pretty_print_stmt(rule)?; self.pretty_print_stmt(rule)?;
} }

View File

@ -127,10 +127,8 @@ impl<'a> Lexer<'a> {
} }
'*' => { '*' => {
while let Some(tok) = self.buf.next() { while let Some(tok) = self.buf.next() {
if tok == '*' { if tok == '*' && self.buf.next() == Some('/') {
if self.buf.next() == Some('/') { break;
break;
}
} }
} }
} }

View File

@ -240,7 +240,9 @@ impl<'a> StyleSheetParser<'a> {
| TokenKind::Symbol(Symbol::Hash) | TokenKind::Symbol(Symbol::Hash)
| TokenKind::Symbol(Symbol::Colon) | TokenKind::Symbol(Symbol::Colon)
| TokenKind::Symbol(Symbol::Mul) | TokenKind::Symbol(Symbol::Mul)
| TokenKind::Symbol(Symbol::Period) => rules.extend(self.eat_rules(Selector::None)), | TokenKind::Symbol(Symbol::Period) => {
rules.extend(self.eat_rules(&Selector::None))
}
TokenKind::Whitespace(_) | TokenKind::Symbol(_) => { TokenKind::Whitespace(_) | TokenKind::Symbol(_) => {
self.lexer.next(); self.lexer.next();
continue; continue;
@ -251,13 +253,13 @@ impl<'a> StyleSheetParser<'a> {
StyleSheet { rules } StyleSheet { rules }
} }
fn eat_rules(&mut self, super_selector: Selector) -> Vec<Stmt> { fn eat_rules(&mut self, super_selector: &Selector) -> Vec<Stmt> {
let mut stmts = Vec::new(); let mut stmts = Vec::new();
while let Ok(tok) = self.eat_expr() { while let Ok(tok) = self.eat_expr() {
match tok { match tok {
Expr::Style(s) => stmts.push(Stmt::Style(s)), Expr::Style(s) => stmts.push(Stmt::Style(s)),
Expr::Selector(s) => { Expr::Selector(s) => {
let rules = self.eat_rules(super_selector.clone().zip(s.clone())); let rules = self.eat_rules(&super_selector.clone().zip(s.clone()));
stmts.push(Stmt::RuleSet(RuleSet { stmts.push(Stmt::RuleSet(RuleSet {
super_selector: super_selector.clone(), super_selector: super_selector.clone(),
selector: s, selector: s,
@ -306,7 +308,10 @@ fn main() -> io::Result<()> {
let mut stdout = std::io::stdout(); let mut stdout = std::io::stdout();
let s = StyleSheet::new(&input); let s = StyleSheet::new(&input);
// dbg!(s); // dbg!(s);
s.pretty_print(&mut stdout)?; // s.pretty_print(&mut stdout)?;
// s.pretty_print_selectors(&mut stdout)?;
s.print_as_css(&mut stdout)?;
// dbg!(Css::from_stylesheet(s));
// println!("{}", s); // println!("{}", s);
// drop(input); // drop(input);
Ok(()) Ok(())