clippy & rustfmt
This commit is contained in:
parent
b2eb96963c
commit
3d0ae02b0a
11
src/css.rs
11
src/css.rs
@ -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 crate::{Selector, Style, StyleSheet, Stmt, RuleSet};
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Block {
|
||||
@ -10,7 +9,7 @@ pub struct Block {
|
||||
}
|
||||
|
||||
impl Block {
|
||||
fn new(selector: Selector) -> Self {
|
||||
const fn new(selector: Selector) -> Self {
|
||||
Block {
|
||||
selector,
|
||||
styles: Vec::new(),
|
||||
@ -29,7 +28,7 @@ pub struct Css {
|
||||
}
|
||||
|
||||
impl Css {
|
||||
pub fn new() -> Self {
|
||||
pub const fn new() -> Self {
|
||||
Css {
|
||||
blocks: Vec::new(),
|
||||
idx: 0,
|
||||
@ -91,4 +90,4 @@ impl Css {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
/// Meant for debugging
|
||||
/// 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 {
|
||||
self.pretty_print_stmt(rule)?;
|
||||
}
|
||||
|
@ -127,10 +127,8 @@ impl<'a> Lexer<'a> {
|
||||
}
|
||||
'*' => {
|
||||
while let Some(tok) = self.buf.next() {
|
||||
if tok == '*' {
|
||||
if self.buf.next() == Some('/') {
|
||||
break;
|
||||
}
|
||||
if tok == '*' && self.buf.next() == Some('/') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
src/main.rs
13
src/main.rs
@ -240,7 +240,9 @@ impl<'a> StyleSheetParser<'a> {
|
||||
| TokenKind::Symbol(Symbol::Hash)
|
||||
| TokenKind::Symbol(Symbol::Colon)
|
||||
| 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(_) => {
|
||||
self.lexer.next();
|
||||
continue;
|
||||
@ -251,13 +253,13 @@ impl<'a> StyleSheetParser<'a> {
|
||||
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();
|
||||
while let Ok(tok) = self.eat_expr() {
|
||||
match tok {
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(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 {
|
||||
super_selector: super_selector.clone(),
|
||||
selector: s,
|
||||
@ -306,7 +308,10 @@ fn main() -> io::Result<()> {
|
||||
let mut stdout = std::io::stdout();
|
||||
let s = StyleSheet::new(&input);
|
||||
// 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);
|
||||
// drop(input);
|
||||
Ok(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user