regex: Fix control flow in the parser

This commit is contained in:
Piotr Czarnecki
2014-10-24 14:28:10 +01:00
parent 00cc6d2409
commit e2e47d6eb5
2 changed files with 24 additions and 18 deletions

View File

@@ -411,9 +411,6 @@ impl<'a> Parser<'a> {
ast => fail!("Unexpected AST item '{}'", ast),
}
}
_ => {},
}
match c {
']' => {
if ranges.len() > 0 {
let flags = negated | (self.flags & FLAG_NOCASE);
@@ -431,7 +428,8 @@ impl<'a> Parser<'a> {
}
return Ok(())
}
c => {
}
if self.peek_is(1, '-') && !self.peek_is(2, ']') {
try!(self.expect('-'))
try!(self.noteof("not a ']'"))
@@ -448,8 +446,6 @@ impl<'a> Parser<'a> {
}
}
}
}
}
// Tries to parse an ASCII character class of the form [:name:].
// If successful, returns an AST character class corresponding to name

View File

@@ -43,6 +43,16 @@ fn empty_regex_nonempty_match() {
assert_eq!(ms, vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
}
#[test]
fn quoted_bracket_set() {
let re = regex!(r"([\x{5b}\x{5d}])");
let ms = re.find_iter("[]").collect::<Vec<(uint, uint)>>();
assert_eq!(ms, vec![(0, 1), (1, 2)]);
let re = regex!(r"([\[\]])");
let ms = re.find_iter("[]").collect::<Vec<(uint, uint)>>();
assert_eq!(ms, vec![(0, 1), (1, 2)]);
}
macro_rules! replace(
($name:ident, $which:ident, $re:expr,
$search:expr, $replace:expr, $result:expr) => (