Skip to content

Commit 218d737

Browse files
author
bors-servo
authored
Auto merge of servo#235 - servo:new_error_for_next_token, r=SimonSapin
Add Parser::new_error_for_next_token <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/235) <!-- Reviewable:end -->
2 parents f81283a + 3d7aa4b commit 218d737

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
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.25.1"
3+
version = "0.25.2"
44
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]
55

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

src/parser.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,16 @@ impl<'i: 't, 't> Parser<'i, 't> {
421421
self.new_error(BasicParseErrorKind::UnexpectedToken(token))
422422
}
423423

424+
/// Create a new unexpected token or EOF ParseError at the current location
425+
#[inline]
426+
pub fn new_error_for_next_token<E>(&mut self) -> ParseError<'i, E> {
427+
let token = match self.next() {
428+
Ok(token) => token.clone(),
429+
Err(e) => return e.into()
430+
};
431+
self.new_error(BasicParseErrorKind::UnexpectedToken(token))
432+
}
433+
424434
/// Return the current internal state of the parser (including position within the input).
425435
///
426436
/// This state can later be restored with the `Parser::reset` method.

0 commit comments

Comments
 (0)