Skip to content

Commit 78d6cd7

Browse files
committed
Modify function names to adhere to reduce confusion with Iterator
1 parent 2300188 commit 78d6cd7

File tree

8 files changed

+81
-74
lines changed

8 files changed

+81
-74
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser"
3-
version = "0.33.0"
3+
version = "0.34.0"
44
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
55

66
description = "Rust implementation of CSS Syntax Level 3"

color/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser-color"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Emilio Cobos Álvarez <emilio@crisal.io>"]
55
description = "Color implementation based on cssparser"
66
documentation = "https://docs.rs/cssparser-color/"

color/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where
5050
P: ColorParser<'i>,
5151
{
5252
let location = input.current_source_location();
53-
let token = input.next()?;
53+
let token = input.try_next()?;
5454
match *token {
5555
Token::Hash(ref value) | Token::IDHash(ref value) => {
5656
parse_hash_color(value.as_bytes()).map(|(r, g, b, a)| P::Output::from_rgba(r, g, b, a))
@@ -1033,7 +1033,7 @@ pub trait ColorParser<'i> {
10331033
input: &mut Parser<'i, 't>,
10341034
) -> Result<AngleOrNumber, ParseError<'i, Self::Error>> {
10351035
let location = input.current_source_location();
1036-
Ok(match *input.next()? {
1036+
Ok(match *input.try_next()? {
10371037
Token::Number { value, .. } => AngleOrNumber::Number { value },
10381038
Token::Dimension {
10391039
value: v, ref unit, ..
@@ -1078,7 +1078,7 @@ pub trait ColorParser<'i> {
10781078
input: &mut Parser<'i, 't>,
10791079
) -> Result<NumberOrPercentage, ParseError<'i, Self::Error>> {
10801080
let location = input.current_source_location();
1081-
Ok(match *input.next()? {
1081+
Ok(match *input.try_next()? {
10821082
Token::Number { value, .. } => NumberOrPercentage::Number { value },
10831083
Token::Percentage { unit_value, .. } => NumberOrPercentage::Percentage { unit_value },
10841084
ref t => return Err(location.new_unexpected_token_error(t.clone())),

src/nth.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::{BasicParseError, Parser, ParserInput, Token};
99
/// in which case the caller needs to check if the arguments’ parser is exhausted.
1010
/// Return `Ok((A, B))`, or `Err(())` for a syntax error.
1111
pub fn parse_nth<'i>(input: &mut Parser<'i, '_>) -> Result<(i32, i32), BasicParseError<'i>> {
12-
match *input.next()? {
12+
match *input.try_next()? {
1313
Token::Number {
1414
int_value: Some(b), ..
1515
} => Ok((0, b)),
@@ -55,7 +55,7 @@ pub fn parse_nth<'i>(input: &mut Parser<'i, '_>) -> Result<(i32, i32), BasicPars
5555
}
5656
}
5757
}
58-
Token::Delim('+') => match *input.next_including_whitespace()? {
58+
Token::Delim('+') => match *input.try_next_including_whitespace()? {
5959
Token::Ident(ref value) => {
6060
match_ignore_ascii_case! { value,
6161
"n" => parse_b(input, 1),
@@ -83,7 +83,7 @@ pub fn parse_nth<'i>(input: &mut Parser<'i, '_>) -> Result<(i32, i32), BasicPars
8383

8484
fn parse_b<'i>(input: &mut Parser<'i, '_>, a: i32) -> Result<(i32, i32), BasicParseError<'i>> {
8585
let start = input.state();
86-
match input.next() {
86+
match input.try_next() {
8787
Ok(&Token::Delim('+')) => parse_signless_b(input, a, 1),
8888
Ok(&Token::Delim('-')) => parse_signless_b(input, a, -1),
8989
Ok(&Token::Number {
@@ -104,7 +104,7 @@ fn parse_signless_b<'i>(
104104
b_sign: i32,
105105
) -> Result<(i32, i32), BasicParseError<'i>> {
106106
// FIXME: remove .clone() when lifetimes are non-lexical.
107-
match input.next()?.clone() {
107+
match input.try_next()?.clone() {
108108
Token::Number {
109109
has_sign: false,
110110
int_value: Some(b),
@@ -132,7 +132,7 @@ fn parse_number_saturate(string: &str) -> Result<i32, ()> {
132132
let int = if let Ok(&Token::Number {
133133
int_value: Some(int),
134134
..
135-
}) = parser.next_including_whitespace_and_comments()
135+
}) = parser.try_next_including_whitespace_and_comments()
136136
{
137137
int
138138
} else {

src/parser.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ macro_rules! expect {
360360
($parser: ident, $($branches: tt)+) => {
361361
{
362362
let start_location = $parser.current_source_location();
363-
match *$parser.next()? {
363+
match *$parser.try_next()? {
364364
$($branches)+
365365
ref token => {
366366
return Err(start_location.new_basic_unexpected_token_error(token.clone()))
@@ -401,7 +401,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
401401
#[inline]
402402
pub fn expect_exhausted(&mut self) -> Result<(), BasicParseError<'i>> {
403403
let start = self.state();
404-
let result = match self.next() {
404+
let result = match self.try_next() {
405405
Err(BasicParseError {
406406
kind: BasicParseErrorKind::EndOfInput,
407407
..
@@ -486,7 +486,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
486486
/// Create a new unexpected token or EOF ParseError at the current location
487487
#[inline]
488488
pub fn new_error_for_next_token<E>(&mut self) -> ParseError<'i, E> {
489-
let token = match self.next() {
489+
let token = match self.try_next() {
490490
Ok(token) => token.clone(),
491491
Err(e) => return e.into(),
492492
};
@@ -606,15 +606,15 @@ impl<'i: 't, 't> Parser<'i, 't> {
606606
/// See the `Parser::parse_nested_block` method to parse the content of functions or blocks.
607607
///
608608
/// This only returns a closing token when it is unmatched (and therefore an error).
609-
pub fn next(&mut self) -> Result<&Token<'i>, BasicParseError<'i>> {
609+
pub fn try_next(&mut self) -> Result<&Token<'i>, BasicParseError<'i>> {
610610
self.skip_whitespace();
611-
self.next_including_whitespace_and_comments()
611+
self.try_next_including_whitespace_and_comments()
612612
}
613613

614614
/// Same as `Parser::next`, but does not skip whitespace tokens.
615-
pub fn next_including_whitespace(&mut self) -> Result<&Token<'i>, BasicParseError<'i>> {
615+
pub fn try_next_including_whitespace(&mut self) -> Result<&Token<'i>, BasicParseError<'i>> {
616616
loop {
617-
match self.next_including_whitespace_and_comments() {
617+
match self.try_next_including_whitespace_and_comments() {
618618
Err(e) => return Err(e),
619619
Ok(&Token::Comment(_)) => {}
620620
_ => break,
@@ -629,7 +629,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
629629
/// where comments are preserved.
630630
/// When parsing higher-level values, per the CSS Syntax specification,
631631
/// comments should always be ignored between tokens.
632-
pub fn next_including_whitespace_and_comments(
632+
pub fn try_next_including_whitespace_and_comments(
633633
&mut self,
634634
) -> Result<&Token<'i>, BasicParseError<'i>> {
635635
if let Some(block_type) = self.at_start_of.take() {
@@ -749,7 +749,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
749749
Err(e) if !ignore_errors => return Err(e),
750750
Err(_) => {}
751751
}
752-
match self.next() {
752+
match self.try_next() {
753753
Err(_) => return Ok(values),
754754
Ok(&Token::Comma) => continue,
755755
Ok(_) => unreachable!(),
@@ -817,7 +817,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
817817
#[inline]
818818
pub fn expect_whitespace(&mut self) -> Result<&'i str, BasicParseError<'i>> {
819819
let start_location = self.current_source_location();
820-
match *self.next_including_whitespace()? {
820+
match *self.try_next_including_whitespace()? {
821821
Token::WhiteSpace(value) => Ok(value),
822822
ref t => Err(start_location.new_basic_unexpected_token_error(t.clone())),
823823
}
@@ -1016,7 +1016,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
10161016
#[inline]
10171017
pub fn expect_no_error_token(&mut self) -> Result<(), BasicParseError<'i>> {
10181018
loop {
1019-
match self.next_including_whitespace_and_comments() {
1019+
match self.try_next_including_whitespace_and_comments() {
10201020
Ok(&Token::Function(_))
10211021
| Ok(&Token::ParenthesisBlock)
10221022
| Ok(&Token::SquareBracketBlock)

src/rules_and_declarations.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ where
252252
loop {
253253
self.input.skip_whitespace();
254254
let start = self.input.state();
255-
match self.input.next_including_whitespace_and_comments().ok()? {
255+
match self
256+
.input
257+
.try_next_including_whitespace_and_comments()
258+
.ok()?
259+
{
256260
Token::CloseCurlyBracket
257261
| Token::WhiteSpace(..)
258262
| Token::Semicolon
@@ -366,7 +370,7 @@ where
366370
self.input.skip_cdc_and_cdo();
367371
let start = self.input.state();
368372
let at_keyword = match self.input.next_byte()? {
369-
b'@' => match self.input.next_including_whitespace_and_comments() {
373+
b'@' => match self.input.try_next_including_whitespace_and_comments() {
370374
Ok(Token::AtKeyword(name)) => Some(name.clone()),
371375
_ => {
372376
self.input.reset(&start);
@@ -436,7 +440,7 @@ where
436440
input.skip_whitespace();
437441
let start = input.state();
438442
let at_keyword = if input.next_byte() == Some(b'@') {
439-
match *input.next_including_whitespace_and_comments()? {
443+
match *input.try_next_including_whitespace_and_comments()? {
440444
Token::AtKeyword(ref name) => Some(name.clone()),
441445
_ => {
442446
input.reset(&start);
@@ -468,7 +472,7 @@ where
468472
let result = input.parse_until_before(delimiters, |input| parser.parse_prelude(name, input));
469473
match result {
470474
Ok(prelude) => {
471-
let result = match input.next() {
475+
let result = match input.try_next() {
472476
Ok(&Token::Semicolon) | Err(_) => parser
473477
.rule_without_block(prelude, start)
474478
.map_err(|()| input.new_unexpected_token_error(Token::Semicolon)),
@@ -481,7 +485,7 @@ where
481485
}
482486
Err(error) => {
483487
let end_position = input.position();
484-
match input.next() {
488+
match input.try_next() {
485489
Ok(&Token::CurlyBracketBlock) | Ok(&Token::Semicolon) | Err(_) => {}
486490
_ => unreachable!(),
487491
};

0 commit comments

Comments
 (0)