From a74d22cce9b9adb1e5cd2a0bd2876a494956235c Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Wed, 8 Jan 2020 20:58:02 -0500 Subject: [PATCH] Document some internal enums and structs --- src/main.rs | 28 +++++++++++++++++++++++++++- src/style.rs | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index dbf5851..36c3aa6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,6 +94,8 @@ impl Display for TokenKind { } } + +/// Represents a parsed SASS stylesheet with nesting #[derive(Debug, Clone, Eq, PartialEq)] pub struct StyleSheet { rules: Vec, @@ -101,11 +103,22 @@ pub struct StyleSheet { #[derive(Clone, Debug, Eq, PartialEq)] pub enum Stmt { + /// A style: `color: red` Style(Style), + /// An entire `[RuleSet](crate::RuleSet)` RuleSet(RuleSet), + /// A multiline comment: `/* foo bar */` MultilineComment(String), } +/// Represents a single rule set. Rule sets can contain other rule sets +/// +/// a { +/// color: blue; +/// b { +/// color: red; +/// } +/// } #[derive(Clone, Debug, Eq, PartialEq)] pub struct RuleSet { selector: Selector, @@ -114,11 +127,17 @@ pub struct RuleSet { super_selector: Selector, } +/// An intermediate representation of what are essentially single lines +/// todo! rename this #[derive(Clone, Debug, Eq, PartialEq)] enum Expr { + /// A style: `color: red` Style(Style), + /// A full selector `a > h1` Selector(Selector), + /// A variable declaration `$var: 1px` VariableDecl(String, Vec), + /// A multiline comment: `/* foobar */` MultilineComment(String), } @@ -145,14 +164,21 @@ impl StyleSheet { .parse_toplevel() } + /// Print the internal representation of a parsed stylesheet + /// + /// Very closely resembles the origin SASS, but contains only things translatable + /// to pure CSS + /// + /// Used mainly in debugging, but can at times be useful pub fn pretty_print(&self, buf: W) -> io::Result<()> { PrettyPrinter::new(buf).pretty_print(self) } - pub fn pretty_print_selectors(&self, buf: W) -> io::Result<()> { + fn pretty_print_selectors(&self, buf: W) -> io::Result<()> { PrettyPrinter::new(buf).pretty_print_preserve_super_selectors(self) } + /// Write the internal representation as CSS to `buf` pub fn print_as_css(self, buf: &mut W) -> io::Result<()> { Css::from_stylesheet(self).pretty_print(buf) } diff --git a/src/style.rs b/src/style.rs index d847fbc..1e8f798 100644 --- a/src/style.rs +++ b/src/style.rs @@ -5,6 +5,7 @@ use std::fmt::{self, Display}; use std::iter::Peekable; use std::slice::Iter; +/// A style: `color: red` #[derive(Clone, Debug, Eq, PartialEq)] pub struct Style { property: String,