Skip to content

Commit 29f757d

Browse files
committed
WIP
1 parent 3fbebc6 commit 29f757d

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

src/parser.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'i, 't> Parser<'i, 't> {
331331
/// This can help tell e.g. `color: green;` from `color: green 4px;`
332332
#[inline]
333333
pub fn parse_entirely<F, T>(&mut self, parse: F) -> Result<T, ()>
334-
where F: FnOnce(&mut Parser) -> Result<T, ()> {
334+
where F: FnOnce(&mut Parser<'i, 't>) -> Result<T, ()> {
335335
let result = parse(self);
336336
try!(self.expect_exhausted());
337337
result
@@ -374,7 +374,9 @@ impl<'i, 't> Parser<'i, 't> {
374374
/// The result is overridden to `Err(())` if the closure leaves some input before that point.
375375
#[inline]
376376
pub fn parse_nested_block<F, T>(&mut self, parse: F) -> Result <T, ()>
377-
where F: FnOnce(&mut Parser) -> Result<T, ()> {
377+
where for<'tt> F: FnOnce(&mut Parser<'i, 'tt>) -> Result<T, ()> {
378+
// where 'tt: 't, F: FnOnce(&mut Parser<'i, 'tt>) -> Result<T, ()> {
379+
// where F: FnOnce(&mut Parser) -> Result<T, ()> {
378380
let block_type = self.at_start_of.take().expect("\
379381
A nested parser can only be created when a Function, \
380382
ParenthesisBlock, SquareBracketBlock, or CurlyBracketBlock \
@@ -412,7 +414,7 @@ impl<'i, 't> Parser<'i, 't> {
412414
#[inline]
413415
pub fn parse_until_before<F, T>(&mut self, delimiters: Delimiters, parse: F)
414416
-> Result <T, ()>
415-
where F: FnOnce(&mut Parser) -> Result<T, ()> {
417+
where for<'tt> F: FnOnce(&mut Parser<'i, 'tt>) -> Result<T, ()> {
416418
let delimiters = self.stop_before | delimiters;
417419
let result;
418420
// Introduce a new scope to limit duration of nested_parser’s borrow
@@ -451,7 +453,7 @@ impl<'i, 't> Parser<'i, 't> {
451453
#[inline]
452454
pub fn parse_until_after<F, T>(&mut self, delimiters: Delimiters, parse: F)
453455
-> Result <T, ()>
454-
where F: FnOnce(&mut Parser) -> Result<T, ()> {
456+
where for<'tt> F: FnOnce(&mut Parser<'i, 'tt>) -> Result<T, ()> {
455457
let result = self.parse_until_before(delimiters, parse);
456458
let next_byte = self.tokenizer.next_byte();
457459
if next_byte.is_some() && !self.stop_before.contains(Delimiters::from_byte(next_byte)) {
@@ -481,7 +483,7 @@ impl<'i, 't> Parser<'i, 't> {
481483

482484
/// Parse a <ident-token> whose unescaped value is an ASCII-insensitive match for the given value.
483485
#[inline]
484-
pub fn expect_ident_matching<'a>(&mut self, expected_value: &str) -> Result<(), ()> {
486+
pub fn expect_ident_matching(&mut self, expected_value: &str) -> Result<(), ()> {
485487
match try!(self.next()) {
486488
Token::Ident(ref value) if value.eq_ignore_ascii_case(expected_value) => Ok(()),
487489
_ => Err(())
@@ -512,9 +514,9 @@ impl<'i, 't> Parser<'i, 't> {
512514
pub fn expect_url(&mut self) -> Result<Cow<'i, str>, ()> {
513515
match try!(self.next()) {
514516
Token::UnquotedUrl(value) => Ok(value),
515-
Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {
516-
self.parse_nested_block(|input| input.expect_string())
517-
},
517+
// Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {
518+
// self.parse_nested_block(|input| input.expect_string())
519+
// },
518520
_ => Err(())
519521
}
520522
}
@@ -525,9 +527,9 @@ impl<'i, 't> Parser<'i, 't> {
525527
match try!(self.next()) {
526528
Token::UnquotedUrl(value) => Ok(value),
527529
Token::QuotedString(value) => Ok(value),
528-
Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {
529-
self.parse_nested_block(|input| input.expect_string())
530-
},
530+
// Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {
531+
// self.parse_nested_block(|input| input.expect_string())
532+
// },
531533
_ => Err(())
532534
}
533535
}

src/tests.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use std::borrow::Cow::Borrowed;
5+
use std::borrow::Cow::{self, Borrowed};
66
use std::fs::File;
77
use std::io::{self, Write};
88
use std::path::Path;
@@ -247,11 +247,16 @@ fn expect_no_error_token() {
247247
/// https://github.com/servo/rust-cssparser/issues/71
248248
#[test]
249249
fn outer_block_end_consumed() {
250-
let mut input = Parser::new("(calc(true))");
251-
assert!(input.expect_parenthesis_block().is_ok());
252-
assert!(input.parse_nested_block(|input| input.expect_function_matching("calc")).is_ok());
253-
println!("{:?}", input.position());
254-
assert_eq!(input.next(), Err(()));
250+
Parser::new("").parse_nested_block(|input| input.expect_exhausted());
251+
252+
253+
// let mut input = Parser::new("(calc(true))");
254+
// assert!(input.expect_parenthesis_block().is_ok());
255+
// let r =
256+
// input.parse_nested_block(|input| input.expect_function_matching("calc"));
257+
// assert!(r.is_ok());
258+
// println!("{:?}", input.position());
259+
// assert_eq!(input.next(), Err(()));
255260
}
256261

257262
#[test]
@@ -274,6 +279,14 @@ fn unquoted_url_escaping() {
274279
assert_eq!(Parser::new(&serialized).next(), Ok(token))
275280
}
276281

282+
#[test]
283+
fn test_expect_url() {
284+
fn parse(s: &str) -> Result<Cow<str>, ()> {
285+
Parser::new(s).expect_url()
286+
}
287+
assert_eq!(parse("url()").unwrap(), "");
288+
}
289+
277290

278291
fn run_color_tests<F: Fn(Result<Color, ()>) -> Json>(json_data: &str, to_json: F) {
279292
run_json_tests(json_data, |input| {

0 commit comments

Comments
 (0)