Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cssparser"
version = "0.19.4"
version = "0.19.5"
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]

description = "Rust implementation of CSS Syntax Level 3"
Expand Down
9 changes: 9 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ impl<'i> ParserInput<'i> {
}
}

/// Create a new input for a parser. Line numbers in locations
/// are offset by the given value.
pub fn new_with_line_number_offset(input: &'i str, first_line_number: u32) -> ParserInput<'i> {
ParserInput {
tokenizer: Tokenizer::with_first_line_number(input, first_line_number),
cached_token: None,
}
}

#[inline]
fn cached_token_ref(&self) -> &Token<'i> {
&self.cached_token.as_ref().unwrap().token
Expand Down
14 changes: 14 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,20 @@ fn parser_maintains_current_line() {
assert_eq!(parser.current_line(), "ident");
}

#[test]
fn parser_with_line_number_offset() {
let mut input = ParserInput::new_with_line_number_offset("ident\nident", 72);
let mut parser = Parser::new(&mut input);
assert_eq!(parser.current_source_location(), SourceLocation { line: 72, column: 0 });
assert_eq!(parser.next_including_whitespace_and_comments(), Ok(&Token::Ident("ident".into())));
assert_eq!(parser.current_source_location(), SourceLocation { line: 72, column: 5 });
assert_eq!(parser.next_including_whitespace_and_comments(),
Ok(&Token::WhiteSpace("\n".into())));
assert_eq!(parser.current_source_location(), SourceLocation { line: 73, column: 0 });
assert_eq!(parser.next_including_whitespace_and_comments(), Ok(&Token::Ident("ident".into())));
assert_eq!(parser.current_source_location(), SourceLocation { line: 73, column: 5 });
}

#[test]
fn cdc_regression_test() {
let mut input = ParserInput::new("-->x");
Expand Down