use peekmore rather than std::iter::Peekable
This commit is contained in:
parent
e07ceda8c7
commit
4cdcf4f0d4
@ -1,8 +1,9 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::iter::Peekable;
|
|
||||||
|
|
||||||
use codemap::{Span, Spanned};
|
use codemap::{Span, Spanned};
|
||||||
|
|
||||||
|
use peekmore::PeekMoreIterator;
|
||||||
|
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::selector::Selector;
|
use crate::selector::Selector;
|
||||||
@ -172,7 +173,7 @@ impl CallArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<FuncArgs> {
|
) -> SassResult<FuncArgs> {
|
||||||
@ -275,7 +276,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<CallArgs> {
|
) -> SassResult<CallArgs> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::iter::Peekable;
|
|
||||||
|
|
||||||
use codemap::{Span, Spanned};
|
use codemap::{Span, Spanned};
|
||||||
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use num_traits::cast::ToPrimitive;
|
use num_traits::cast::ToPrimitive;
|
||||||
|
|
||||||
use super::parse::eat_stmts;
|
use super::parse::eat_stmts;
|
||||||
@ -18,7 +18,7 @@ use crate::value::{Number, Value};
|
|||||||
use crate::Token;
|
use crate::Token;
|
||||||
|
|
||||||
pub(crate) fn parse_for<I: Iterator<Item = Token>>(
|
pub(crate) fn parse_for<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
span: Span,
|
span: Span,
|
||||||
@ -155,7 +155,7 @@ pub(crate) fn parse_for<I: Iterator<Item = Token>>(
|
|||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
stmts.extend(eat_stmts(
|
stmts.extend(eat_stmts(
|
||||||
&mut body.clone().into_iter().peekable(),
|
&mut body.clone().into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?);
|
)?);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use std::iter::Peekable;
|
|
||||||
|
|
||||||
use super::eat_stmts;
|
use super::eat_stmts;
|
||||||
|
|
||||||
use codemap::{Span, Spanned};
|
use codemap::{Span, Spanned};
|
||||||
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use crate::args::{eat_func_args, CallArgs, FuncArgs};
|
use crate::args::{eat_func_args, CallArgs, FuncArgs};
|
||||||
use crate::atrule::AtRule;
|
use crate::atrule::AtRule;
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
@ -40,7 +40,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn decl_from_tokens<I: Iterator<Item = Token>>(
|
pub fn decl_from_tokens<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: Scope,
|
scope: Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<(String, Function)> {
|
) -> SassResult<(String, Function)> {
|
||||||
@ -84,7 +84,7 @@ impl Function {
|
|||||||
Some(v) => v?,
|
Some(v) => v?,
|
||||||
None => match &arg.default {
|
None => match &arg.default {
|
||||||
Some(v) => Value::from_tokens(
|
Some(v) => Value::from_tokens(
|
||||||
&mut v.iter().cloned().peekable(),
|
&mut v.iter().cloned().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?,
|
)?,
|
||||||
@ -110,7 +110,7 @@ impl Function {
|
|||||||
match stmt.node {
|
match stmt.node {
|
||||||
Stmt::AtRule(AtRule::Return(toks)) => {
|
Stmt::AtRule(AtRule::Return(toks)) => {
|
||||||
return Ok(Value::from_tokens(
|
return Ok(Value::from_tokens(
|
||||||
&mut toks.into_iter().peekable(),
|
&mut toks.into_iter().peekmore(),
|
||||||
&self.scope,
|
&self.scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?
|
)?
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::iter::Peekable;
|
|
||||||
|
|
||||||
use codemap::Spanned;
|
use codemap::Spanned;
|
||||||
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use super::{eat_stmts, AtRule};
|
use super::{eat_stmts, AtRule};
|
||||||
|
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
@ -32,7 +32,9 @@ impl Branch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl If {
|
impl If {
|
||||||
pub fn from_tokens<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) -> SassResult<If> {
|
pub fn from_tokens<I: Iterator<Item = Token>>(
|
||||||
|
toks: &mut PeekMoreIterator<I>,
|
||||||
|
) -> SassResult<If> {
|
||||||
let mut branches = Vec::new();
|
let mut branches = Vec::new();
|
||||||
let init_cond = read_until_open_curly_brace(toks);
|
let init_cond = read_until_open_curly_brace(toks);
|
||||||
toks.next();
|
toks.next();
|
||||||
@ -111,7 +113,7 @@ impl If {
|
|||||||
if !found_true {
|
if !found_true {
|
||||||
toks = self.else_;
|
toks = self.else_;
|
||||||
}
|
}
|
||||||
for stmt in eat_stmts(&mut toks.into_iter().peekable(), scope, super_selector)? {
|
for stmt in eat_stmts(&mut toks.into_iter().peekmore(), scope, super_selector)? {
|
||||||
match stmt.node {
|
match stmt.node {
|
||||||
Stmt::AtRule(AtRule::If(i)) => stmts.extend(i.eval(scope, super_selector)?),
|
Stmt::AtRule(AtRule::If(i)) => stmts.extend(i.eval(scope, super_selector)?),
|
||||||
Stmt::RuleSet(r) if r.selector.is_empty() => stmts.extend(r.rules),
|
Stmt::RuleSet(r) if r.selector.is_empty() => stmts.extend(r.rules),
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use std::iter::Peekable;
|
|
||||||
use std::vec::IntoIter;
|
use std::vec::IntoIter;
|
||||||
|
|
||||||
use codemap::Spanned;
|
use codemap::Spanned;
|
||||||
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use super::eat_stmts;
|
use super::eat_stmts;
|
||||||
|
|
||||||
use crate::args::{eat_call_args, eat_func_args, CallArgs, FuncArgs};
|
use crate::args::{eat_call_args, eat_func_args, CallArgs, FuncArgs};
|
||||||
@ -20,7 +21,7 @@ use crate::{eat_expr, Expr, RuleSet, Stmt, Token};
|
|||||||
pub(crate) struct Mixin {
|
pub(crate) struct Mixin {
|
||||||
scope: Scope,
|
scope: Scope,
|
||||||
args: FuncArgs,
|
args: FuncArgs,
|
||||||
body: Peekable<IntoIter<Token>>,
|
body: PeekMoreIterator<IntoIter<Token>>,
|
||||||
content: Vec<Spanned<Stmt>>,
|
content: Vec<Spanned<Stmt>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ impl Mixin {
|
|||||||
body: Vec<Token>,
|
body: Vec<Token>,
|
||||||
content: Vec<Spanned<Stmt>>,
|
content: Vec<Spanned<Stmt>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let body = body.into_iter().peekable();
|
let body = body.into_iter().peekmore();
|
||||||
Mixin {
|
Mixin {
|
||||||
scope,
|
scope,
|
||||||
args,
|
args,
|
||||||
@ -41,7 +42,7 @@ impl Mixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn decl_from_tokens<I: Iterator<Item = Token>>(
|
pub fn decl_from_tokens<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Spanned<(String, Mixin)>> {
|
) -> SassResult<Spanned<(String, Mixin)>> {
|
||||||
@ -95,7 +96,7 @@ impl Mixin {
|
|||||||
Some(v) => v?,
|
Some(v) => v?,
|
||||||
None => match &arg.default {
|
None => match &arg.default {
|
||||||
Some(v) => Value::from_tokens(
|
Some(v) => Value::from_tokens(
|
||||||
&mut v.iter().cloned().peekable(),
|
&mut v.iter().cloned().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?,
|
)?,
|
||||||
@ -177,7 +178,7 @@ impl Mixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_include<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_include<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Vec<Spanned<Stmt>>> {
|
) -> SassResult<Vec<Spanned<Stmt>>> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::iter::Peekable;
|
|
||||||
|
|
||||||
use codemap::{Span, Spanned};
|
use codemap::{Span, Spanned};
|
||||||
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use crate::common::{Brackets, ListSeparator};
|
use crate::common::{Brackets, ListSeparator};
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
@ -50,7 +50,7 @@ impl AtRule {
|
|||||||
pub fn from_tokens<I: Iterator<Item = Token>>(
|
pub fn from_tokens<I: Iterator<Item = Token>>(
|
||||||
rule: &AtRuleKind,
|
rule: &AtRuleKind,
|
||||||
kind_span: Span,
|
kind_span: Span,
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Spanned<AtRule>> {
|
) -> SassResult<Spanned<AtRule>> {
|
||||||
@ -139,7 +139,7 @@ impl AtRule {
|
|||||||
let mut selector = &Selector::replace(
|
let mut selector = &Selector::replace(
|
||||||
super_selector,
|
super_selector,
|
||||||
Selector::from_tokens(
|
Selector::from_tokens(
|
||||||
&mut read_until_open_curly_brace(toks).into_iter().peekable(),
|
&mut read_until_open_curly_brace(toks).into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?,
|
)?,
|
||||||
@ -156,7 +156,7 @@ impl AtRule {
|
|||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
let mut styles = Vec::new();
|
let mut styles = Vec::new();
|
||||||
let raw_stmts = eat_stmts_at_root(
|
let raw_stmts = eat_stmts_at_root(
|
||||||
&mut body.into_iter().peekable(),
|
&mut body.into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
selector,
|
selector,
|
||||||
0,
|
0,
|
||||||
@ -284,7 +284,7 @@ impl AtRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stmts.extend(eat_stmts(
|
stmts.extend(eat_stmts(
|
||||||
&mut body.clone().into_iter().peekable(),
|
&mut body.clone().into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?);
|
)?);
|
||||||
@ -323,7 +323,7 @@ impl AtRule {
|
|||||||
let mut val = Value::from_vec(cond.clone(), scope, super_selector)?;
|
let mut val = Value::from_vec(cond.clone(), scope, super_selector)?;
|
||||||
while val.node.is_true(val.span)? {
|
while val.node.is_true(val.span)? {
|
||||||
stmts.extend(eat_stmts(
|
stmts.extend(eat_stmts(
|
||||||
&mut body.clone().into_iter().peekable(),
|
&mut body.clone().into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?);
|
)?);
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use std::iter::Peekable;
|
|
||||||
|
|
||||||
use codemap::Spanned;
|
use codemap::Spanned;
|
||||||
|
|
||||||
|
use peekmore::PeekMoreIterator;
|
||||||
|
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use crate::selector::Selector;
|
use crate::selector::Selector;
|
||||||
use crate::{eat_expr, Expr, RuleSet, Stmt, Token};
|
use crate::{eat_expr, Expr, RuleSet, Stmt, Token};
|
||||||
|
|
||||||
pub(crate) fn eat_stmts<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_stmts<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Vec<Spanned<Stmt>>> {
|
) -> SassResult<Vec<Spanned<Stmt>>> {
|
||||||
@ -46,7 +46,7 @@ pub(crate) fn eat_stmts<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_stmts_at_root<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_stmts_at_root<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
mut nesting: usize,
|
mut nesting: usize,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::iter::Peekable;
|
|
||||||
|
|
||||||
use codemap::{Span, Spanned};
|
use codemap::{Span, Spanned};
|
||||||
|
|
||||||
|
use peekmore::PeekMoreIterator;
|
||||||
|
|
||||||
use super::parse::eat_stmts;
|
use super::parse::eat_stmts;
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
@ -19,7 +19,7 @@ pub(crate) struct UnknownAtRule {
|
|||||||
|
|
||||||
impl UnknownAtRule {
|
impl UnknownAtRule {
|
||||||
pub fn from_tokens<I: Iterator<Item = Token>>(
|
pub fn from_tokens<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
name: &str,
|
name: &str,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
|
24
src/lib.rs
24
src/lib.rs
@ -83,11 +83,13 @@ grass input.scss
|
|||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::iter::{Iterator, Peekable};
|
use std::iter::Iterator;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use codemap::{CodeMap, Span, Spanned};
|
use codemap::{CodeMap, Span, Spanned};
|
||||||
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use crate::atrule::{eat_include, AtRule, AtRuleKind, Function, Mixin};
|
use crate::atrule::{eat_include, AtRule, AtRuleKind, Function, Mixin};
|
||||||
pub use crate::error::{SassError, SassResult};
|
pub use crate::error::{SassError, SassResult};
|
||||||
use crate::format::PrettyPrinter;
|
use crate::format::PrettyPrinter;
|
||||||
@ -220,7 +222,7 @@ impl StyleSheet {
|
|||||||
let file = map.add_file("stdin".into(), input);
|
let file = map.add_file("stdin".into(), input);
|
||||||
Css::from_stylesheet(StyleSheet(
|
Css::from_stylesheet(StyleSheet(
|
||||||
StyleSheetParser {
|
StyleSheetParser {
|
||||||
lexer: Lexer::new(&file).peekable(),
|
lexer: Lexer::new(&file).peekmore(),
|
||||||
nesting: 0,
|
nesting: 0,
|
||||||
map: &map,
|
map: &map,
|
||||||
}
|
}
|
||||||
@ -255,7 +257,7 @@ impl StyleSheet {
|
|||||||
let file = map.add_file(p.clone().into(), String::from_utf8(fs::read(p.as_ref())?)?);
|
let file = map.add_file(p.clone().into(), String::from_utf8(fs::read(p.as_ref())?)?);
|
||||||
Css::from_stylesheet(StyleSheet(
|
Css::from_stylesheet(StyleSheet(
|
||||||
StyleSheetParser {
|
StyleSheetParser {
|
||||||
lexer: Lexer::new(&file).peekable(),
|
lexer: Lexer::new(&file).peekmore(),
|
||||||
nesting: 0,
|
nesting: 0,
|
||||||
map: &map,
|
map: &map,
|
||||||
}
|
}
|
||||||
@ -275,7 +277,7 @@ impl StyleSheet {
|
|||||||
let mut map = CodeMap::new();
|
let mut map = CodeMap::new();
|
||||||
let file = map.add_file(p.clone().into(), String::from_utf8(fs::read(p.as_ref())?)?);
|
let file = map.add_file(p.clone().into(), String::from_utf8(fs::read(p.as_ref())?)?);
|
||||||
Ok(StyleSheetParser {
|
Ok(StyleSheetParser {
|
||||||
lexer: Lexer::new(&file).peekable(),
|
lexer: Lexer::new(&file).peekmore(),
|
||||||
nesting: 0,
|
nesting: 0,
|
||||||
map: &map,
|
map: &map,
|
||||||
}
|
}
|
||||||
@ -288,7 +290,7 @@ impl StyleSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct StyleSheetParser<'a> {
|
struct StyleSheetParser<'a> {
|
||||||
lexer: Peekable<Lexer<'a>>,
|
lexer: PeekMoreIterator<Lexer<'a>>,
|
||||||
nesting: u32,
|
nesting: u32,
|
||||||
map: &'a CodeMap,
|
map: &'a CodeMap,
|
||||||
}
|
}
|
||||||
@ -520,7 +522,7 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Option<Spanned<Expr>>> {
|
) -> SassResult<Option<Spanned<Expr>>> {
|
||||||
@ -537,7 +539,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
let tok = toks.next();
|
let tok = toks.next();
|
||||||
if devour_whitespace(toks) {
|
if devour_whitespace(toks) {
|
||||||
let prop = Style::parse_property(
|
let prop = Style::parse_property(
|
||||||
&mut values.into_iter().peekable(),
|
&mut values.into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
String::new(),
|
String::new(),
|
||||||
@ -555,7 +557,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
// special edge case where there was no space between the colon
|
// special edge case where there was no space between the colon
|
||||||
// in a style, e.g. `color:red`. todo: refactor
|
// in a style, e.g. `color:red`. todo: refactor
|
||||||
let mut v = values.into_iter().peekable();
|
let mut v = values.into_iter().peekmore();
|
||||||
devour_whitespace(&mut v);
|
devour_whitespace(&mut v);
|
||||||
if v.peek().is_none() {
|
if v.peek().is_none() {
|
||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
@ -587,7 +589,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
// special edge case where there was no space between the colon
|
// special edge case where there was no space between the colon
|
||||||
// and no semicolon following the style
|
// and no semicolon following the style
|
||||||
// in a style `color:red`. todo: refactor
|
// in a style `color:red`. todo: refactor
|
||||||
let mut v = values.into_iter().peekable();
|
let mut v = values.into_iter().peekmore();
|
||||||
let property =
|
let property =
|
||||||
Style::parse_property(&mut v, scope, super_selector, String::new())?;
|
Style::parse_property(&mut v, scope, super_selector, String::new())?;
|
||||||
let value = Style::parse_value(&mut v, scope, super_selector)?;
|
let value = Style::parse_value(&mut v, scope, super_selector)?;
|
||||||
@ -602,7 +604,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
return Ok(Some(Spanned {
|
return Ok(Some(Spanned {
|
||||||
node: Expr::Selector(Selector::from_tokens(
|
node: Expr::Selector(Selector::from_tokens(
|
||||||
&mut values.into_iter().peekable(),
|
&mut values.into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?),
|
)?),
|
||||||
@ -713,7 +715,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_interpolation<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) -> Vec<Token> {
|
fn eat_interpolation<I: Iterator<Item = Token>>(toks: &mut PeekMoreIterator<I>) -> Vec<Token> {
|
||||||
let mut vals = Vec::new();
|
let mut vals = Vec::new();
|
||||||
let mut n = 1;
|
let mut n = 1;
|
||||||
for tok in toks {
|
for tok in toks {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use std::iter::Peekable;
|
|
||||||
|
use peekmore::PeekMoreIterator;
|
||||||
|
|
||||||
use codemap::Span;
|
use codemap::Span;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ pub(crate) struct Attribute {
|
|||||||
|
|
||||||
impl Attribute {
|
impl Attribute {
|
||||||
pub fn from_tokens<I: Iterator<Item = Token>>(
|
pub fn from_tokens<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
mut start: Span,
|
mut start: Span,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::fmt::{self, Display, Write};
|
use std::fmt::{self, Display, Write};
|
||||||
use std::iter::Peekable;
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
@ -26,7 +27,7 @@ struct SelectorPart {
|
|||||||
|
|
||||||
impl Display for SelectorPart {
|
impl Display for SelectorPart {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut iter = self.inner.iter().peekable();
|
let mut iter = self.inner.iter().peekmore();
|
||||||
devour_whitespace(&mut iter);
|
devour_whitespace(&mut iter);
|
||||||
while let Some(s) = iter.next() {
|
while let Some(s) = iter.next() {
|
||||||
write!(f, "{}", s)?;
|
write!(f, "{}", s)?;
|
||||||
@ -176,7 +177,7 @@ fn is_selector_name_char(c: char) -> bool {
|
|||||||
|
|
||||||
impl Selector {
|
impl Selector {
|
||||||
pub fn from_tokens<I: Iterator<Item = Token>>(
|
pub fn from_tokens<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Selector> {
|
) -> SassResult<Selector> {
|
||||||
@ -252,7 +253,7 @@ impl Selector {
|
|||||||
tok
|
tok
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let mut iter = sel_toks.into_iter().peekable();
|
let mut iter = sel_toks.into_iter().peekmore();
|
||||||
|
|
||||||
while let Some(tok) = iter.peek() {
|
while let Some(tok) = iter.peek() {
|
||||||
inner.push(match tok.kind {
|
inner.push(match tok.kind {
|
||||||
@ -360,7 +361,7 @@ impl Selector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn consume_pseudo_selector<I: Iterator<Item = Token>>(
|
fn consume_pseudo_selector<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<SelectorKind> {
|
) -> SassResult<SelectorKind> {
|
||||||
@ -378,7 +379,7 @@ impl Selector {
|
|||||||
let mut inner_toks = read_until_closing_paren(toks);
|
let mut inner_toks = read_until_closing_paren(toks);
|
||||||
inner_toks.pop();
|
inner_toks.pop();
|
||||||
let inner = Selector::from_tokens(
|
let inner = Selector::from_tokens(
|
||||||
&mut inner_toks.into_iter().peekable(),
|
&mut inner_toks.into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?;
|
)?;
|
||||||
|
14
src/style.rs
14
src/style.rs
@ -1,4 +1,4 @@
|
|||||||
use std::iter::Peekable;
|
use peekmore::PeekMoreIterator;
|
||||||
|
|
||||||
use codemap::Spanned;
|
use codemap::Spanned;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ pub(crate) struct Style {
|
|||||||
|
|
||||||
impl Style {
|
impl Style {
|
||||||
pub fn parse_property<I: Iterator<Item = Token>>(
|
pub fn parse_property<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
super_property: String,
|
super_property: String,
|
||||||
@ -48,7 +48,7 @@ impl Style {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_value<I: Iterator<Item = Token>>(
|
pub fn parse_value<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Spanned<Value>> {
|
) -> SassResult<Spanned<Value>> {
|
||||||
@ -56,7 +56,7 @@ impl Style {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_tokens<I: Iterator<Item = Token>>(
|
pub fn from_tokens<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
super_property: String,
|
super_property: String,
|
||||||
@ -80,7 +80,7 @@ impl<'a> StyleParser<'a> {
|
|||||||
|
|
||||||
pub(crate) fn parse_style_value<I: Iterator<Item = Token>>(
|
pub(crate) fn parse_style_value<I: Iterator<Item = Token>>(
|
||||||
&self,
|
&self,
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
) -> SassResult<Spanned<Value>> {
|
) -> SassResult<Spanned<Value>> {
|
||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
@ -93,7 +93,7 @@ impl<'a> StyleParser<'a> {
|
|||||||
|
|
||||||
pub(crate) fn eat_style_group<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_style_group<I: Iterator<Item = Token>>(
|
||||||
&self,
|
&self,
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
super_property: String,
|
super_property: String,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
) -> SassResult<Expr> {
|
) -> SassResult<Expr> {
|
||||||
@ -199,7 +199,7 @@ impl<'a> StyleParser<'a> {
|
|||||||
|
|
||||||
pub(crate) fn parse_property<I: Iterator<Item = Token>>(
|
pub(crate) fn parse_property<I: Iterator<Item = Token>>(
|
||||||
&self,
|
&self,
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
mut super_property: String,
|
mut super_property: String,
|
||||||
) -> SassResult<String> {
|
) -> SassResult<String> {
|
||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
|
52
src/utils.rs
52
src/utils.rs
@ -1,7 +1,9 @@
|
|||||||
use std::iter::{Iterator, Peekable};
|
use std::iter::Iterator;
|
||||||
|
|
||||||
use codemap::{Span, Spanned};
|
use codemap::{Span, Spanned};
|
||||||
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use crate::common::QuoteKind;
|
use crate::common::QuoteKind;
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::selector::Selector;
|
use crate::selector::Selector;
|
||||||
@ -19,7 +21,7 @@ impl IsWhitespace for char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn devour_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(
|
pub(crate) fn devour_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(
|
||||||
s: &mut Peekable<I>,
|
s: &mut PeekMoreIterator<I>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut found_whitespace = false;
|
let mut found_whitespace = false;
|
||||||
while let Some(w) = s.peek() {
|
while let Some(w) = s.peek() {
|
||||||
@ -37,7 +39,7 @@ pub(crate) trait IsComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn devour_whitespace_or_comment<I: Iterator<Item = Token>>(
|
pub(crate) fn devour_whitespace_or_comment<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
) -> SassResult<bool> {
|
) -> SassResult<bool> {
|
||||||
let mut found_whitespace = false;
|
let mut found_whitespace = false;
|
||||||
while let Some(tok) = toks.peek() {
|
while let Some(tok) = toks.peek() {
|
||||||
@ -63,7 +65,7 @@ pub(crate) fn devour_whitespace_or_comment<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_interpolation<I: Iterator<Item = Token>>(
|
pub(crate) fn parse_interpolation<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Spanned<Value>> {
|
) -> SassResult<Spanned<Value>> {
|
||||||
@ -95,7 +97,7 @@ impl VariableDecl {
|
|||||||
//
|
//
|
||||||
// Does not consume the open curly brace
|
// Does not consume the open curly brace
|
||||||
pub(crate) fn read_until_open_curly_brace<I: Iterator<Item = Token>>(
|
pub(crate) fn read_until_open_curly_brace<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
) -> Vec<Token> {
|
) -> Vec<Token> {
|
||||||
let mut val = Vec::new();
|
let mut val = Vec::new();
|
||||||
let mut n = 0;
|
let mut n = 0;
|
||||||
@ -123,7 +125,7 @@ pub(crate) fn read_until_open_curly_brace<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_until_closing_curly_brace<I: Iterator<Item = Token>>(
|
pub(crate) fn read_until_closing_curly_brace<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
) -> Vec<Token> {
|
) -> Vec<Token> {
|
||||||
let mut t = Vec::new();
|
let mut t = Vec::new();
|
||||||
let mut nesting = 0;
|
let mut nesting = 0;
|
||||||
@ -161,7 +163,7 @@ pub(crate) fn read_until_closing_curly_brace<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_until_closing_quote<I: Iterator<Item = Token>>(
|
pub(crate) fn read_until_closing_quote<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
q: char,
|
q: char,
|
||||||
) -> Vec<Token> {
|
) -> Vec<Token> {
|
||||||
let mut t = Vec::new();
|
let mut t = Vec::new();
|
||||||
@ -194,7 +196,7 @@ pub(crate) fn read_until_closing_quote<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_until_semicolon_or_closing_curly_brace<I: Iterator<Item = Token>>(
|
pub(crate) fn read_until_semicolon_or_closing_curly_brace<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
) -> Vec<Token> {
|
) -> Vec<Token> {
|
||||||
let mut t = Vec::new();
|
let mut t = Vec::new();
|
||||||
let mut nesting = 0;
|
let mut nesting = 0;
|
||||||
@ -240,7 +242,7 @@ pub(crate) fn read_until_semicolon_or_closing_curly_brace<I: Iterator<Item = Tok
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_until_semicolon_or_open_or_closing_curly_brace<I: Iterator<Item = Token>>(
|
pub(crate) fn read_until_semicolon_or_open_or_closing_curly_brace<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
) -> Vec<Token> {
|
) -> Vec<Token> {
|
||||||
let mut t = Vec::new();
|
let mut t = Vec::new();
|
||||||
let mut nesting = 0;
|
let mut nesting = 0;
|
||||||
@ -299,7 +301,7 @@ pub(crate) fn read_until_semicolon_or_open_or_closing_curly_brace<I: Iterator<It
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_variable_value<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_variable_value<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<VariableDecl> {
|
) -> SassResult<VariableDecl> {
|
||||||
@ -308,7 +310,7 @@ pub(crate) fn eat_variable_value<I: Iterator<Item = Token>>(
|
|||||||
let mut global = false;
|
let mut global = false;
|
||||||
let mut raw = read_until_semicolon_or_closing_curly_brace(toks)
|
let mut raw = read_until_semicolon_or_closing_curly_brace(toks)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.peekable();
|
.peekmore();
|
||||||
if toks.peek().is_some() && toks.peek().unwrap().kind == ';' {
|
if toks.peek().is_some() && toks.peek().unwrap().kind == ';' {
|
||||||
toks.next();
|
toks.next();
|
||||||
}
|
}
|
||||||
@ -348,7 +350,7 @@ pub(crate) fn eat_variable_value<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ident_body<I: Iterator<Item = Token>>(
|
fn ident_body<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
unit: bool,
|
unit: bool,
|
||||||
mut span: Span,
|
mut span: Span,
|
||||||
) -> SassResult<Spanned<String>> {
|
) -> SassResult<Spanned<String>> {
|
||||||
@ -356,8 +358,8 @@ fn ident_body<I: Iterator<Item = Token>>(
|
|||||||
while let Some(tok) = toks.peek() {
|
while let Some(tok) = toks.peek() {
|
||||||
span = span.merge(tok.pos());
|
span = span.merge(tok.pos());
|
||||||
if unit && tok.kind == '-' {
|
if unit && tok.kind == '-' {
|
||||||
todo!()
|
// Disallow `-` followed by a dot or a digit digit in units.
|
||||||
// Disallow `-` followed by a dot or a digit digit in units.
|
toks.next();
|
||||||
// var second = scanner.peekChar(1);
|
// var second = scanner.peekChar(1);
|
||||||
// if (second != null && (second == $dot || isDigit(second))) break;
|
// if (second != null && (second == $dot || isDigit(second))) break;
|
||||||
// text.writeCharCode(scanner.readChar());
|
// text.writeCharCode(scanner.readChar());
|
||||||
@ -374,7 +376,7 @@ fn ident_body<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn interpolated_ident_body<I: Iterator<Item = Token>>(
|
fn interpolated_ident_body<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
mut span: Span,
|
mut span: Span,
|
||||||
@ -419,7 +421,7 @@ fn is_name_start(c: char) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn escape<I: Iterator<Item = Token>>(
|
fn escape<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
identifier_start: bool,
|
identifier_start: bool,
|
||||||
) -> SassResult<String> {
|
) -> SassResult<String> {
|
||||||
let mut value = 0;
|
let mut value = 0;
|
||||||
@ -475,7 +477,7 @@ fn escape<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_ident<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_ident<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Spanned<String>> {
|
) -> SassResult<Spanned<String>> {
|
||||||
@ -532,7 +534,7 @@ pub(crate) fn eat_ident<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_ident_no_interpolation<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_ident_no_interpolation<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
unit: bool,
|
unit: bool,
|
||||||
) -> SassResult<Spanned<String>> {
|
) -> SassResult<Spanned<String>> {
|
||||||
let mut span = toks.peek().unwrap().pos();
|
let mut span = toks.peek().unwrap().pos();
|
||||||
@ -569,7 +571,7 @@ pub(crate) fn eat_ident_no_interpolation<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_number<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_number<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
) -> SassResult<Spanned<String>> {
|
) -> SassResult<Spanned<String>> {
|
||||||
let mut whole = String::new();
|
let mut whole = String::new();
|
||||||
let mut span = if let Some(tok) = toks.peek() {
|
let mut span = if let Some(tok) = toks.peek() {
|
||||||
@ -621,7 +623,7 @@ pub(crate) fn eat_number<I: Iterator<Item = Token>>(
|
|||||||
/// We only have to check for \n as the lexing step normalizes all newline characters
|
/// We only have to check for \n as the lexing step normalizes all newline characters
|
||||||
///
|
///
|
||||||
/// The newline is consumed
|
/// The newline is consumed
|
||||||
pub(crate) fn read_until_newline<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) {
|
pub(crate) fn read_until_newline<I: Iterator<Item = Token>>(toks: &mut PeekMoreIterator<I>) {
|
||||||
for tok in toks {
|
for tok in toks {
|
||||||
if tok.kind == '\n' {
|
if tok.kind == '\n' {
|
||||||
break;
|
break;
|
||||||
@ -635,7 +637,7 @@ pub(crate) fn read_until_newline<I: Iterator<Item = Token>>(toks: &mut Peekable<
|
|||||||
/// The entirety of the comment, including the ending "*/" is consumed.
|
/// The entirety of the comment, including the ending "*/" is consumed.
|
||||||
/// Note that the ending "*/" is not included in the output.
|
/// Note that the ending "*/" is not included in the output.
|
||||||
pub(crate) fn eat_comment<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_comment<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Spanned<String>> {
|
) -> SassResult<Spanned<String>> {
|
||||||
@ -676,7 +678,7 @@ fn as_hex(c: u32) -> u32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
|
pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
q: char,
|
q: char,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
@ -753,7 +755,7 @@ pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_until_closing_paren<I: Iterator<Item = Token>>(
|
pub(crate) fn read_until_closing_paren<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
) -> Vec<Token> {
|
) -> Vec<Token> {
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
let mut scope = 0;
|
let mut scope = 0;
|
||||||
@ -781,7 +783,7 @@ pub(crate) fn read_until_closing_paren<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_until_closing_square_brace<I: Iterator<Item = Token>>(
|
pub(crate) fn read_until_closing_square_brace<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
) -> Vec<Token> {
|
) -> Vec<Token> {
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
let mut scope = 0;
|
let mut scope = 0;
|
||||||
@ -809,7 +811,7 @@ pub(crate) fn read_until_closing_square_brace<I: Iterator<Item = Token>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read_until_char<I: Iterator<Item = Token>>(
|
pub(crate) fn read_until_char<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
c: char,
|
c: char,
|
||||||
) -> Vec<Token> {
|
) -> Vec<Token> {
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::iter::Peekable;
|
use peekmore::PeekMoreIterator;
|
||||||
|
|
||||||
use crate::error::SassResult;
|
use crate::error::SassResult;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
@ -7,7 +7,7 @@ use crate::utils::{devour_whitespace, parse_interpolation};
|
|||||||
use crate::Token;
|
use crate::Token;
|
||||||
|
|
||||||
pub(crate) fn eat_calc_args<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_calc_args<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<String> {
|
) -> SassResult<String> {
|
||||||
@ -57,7 +57,7 @@ pub(crate) fn is_special_function(s: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn eat_progid<I: Iterator<Item = Token>>(
|
pub(crate) fn eat_progid<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<String> {
|
) -> SassResult<String> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::iter::{Iterator, Peekable};
|
use std::iter::Iterator;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
@ -8,6 +8,8 @@ use num_traits::pow;
|
|||||||
|
|
||||||
use codemap::{Span, Spanned};
|
use codemap::{Span, Spanned};
|
||||||
|
|
||||||
|
use peekmore::{PeekMore, PeekMoreIterator};
|
||||||
|
|
||||||
use super::css_function::{eat_calc_args, eat_progid};
|
use super::css_function::{eat_calc_args, eat_progid};
|
||||||
|
|
||||||
use crate::args::eat_call_args;
|
use crate::args::eat_call_args;
|
||||||
@ -30,7 +32,7 @@ use super::map::SassMap;
|
|||||||
use super::number::Number;
|
use super::number::Number;
|
||||||
|
|
||||||
fn parse_hex<I: Iterator<Item = Token>>(
|
fn parse_hex<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
mut span: Span,
|
mut span: Span,
|
||||||
@ -140,7 +142,7 @@ fn parse_paren(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let paren_toks = &mut t.node.into_iter().peekable();
|
let paren_toks = &mut t.node.into_iter().peekmore();
|
||||||
|
|
||||||
let mut map = SassMap::new();
|
let mut map = SassMap::new();
|
||||||
let key = Value::from_vec(read_until_char(paren_toks, ':'), scope, super_selector)?;
|
let key = Value::from_vec(read_until_char(paren_toks, ':'), scope, super_selector)?;
|
||||||
@ -188,7 +190,7 @@ fn parse_paren(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn eat_op<I: Iterator<Item = IntermediateValue>>(
|
fn eat_op<I: Iterator<Item = IntermediateValue>>(
|
||||||
iter: &mut Peekable<I>,
|
iter: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
op: Spanned<Op>,
|
op: Spanned<Op>,
|
||||||
@ -300,7 +302,7 @@ fn eat_op<I: Iterator<Item = IntermediateValue>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn single_value<I: Iterator<Item = IntermediateValue>>(
|
fn single_value<I: Iterator<Item = IntermediateValue>>(
|
||||||
iter: &mut Peekable<I>,
|
iter: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
span: Span,
|
span: Span,
|
||||||
@ -363,7 +365,7 @@ fn single_value<I: Iterator<Item = IntermediateValue>>(
|
|||||||
|
|
||||||
impl Value {
|
impl Value {
|
||||||
pub fn from_tokens<I: Iterator<Item = Token>>(
|
pub fn from_tokens<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Spanned<Self>> {
|
) -> SassResult<Spanned<Self>> {
|
||||||
@ -379,7 +381,7 @@ impl Value {
|
|||||||
let mut last_was_whitespace = false;
|
let mut last_was_whitespace = false;
|
||||||
let mut space_separated = Vec::new();
|
let mut space_separated = Vec::new();
|
||||||
let mut comma_separated = Vec::new();
|
let mut comma_separated = Vec::new();
|
||||||
let mut iter = intermediate_values.into_iter().peekable();
|
let mut iter = intermediate_values.into_iter().peekmore();
|
||||||
while let Some(val) = iter.next() {
|
while let Some(val) = iter.next() {
|
||||||
match val {
|
match val {
|
||||||
IntermediateValue::Value(v) => {
|
IntermediateValue::Value(v) => {
|
||||||
@ -484,11 +486,11 @@ impl Value {
|
|||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<Spanned<Value>> {
|
) -> SassResult<Spanned<Value>> {
|
||||||
Self::from_tokens(&mut toks.into_iter().peekable(), scope, super_selector)
|
Self::from_tokens(&mut toks.into_iter().peekmore(), scope, super_selector)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ident<I: Iterator<Item = Token>>(
|
fn ident<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<IntermediateValue> {
|
) -> SassResult<IntermediateValue> {
|
||||||
@ -583,7 +585,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_intermediate_value<I: Iterator<Item = Token>>(
|
fn parse_intermediate_value<I: Iterator<Item = Token>>(
|
||||||
toks: &mut Peekable<I>,
|
toks: &mut PeekMoreIterator<I>,
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<IntermediateValue> {
|
) -> SassResult<IntermediateValue> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user