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,22 +428,21 @@ impl<'a> Parser<'a> {
}
return Ok(())
}
c => {
if self.peek_is(1, '-') && !self.peek_is(2, ']') {
try!(self.expect('-'))
try!(self.noteof("not a ']'"))
let c2 = self.cur();
if c2 < c {
return self.err(format!("Invalid character class \
range '{}-{}'",
c,
c2).as_slice())
}
ranges.push((c, self.cur()))
} else {
ranges.push((c, c))
}
}
if self.peek_is(1, '-') && !self.peek_is(2, ']') {
try!(self.expect('-'))
try!(self.noteof("not a ']'"))
let c2 = self.cur();
if c2 < c {
return self.err(format!("Invalid character class \
range '{}-{}'",
c,
c2).as_slice())
}
ranges.push((c, self.cur()))
} else {
ranges.push((c, c))
}
}
}