Skip to content

Fix macro expansions #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2014
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
26 changes: 13 additions & 13 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ impl<'a> Parser<'a> {
},
'(' => {
if self.peek_is(1, '?') {
try!(self.expect('?'))
try!(self.parse_group_opts())
try!(self.expect('?'));
try!(self.parse_group_opts());
} else {
self.caps += 1;
self.stack.push(Paren(self.flags,
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<'a> Parser<'a> {
fn parse_class(&mut self) -> Result<(), Error> {
let negated =
if self.peek_is(1, '^') {
try!(self.expect('^'))
try!(self.expect('^'));
FLAG_NEGATED
} else {
FLAG_EMPTY
Expand Down Expand Up @@ -597,7 +597,7 @@ impl<'a> Parser<'a> {
// Parses all escape sequences.
// Assumes that '\' is the current character.
fn parse_escape(&mut self) -> Result<Ast, Error> {
try!(self.noteof("an escape sequence following a '\\'"))
try!(self.noteof("an escape sequence following a '\\'"));

let c = self.cur();
if is_punct(c) {
Expand Down Expand Up @@ -639,7 +639,7 @@ impl<'a> Parser<'a> {
let negated = if self.cur() == 'P' { FLAG_NEGATED } else { FLAG_EMPTY };
let mut name: String;
if self.peek_is(1, '{') {
try!(self.expect('{'))
try!(self.expect('{'));
let closer =
match self.pos('}') {
Some(i) => i,
Expand Down Expand Up @@ -677,10 +677,10 @@ impl<'a> Parser<'a> {
let mut end = start + 1;
let (d2, d3) = (self.peek(1), self.peek(2));
if d2 >= Some('0') && d2 <= Some('7') {
try!(self.noteof("expected octal character in [0-7]"))
try!(self.noteof("expected octal character in [0-7]"));
end += 1;
if d3 >= Some('0') && d3 <= Some('7') {
try!(self.noteof("expected octal character in [0-7]"))
try!(self.noteof("expected octal character in [0-7]"));
end += 1;
}
}
Expand All @@ -698,7 +698,7 @@ impl<'a> Parser<'a> {
// Assumes that \x has been read.
fn parse_hex(&mut self) -> Result<Ast, Error> {
if !self.peek_is(1, '{') {
try!(self.expect('{'))
try!(self.expect('{'));
return self.parse_hex_two()
}
let start = self.chari + 2;
Expand All @@ -723,7 +723,7 @@ impl<'a> Parser<'a> {
let (start, end) = (self.chari, self.chari + 2);
let bad = self.slice(start - 2, self.chars.len());
try!(self.noteof(format!("Invalid hex escape sequence '{}'",
bad).as_slice()))
bad).as_slice()));
self.parse_hex_digits(self.slice(start, end).as_slice())
}

Expand All @@ -743,7 +743,7 @@ impl<'a> Parser<'a> {
// is '<'.
// When done, parser will be at the closing '>' character.
fn parse_named_capture(&mut self) -> Result<(), Error> {
try!(self.noteof("a capture name"))
try!(self.noteof("a capture name"));
let closer =
match self.pos('>') {
Some(i) => i,
Expand Down Expand Up @@ -773,15 +773,15 @@ impl<'a> Parser<'a> {
// character.
fn parse_group_opts(&mut self) -> Result<(), Error> {
if self.peek_is(1, 'P') && self.peek_is(2, '<') {
try!(self.expect('P')) try!(self.expect('<'))
try!(self.expect('P')); try!(self.expect('<'));
return self.parse_named_capture()
}
let start = self.chari;
let mut flags = self.flags;
let mut sign = 1i;
let mut saw_flag = false;
loop {
try!(self.noteof("expected non-empty set of flags or closing ')'"))
try!(self.noteof("expected non-empty set of flags or closing ')'"));
match self.cur() {
'i' => { flags = flags | FLAG_NOCASE; saw_flag = true},
'm' => { flags = flags | FLAG_MULTI; saw_flag = true},
Expand Down Expand Up @@ -823,7 +823,7 @@ impl<'a> Parser<'a> {
// If it is, then the next character is consumed.
fn get_next_greedy(&mut self) -> Result<Greed, Error> {
Ok(if self.peek_is(1, '?') {
try!(self.expect('?'))
try!(self.expect('?'));
Ungreedy
} else {
Greedy
Expand Down
26 changes: 13 additions & 13 deletions tests/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ macro_rules! throughput(
b.iter(|| if $regex.is_match(text.as_slice()) { panic!("match") });
}
);
)
);

fn easy0() -> Regex { regex!("ABCDEFGHIJKLMNOPQRSTUVWXYZ$") }
fn easy1() -> Regex { regex!("A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$") }
Expand All @@ -165,18 +165,18 @@ fn gen_text(n: uint) -> String {
String::from_utf8(bytes).unwrap()
}

throughput!(easy0_32, easy0(), 32)
throughput!(easy0_1K, easy0(), 1<<10)
throughput!(easy0_32K, easy0(), 32<<10)
throughput!(easy0_32, easy0(), 32);
throughput!(easy0_1K, easy0(), 1<<10);
throughput!(easy0_32K, easy0(), 32<<10);

throughput!(easy1_32, easy1(), 32)
throughput!(easy1_1K, easy1(), 1<<10)
throughput!(easy1_32K, easy1(), 32<<10)
throughput!(easy1_32, easy1(), 32);
throughput!(easy1_1K, easy1(), 1<<10);
throughput!(easy1_32K, easy1(), 32<<10);

throughput!(medium_32, medium(), 32)
throughput!(medium_1K, medium(), 1<<10)
throughput!(medium_32K,medium(), 32<<10)
throughput!(medium_32, medium(), 32);
throughput!(medium_1K, medium(), 1<<10);
throughput!(medium_32K,medium(), 32<<10);

throughput!(hard_32, hard(), 32)
throughput!(hard_1K, hard(), 1<<10)
throughput!(hard_32K,hard(), 32<<10)
throughput!(hard_32, hard(), 32);
throughput!(hard_1K, hard(), 1<<10);
throughput!(hard_32K,hard(), 32<<10);
Loading