Skip to content

Commit

Permalink
style: start using rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Aug 3, 2019
1 parent 6bffb75 commit 23f7f59
Show file tree
Hide file tree
Showing 28 changed files with 32,931 additions and 11,708 deletions.
3 changes: 2 additions & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ fn parse_medium2(b: &mut Bencher) {
#[bench]
fn parse_medium3(b: &mut Bencher) {
b.iter(|| {
let re = r"\p{age:3.2}\p{hira}\p{scx:hira}\p{alphabetic}\p{sc:Greek}\pL";
let re =
r"\p{age:3.2}\p{hira}\p{scx:hira}\p{alphabetic}\p{sc:Greek}\pL";
Parser::new().parse(re).unwrap()
});
}
Expand Down
191 changes: 85 additions & 106 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::cmp::Ordering;
use std::error;
use std::fmt;

pub use ast::visitor::{Visitor, visit};
pub use ast::visitor::{visit, Visitor};

pub mod parse;
pub mod print;
Expand Down Expand Up @@ -202,11 +202,11 @@ impl error::Error for Error {
EscapeUnexpectedEof => "unexpected eof (escape sequence)",
EscapeUnrecognized => "unrecognized escape sequence",
FlagDanglingNegation => "dangling flag negation operator",
FlagDuplicate{..} => "duplicate flag",
FlagRepeatedNegation{..} => "repeated negation",
FlagDuplicate { .. } => "duplicate flag",
FlagRepeatedNegation { .. } => "repeated negation",
FlagUnexpectedEof => "unexpected eof (flag)",
FlagUnrecognized => "unrecognized flag",
GroupNameDuplicate{..} => "duplicate capture group name",
GroupNameDuplicate { .. } => "duplicate capture group name",
GroupNameEmpty => "empty capture group name",
GroupNameInvalid => "invalid capture group name",
GroupNameUnexpectedEof => "unclosed capture group name",
Expand All @@ -233,86 +233,67 @@ impl fmt::Display for ErrorKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::ErrorKind::*;
match *self {
CaptureLimitExceeded => {
write!(f, "exceeded the maximum number of \
capturing groups ({})", ::std::u32::MAX)
}
CaptureLimitExceeded => write!(
f,
"exceeded the maximum number of \
capturing groups ({})",
::std::u32::MAX
),
ClassEscapeInvalid => {
write!(f, "invalid escape sequence found in character class")
}
ClassRangeInvalid => {
write!(f, "invalid character class range, \
the start must be <= the end")
}
ClassRangeInvalid => write!(
f,
"invalid character class range, \
the start must be <= the end"
),
ClassRangeLiteral => {
write!(f, "invalid range boundary, must be a literal")
}
ClassUnclosed => {
write!(f, "unclosed character class")
}
DecimalEmpty => {
write!(f, "decimal literal empty")
}
DecimalInvalid => {
write!(f, "decimal literal invalid")
}
EscapeHexEmpty => {
write!(f, "hexadecimal literal empty")
}
ClassUnclosed => write!(f, "unclosed character class"),
DecimalEmpty => write!(f, "decimal literal empty"),
DecimalInvalid => write!(f, "decimal literal invalid"),
EscapeHexEmpty => write!(f, "hexadecimal literal empty"),
EscapeHexInvalid => {
write!(f, "hexadecimal literal is not a Unicode scalar value")
}
EscapeHexInvalidDigit => {
write!(f, "invalid hexadecimal digit")
}
EscapeUnexpectedEof => {
write!(f, "incomplete escape sequence, \
reached end of pattern prematurely")
}
EscapeUnrecognized => {
write!(f, "unrecognized escape sequence")
}
EscapeHexInvalidDigit => write!(f, "invalid hexadecimal digit"),
EscapeUnexpectedEof => write!(
f,
"incomplete escape sequence, \
reached end of pattern prematurely"
),
EscapeUnrecognized => write!(f, "unrecognized escape sequence"),
FlagDanglingNegation => {
write!(f, "dangling flag negation operator")
}
FlagDuplicate{..} => {
write!(f, "duplicate flag")
}
FlagRepeatedNegation{..} => {
FlagDuplicate { .. } => write!(f, "duplicate flag"),
FlagRepeatedNegation { .. } => {
write!(f, "flag negation operator repeated")
}
FlagUnexpectedEof => {
write!(f, "expected flag but got end of regex")
}
FlagUnrecognized => {
write!(f, "unrecognized flag")
}
GroupNameDuplicate{..} => {
FlagUnrecognized => write!(f, "unrecognized flag"),
GroupNameDuplicate { .. } => {
write!(f, "duplicate capture group name")
}
GroupNameEmpty => {
write!(f, "empty capture group name")
}
GroupNameInvalid => {
write!(f, "invalid capture group character")
}
GroupNameUnexpectedEof => {
write!(f, "unclosed capture group name")
}
GroupUnclosed => {
write!(f, "unclosed group")
}
GroupUnopened => {
write!(f, "unopened group")
}
NestLimitExceeded(limit) => {
write!(f, "exceed the maximum number of \
nested parentheses/brackets ({})", limit)
}
RepetitionCountInvalid => {
write!(f, "invalid repetition count range, \
the start must be <= the end")
}
GroupNameEmpty => write!(f, "empty capture group name"),
GroupNameInvalid => write!(f, "invalid capture group character"),
GroupNameUnexpectedEof => write!(f, "unclosed capture group name"),
GroupUnclosed => write!(f, "unclosed group"),
GroupUnopened => write!(f, "unopened group"),
NestLimitExceeded(limit) => write!(
f,
"exceed the maximum number of \
nested parentheses/brackets ({})",
limit
),
RepetitionCountInvalid => write!(
f,
"invalid repetition count range, \
the start must be <= the end"
),
RepetitionCountDecimalEmpty => {
write!(f, "repetition quantifier expects a valid decimal")
}
Expand All @@ -325,10 +306,11 @@ impl fmt::Display for ErrorKind {
UnsupportedBackreference => {
write!(f, "backreferences are not supported")
}
UnsupportedLookAround => {
write!(f, "look-around, including look-ahead and look-behind, \
is not supported")
}
UnsupportedLookAround => write!(
f,
"look-around, including look-ahead and look-behind, \
is not supported"
),
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -384,7 +366,8 @@ impl fmt::Debug for Position {
write!(
f,
"Position(o: {:?}, l: {:?}, c: {:?})",
self.offset, self.line, self.column)
self.offset, self.line, self.column
)
}
}

Expand Down Expand Up @@ -868,7 +851,8 @@ impl ClassUnicode {
pub fn is_negated(&self) -> bool {
match self.kind {
ClassUnicodeKind::NamedValue {
op: ClassUnicodeOpKind::NotEqual, ..
op: ClassUnicodeOpKind::NotEqual,
..
} => !self.negated,
_ => self.negated,
}
Expand Down Expand Up @@ -910,7 +894,7 @@ impl ClassUnicodeOpKind {
/// Whether the op is an equality op or not.
pub fn is_equal(&self) -> bool {
match *self {
ClassUnicodeOpKind::Equal|ClassUnicodeOpKind::Colon => true,
ClassUnicodeOpKind::Equal | ClassUnicodeOpKind::Colon => true,
_ => false,
}
}
Expand Down Expand Up @@ -1428,26 +1412,24 @@ impl Drop for ClassSet {
use std::mem;

match *self {
ClassSet::Item(ref item) => {
match *item {
ClassSetItem::Empty(_)
| ClassSetItem::Literal(_)
| ClassSetItem::Range(_)
| ClassSetItem::Ascii(_)
| ClassSetItem::Unicode(_)
| ClassSetItem::Perl(_) => return,
ClassSetItem::Bracketed(ref x) => {
if x.kind.is_empty() {
return;
}
ClassSet::Item(ref item) => match *item {
ClassSetItem::Empty(_)
| ClassSetItem::Literal(_)
| ClassSetItem::Range(_)
| ClassSetItem::Ascii(_)
| ClassSetItem::Unicode(_)
| ClassSetItem::Perl(_) => return,
ClassSetItem::Bracketed(ref x) => {
if x.kind.is_empty() {
return;
}
ClassSetItem::Union(ref x) => {
if x.items.is_empty() {
return;
}
}
ClassSetItem::Union(ref x) => {
if x.items.is_empty() {
return;
}
}
}
},
ClassSet::BinaryOp(ref op) => {
if op.lhs.is_empty() && op.rhs.is_empty() {
return;
Expand All @@ -1460,23 +1442,20 @@ impl Drop for ClassSet {
let mut stack = vec![mem::replace(self, empty_set())];
while let Some(mut set) = stack.pop() {
match set {
ClassSet::Item(ref mut item) => {
match *item {
ClassSetItem::Empty(_)
| ClassSetItem::Literal(_)
| ClassSetItem::Range(_)
| ClassSetItem::Ascii(_)
| ClassSetItem::Unicode(_)
| ClassSetItem::Perl(_) => {}
ClassSetItem::Bracketed(ref mut x) => {
stack.push(mem::replace(&mut x.kind, empty_set()));
}
ClassSetItem::Union(ref mut x) => {
stack.extend(
x.items.drain(..).map(ClassSet::Item));
}
ClassSet::Item(ref mut item) => match *item {
ClassSetItem::Empty(_)
| ClassSetItem::Literal(_)
| ClassSetItem::Range(_)
| ClassSetItem::Ascii(_)
| ClassSetItem::Unicode(_)
| ClassSetItem::Perl(_) => {}
ClassSetItem::Bracketed(ref mut x) => {
stack.push(mem::replace(&mut x.kind, empty_set()));
}
}
ClassSetItem::Union(ref mut x) => {
stack.extend(x.items.drain(..).map(ClassSet::Item));
}
},
ClassSet::BinaryOp(ref mut op) => {
stack.push(mem::replace(&mut op.lhs, empty_set()));
stack.push(mem::replace(&mut op.rhs, empty_set()));
Expand Down Expand Up @@ -1515,7 +1494,7 @@ mod tests {
// We run our test on a thread with a small stack size so we can
// force the issue more easily.
thread::Builder::new()
.stack_size(1<<10)
.stack_size(1 << 10)
.spawn(run)
.unwrap()
.join()
Expand Down
Loading

0 comments on commit 23f7f59

Please sign in to comment.