From a813cab0d70ed81eb592a3f350ee15b7967cab9d Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Thu, 9 Jul 2020 11:56:58 -0400 Subject: [PATCH] remove generics from utility fns --- src/utils/chars.rs | 6 ++-- src/utils/comment_whitespace.rs | 9 ++++-- src/utils/number.rs | 10 +++---- src/utils/peek_until.rs | 38 +++++++++---------------- src/utils/read_until.rs | 50 ++++++++++++++++----------------- 5 files changed, 54 insertions(+), 59 deletions(-) diff --git a/src/utils/chars.rs b/src/utils/chars.rs index f0aa466..68efb60 100644 --- a/src/utils/chars.rs +++ b/src/utils/chars.rs @@ -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>( - toks: &mut PeekMoreIterator, +pub(crate) fn read_until_char( + toks: &mut PeekMoreIterator>, c: char, ) -> SassResult> { let mut v = Vec::new(); diff --git a/src/utils/comment_whitespace.rs b/src/utils/comment_whitespace.rs index 4f95c46..fe3d9fe 100644 --- a/src/utils/comment_whitespace.rs +++ b/src/utils/comment_whitespace.rs @@ -1,3 +1,5 @@ +use std::vec::IntoIter; + use peekmore::PeekMoreIterator; use crate::Token; @@ -26,13 +28,16 @@ pub(crate) fn devour_whitespace, W: IsWhitespace>( found_whitespace } -pub(crate) fn peek_whitespace, W: IsWhitespace>(s: &mut PeekMoreIterator) { +pub(crate) fn peek_whitespace(s: &mut PeekMoreIterator>) -> 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, W: IsWhitespace>(s: &mut Pe pub(crate) fn read_until_newline>(toks: &mut PeekMoreIterator) { for tok in toks { if tok.kind == '\n' { - break; + return; } } } diff --git a/src/utils/number.rs b/src/utils/number.rs index 7102607..a51c754 100644 --- a/src/utils/number.rs +++ b/src/utils/number.rs @@ -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>( - toks: &mut PeekMoreIterator, +pub(crate) fn eat_number( + toks: &mut PeekMoreIterator>, ) -> SassResult> { let mut span = toks.peek().unwrap().pos; let mut whole = eat_whole_number(toks); @@ -112,9 +114,7 @@ pub(crate) fn eat_number>( }) } -pub(crate) fn eat_whole_number>( - toks: &mut PeekMoreIterator, -) -> String { +pub(crate) fn eat_whole_number(toks: &mut PeekMoreIterator>) -> String { let mut buf = String::new(); while let Some(c) = toks.peek() { if !c.kind.is_ascii_digit() { diff --git a/src/utils/peek_until.rs b/src/utils/peek_until.rs index 9f5b307..59f65b0 100644 --- a/src/utils/peek_until.rs +++ b/src/utils/peek_until.rs @@ -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>( - toks: &mut PeekMoreIterator, +pub(crate) fn peek_until_closing_curly_brace( + toks: &mut PeekMoreIterator>, ) -> SassResult> { let mut t = Vec::new(); let mut nesting = 0; @@ -52,8 +54,8 @@ pub(crate) fn peek_until_closing_curly_brace>( Ok(t) } -fn peek_until_closing_quote>( - toks: &mut PeekMoreIterator, +fn peek_until_closing_quote( + toks: &mut PeekMoreIterator>, q: char, ) -> SassResult> { let mut t = Vec::new(); @@ -95,7 +97,7 @@ fn peek_until_closing_quote>( Ok(t) } -fn peek_until_newline>(toks: &mut PeekMoreIterator) { +fn peek_until_newline(toks: &mut PeekMoreIterator>) { while let Some(tok) = toks.peek() { if tok.kind == '\n' { break; @@ -104,21 +106,7 @@ fn peek_until_newline>(toks: &mut PeekMoreIterator) } } -fn peek_whitespace, W: IsWhitespace>(s: &mut PeekMoreIterator) -> 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>( - toks: &mut PeekMoreIterator, -) -> SassResult { +pub(crate) fn peek_escape(toks: &mut PeekMoreIterator>) -> SassResult { let mut value = 0; let first = match toks.peek() { Some(t) => *t, @@ -165,8 +153,8 @@ pub(crate) fn peek_escape>( } } -pub(crate) fn peek_ident_no_interpolation>( - toks: &mut PeekMoreIterator, +pub(crate) fn peek_ident_no_interpolation( + toks: &mut PeekMoreIterator>, unit: bool, span_before: Span, ) -> SassResult> { @@ -210,8 +198,8 @@ pub(crate) fn peek_ident_no_interpolation>( Ok(Spanned { node: text, span }) } -fn peek_ident_body_no_interpolation>( - toks: &mut PeekMoreIterator, +fn peek_ident_body_no_interpolation( + toks: &mut PeekMoreIterator>, unit: bool, mut span: Span, ) -> SassResult> { diff --git a/src/utils/read_until.rs b/src/utils/read_until.rs index bbdbb4a..e1dac0f 100644 --- a/src/utils/read_until.rs +++ b/src/utils/read_until.rs @@ -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>( - toks: &mut PeekMoreIterator, +pub(crate) fn read_until_open_curly_brace( + toks: &mut PeekMoreIterator>, ) -> SassResult> { let mut t = Vec::new(); let mut n = 0; @@ -49,27 +49,27 @@ pub(crate) fn read_until_open_curly_brace>( Ok(t) } -pub(crate) fn read_until_closing_curly_brace>( - toks: &mut PeekMoreIterator, +pub(crate) fn read_until_closing_curly_brace( + toks: &mut PeekMoreIterator>, ) -> SassResult> { - 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>( 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>( - toks: &mut PeekMoreIterator, +pub(crate) fn read_until_closing_quote( + toks: &mut PeekMoreIterator>, q: char, ) -> SassResult> { let mut t = Vec::new(); @@ -150,8 +150,8 @@ pub(crate) fn read_until_closing_quote>( Ok(t) } -pub(crate) fn read_until_semicolon_or_closing_curly_brace>( - toks: &mut PeekMoreIterator, +pub(crate) fn read_until_semicolon_or_closing_curly_brace( + toks: &mut PeekMoreIterator>, ) -> SassResult> { let mut t = Vec::new(); let mut nesting = 0; @@ -202,8 +202,8 @@ pub(crate) fn read_until_semicolon_or_closing_curly_brace>( - toks: &mut PeekMoreIterator, +pub(crate) fn read_until_closing_paren( + toks: &mut PeekMoreIterator>, ) -> SassResult> { let mut t = Vec::new(); let mut scope = 0; @@ -236,8 +236,8 @@ pub(crate) fn read_until_closing_paren>( Ok(t) } -pub(crate) fn read_until_closing_square_brace>( - toks: &mut PeekMoreIterator, +pub(crate) fn read_until_closing_square_brace( + toks: &mut PeekMoreIterator>, ) -> SassResult> { let mut t = Vec::new(); let mut scope = 0;