remove generics from utility fns
This commit is contained in:
parent
b199984170
commit
a813cab0d7
@ -1,3 +1,5 @@
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use peekmore::PeekMoreIterator;
|
||||
|
||||
use crate::{error::SassResult, Token};
|
||||
@ -5,8 +7,8 @@ use crate::{error::SassResult, Token};
|
||||
use super::{read_until_closing_paren, read_until_closing_quote};
|
||||
/// Reads until the char is found, consuming the char,
|
||||
/// or until the end of the iterator is hit
|
||||
pub(crate) fn read_until_char<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn read_until_char(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
c: char,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut v = Vec::new();
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use peekmore::PeekMoreIterator;
|
||||
|
||||
use crate::Token;
|
||||
@ -26,13 +28,16 @@ pub(crate) fn devour_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(
|
||||
found_whitespace
|
||||
}
|
||||
|
||||
pub(crate) fn peek_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(s: &mut PeekMoreIterator<I>) {
|
||||
pub(crate) fn peek_whitespace(s: &mut PeekMoreIterator<IntoIter<Token>>) -> bool {
|
||||
let mut found_whitespace = false;
|
||||
while let Some(w) = s.peek() {
|
||||
if !w.is_whitespace() {
|
||||
break;
|
||||
}
|
||||
found_whitespace = true;
|
||||
s.advance_cursor();
|
||||
}
|
||||
found_whitespace
|
||||
}
|
||||
|
||||
/// Eat tokens until a newline
|
||||
@ -44,7 +49,7 @@ pub(crate) fn peek_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(s: &mut Pe
|
||||
pub(crate) fn read_until_newline<I: Iterator<Item = Token>>(toks: &mut PeekMoreIterator<I>) {
|
||||
for tok in toks {
|
||||
if tok.kind == '\n' {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use codemap::Spanned;
|
||||
use peekmore::PeekMoreIterator;
|
||||
|
||||
@ -45,8 +47,8 @@ impl ParsedNumber {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn eat_number<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn eat_number(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
) -> SassResult<Spanned<ParsedNumber>> {
|
||||
let mut span = toks.peek().unwrap().pos;
|
||||
let mut whole = eat_whole_number(toks);
|
||||
@ -112,9 +114,7 @@ pub(crate) fn eat_number<I: Iterator<Item = Token>>(
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn eat_whole_number<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
) -> String {
|
||||
pub(crate) fn eat_whole_number(toks: &mut PeekMoreIterator<IntoIter<Token>>) -> String {
|
||||
let mut buf = String::new();
|
||||
while let Some(c) = toks.peek() {
|
||||
if !c.kind.is_ascii_digit() {
|
||||
|
@ -1,13 +1,15 @@
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use codemap::{Span, Spanned};
|
||||
|
||||
use peekmore::PeekMoreIterator;
|
||||
|
||||
use crate::{error::SassResult, Token};
|
||||
|
||||
use super::{as_hex, hex_char_for, is_name, is_name_start, IsWhitespace};
|
||||
use super::{as_hex, hex_char_for, is_name, is_name_start, peek_whitespace};
|
||||
|
||||
pub(crate) fn peek_until_closing_curly_brace<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn peek_until_closing_curly_brace(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
let mut nesting = 0;
|
||||
@ -52,8 +54,8 @@ pub(crate) fn peek_until_closing_curly_brace<I: Iterator<Item = Token>>(
|
||||
Ok(t)
|
||||
}
|
||||
|
||||
fn peek_until_closing_quote<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
fn peek_until_closing_quote(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
q: char,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
@ -95,7 +97,7 @@ fn peek_until_closing_quote<I: Iterator<Item = Token>>(
|
||||
Ok(t)
|
||||
}
|
||||
|
||||
fn peek_until_newline<I: Iterator<Item = Token>>(toks: &mut PeekMoreIterator<I>) {
|
||||
fn peek_until_newline(toks: &mut PeekMoreIterator<IntoIter<Token>>) {
|
||||
while let Some(tok) = toks.peek() {
|
||||
if tok.kind == '\n' {
|
||||
break;
|
||||
@ -104,21 +106,7 @@ fn peek_until_newline<I: Iterator<Item = Token>>(toks: &mut PeekMoreIterator<I>)
|
||||
}
|
||||
}
|
||||
|
||||
fn peek_whitespace<I: Iterator<Item = W>, W: IsWhitespace>(s: &mut PeekMoreIterator<I>) -> bool {
|
||||
let mut found_whitespace = false;
|
||||
while let Some(w) = s.peek() {
|
||||
if !w.is_whitespace() {
|
||||
break;
|
||||
}
|
||||
found_whitespace = true;
|
||||
s.advance_cursor();
|
||||
}
|
||||
found_whitespace
|
||||
}
|
||||
|
||||
pub(crate) fn peek_escape<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
) -> SassResult<String> {
|
||||
pub(crate) fn peek_escape(toks: &mut PeekMoreIterator<IntoIter<Token>>) -> SassResult<String> {
|
||||
let mut value = 0;
|
||||
let first = match toks.peek() {
|
||||
Some(t) => *t,
|
||||
@ -165,8 +153,8 @@ pub(crate) fn peek_escape<I: Iterator<Item = Token>>(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn peek_ident_no_interpolation<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn peek_ident_no_interpolation(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
unit: bool,
|
||||
span_before: Span,
|
||||
) -> SassResult<Spanned<String>> {
|
||||
@ -210,8 +198,8 @@ pub(crate) fn peek_ident_no_interpolation<I: Iterator<Item = Token>>(
|
||||
Ok(Spanned { node: text, span })
|
||||
}
|
||||
|
||||
fn peek_ident_body_no_interpolation<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
fn peek_ident_body_no_interpolation(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
unit: bool,
|
||||
mut span: Span,
|
||||
) -> SassResult<Spanned<String>> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::iter::Iterator;
|
||||
use std::vec::IntoIter;
|
||||
|
||||
use peekmore::PeekMoreIterator;
|
||||
|
||||
@ -9,8 +9,8 @@ use super::{devour_whitespace, read_until_newline};
|
||||
// Eat tokens until an open curly brace
|
||||
//
|
||||
// Does not consume the open curly brace
|
||||
pub(crate) fn read_until_open_curly_brace<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn read_until_open_curly_brace(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
let mut n = 0;
|
||||
@ -49,27 +49,27 @@ pub(crate) fn read_until_open_curly_brace<I: Iterator<Item = Token>>(
|
||||
Ok(t)
|
||||
}
|
||||
|
||||
pub(crate) fn read_until_closing_curly_brace<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn read_until_closing_curly_brace(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
let mut buf = Vec::new();
|
||||
let mut nesting = 0;
|
||||
while let Some(tok) = toks.peek() {
|
||||
match tok.kind {
|
||||
q @ '"' | q @ '\'' => {
|
||||
t.push(toks.next().unwrap());
|
||||
t.extend(read_until_closing_quote(toks, q)?);
|
||||
buf.push(toks.next().unwrap());
|
||||
buf.extend(read_until_closing_quote(toks, q)?);
|
||||
}
|
||||
'{' => {
|
||||
nesting += 1;
|
||||
t.push(toks.next().unwrap());
|
||||
buf.push(toks.next().unwrap());
|
||||
}
|
||||
'}' => {
|
||||
if nesting == 0 {
|
||||
break;
|
||||
} else {
|
||||
nesting -= 1;
|
||||
t.push(toks.next().unwrap());
|
||||
buf.push(toks.next().unwrap());
|
||||
}
|
||||
}
|
||||
'/' => {
|
||||
@ -79,33 +79,33 @@ pub(crate) fn read_until_closing_curly_brace<I: Iterator<Item = Token>>(
|
||||
read_until_newline(toks);
|
||||
devour_whitespace(toks);
|
||||
}
|
||||
Some(..) | None => t.push(next),
|
||||
Some(..) | None => buf.push(next),
|
||||
};
|
||||
continue;
|
||||
}
|
||||
'(' => {
|
||||
t.push(toks.next().unwrap());
|
||||
t.extend(read_until_closing_paren(toks)?);
|
||||
buf.push(toks.next().unwrap());
|
||||
buf.extend(read_until_closing_paren(toks)?);
|
||||
}
|
||||
'\\' => {
|
||||
t.push(toks.next().unwrap());
|
||||
t.push(match toks.next() {
|
||||
buf.push(toks.next().unwrap());
|
||||
buf.push(match toks.next() {
|
||||
Some(tok) => tok,
|
||||
None => continue,
|
||||
});
|
||||
}
|
||||
_ => t.push(toks.next().unwrap()),
|
||||
_ => buf.push(toks.next().unwrap()),
|
||||
}
|
||||
}
|
||||
devour_whitespace(toks);
|
||||
Ok(t)
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
/// Read tokens into a vector until a matching closing quote is found
|
||||
///
|
||||
/// The closing quote is included in the output
|
||||
pub(crate) fn read_until_closing_quote<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn read_until_closing_quote(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
q: char,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
@ -150,8 +150,8 @@ pub(crate) fn read_until_closing_quote<I: Iterator<Item = Token>>(
|
||||
Ok(t)
|
||||
}
|
||||
|
||||
pub(crate) fn read_until_semicolon_or_closing_curly_brace<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn read_until_semicolon_or_closing_curly_brace(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
let mut nesting = 0;
|
||||
@ -202,8 +202,8 @@ pub(crate) fn read_until_semicolon_or_closing_curly_brace<I: Iterator<Item = Tok
|
||||
Ok(t)
|
||||
}
|
||||
|
||||
pub(crate) fn read_until_closing_paren<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn read_until_closing_paren(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
let mut scope = 0;
|
||||
@ -236,8 +236,8 @@ pub(crate) fn read_until_closing_paren<I: Iterator<Item = Token>>(
|
||||
Ok(t)
|
||||
}
|
||||
|
||||
pub(crate) fn read_until_closing_square_brace<I: Iterator<Item = Token>>(
|
||||
toks: &mut PeekMoreIterator<I>,
|
||||
pub(crate) fn read_until_closing_square_brace(
|
||||
toks: &mut PeekMoreIterator<IntoIter<Token>>,
|
||||
) -> SassResult<Vec<Token>> {
|
||||
let mut t = Vec::new();
|
||||
let mut scope = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user