This commit is contained in:
ConnorSkees 2020-01-20 12:17:07 -05:00
parent 1cd38f0317
commit 2efdf489ca
2 changed files with 7 additions and 3 deletions

View File

@ -44,6 +44,7 @@ impl From<FromUtf8Error> for SassError {
} }
impl From<SassError> for String { impl From<SassError> for String {
#[inline]
fn from(error: SassError) -> String { fn from(error: SassError) -> String {
error.message error.message
} }

View File

@ -117,6 +117,7 @@ pub enum TokenKind {
} }
impl Display for TokenKind { impl Display for TokenKind {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
TokenKind::Ident(s) | TokenKind::Number(s) => write!(f, "{}", s), TokenKind::Ident(s) | TokenKind::Number(s) => write!(f, "{}", s),
@ -194,6 +195,7 @@ enum Expr {
} }
impl StyleSheet { impl StyleSheet {
#[inline]
pub fn new(input: &str) -> SassResult<StyleSheet> { pub fn new(input: &str) -> SassResult<StyleSheet> {
Ok(StyleSheet( Ok(StyleSheet(
StyleSheetParser { StyleSheetParser {
@ -208,13 +210,12 @@ impl StyleSheet {
)) ))
} }
#[inline]
pub fn from_path<P: AsRef<Path> + Into<String>>(p: P) -> SassResult<StyleSheet> { pub fn from_path<P: AsRef<Path> + Into<String>>(p: P) -> SassResult<StyleSheet> {
let s = String::from_utf8(fs::read(p.as_ref())?)?;
dbg!(&s);
Ok(StyleSheet( Ok(StyleSheet(
StyleSheetParser { StyleSheetParser {
global_scope: Scope::new(), global_scope: Scope::new(),
lexer: Lexer::new(&s).peekable(), lexer: Lexer::new(&String::from_utf8(fs::read(p.as_ref())?)?).peekable(),
rules: Vec::new(), rules: Vec::new(),
scope: 0, scope: 0,
file: p.into(), file: p.into(),
@ -243,6 +244,7 @@ impl StyleSheet {
/// to pure CSS /// to pure CSS
/// ///
/// Used mainly in debugging, but can at times be useful /// Used mainly in debugging, but can at times be useful
#[inline]
pub fn pretty_print<W: Write>(&self, buf: W) -> SassResult<()> { pub fn pretty_print<W: Write>(&self, buf: W) -> SassResult<()> {
PrettyPrinter::new(buf).pretty_print(self) PrettyPrinter::new(buf).pretty_print(self)
} }
@ -253,6 +255,7 @@ impl StyleSheet {
} }
/// Write the internal representation as CSS to `buf` /// Write the internal representation as CSS to `buf`
#[inline]
pub fn print_as_css<W: Write>(self, buf: &mut W) -> SassResult<()> { pub fn print_as_css<W: Write>(self, buf: &mut W) -> SassResult<()> {
Css::from_stylesheet(self).pretty_print(buf) Css::from_stylesheet(self).pretty_print(buf)
} }