Re-structure control flow a bit + modernization

This commit is contained in:
Alex Crichton 2015-06-07 22:38:36 -07:00
parent 8487b63c97
commit 6580b77a20

View file

@ -254,9 +254,8 @@ impl<'a> Parser<'a> {
let mut keys = Vec::new();
loop {
self.ws();
match self.key_name() {
Some(s) => keys.push(s),
None => {}
if let Some(s) = self.key_name() {
keys.push(s);
}
self.ws();
if self.eat(']') {
@ -293,9 +292,7 @@ impl<'a> Parser<'a> {
self.finish_string(start, false)
} else {
let mut ret = String::new();
loop {
match self.cur.clone().next() {
Some((_, ch)) => {
while let Some((_, ch)) = self.cur.clone().next() {
match ch {
'a' ... 'z' |
'A' ... 'Z' |
@ -304,9 +301,6 @@ impl<'a> Parser<'a> {
_ => break,
}
}
None => break
}
}
Some(ret)
};
match key {
@ -423,9 +417,8 @@ impl<'a> Parser<'a> {
return Some(ret)
}
Some((pos, '\\')) => {
match escape(self, pos, multiline) {
Some(c) => ret.push(c),
None => {}
if let Some(c) = escape(self, pos, multiline) {
ret.push(c);
}
}
Some((pos, ch)) if ch < '\u{1f}' => {
@ -470,14 +463,11 @@ impl<'a> Parser<'a> {
} else {
"invalid"
};
match u32::from_str_radix(num, 16).ok() {
Some(n) => {
match char::from_u32(n) {
Some(c) => {
if let Some(n) = u32::from_str_radix(num, 16).ok() {
if let Some(c) = char::from_u32(n) {
me.cur.by_ref().skip(len - 1).next();
return Some(c)
}
None => {
} else {
me.errors.push(ParserError {
lo: pos + 1,
hi: pos + 5,
@ -486,9 +476,7 @@ impl<'a> Parser<'a> {
codepoint", n),
})
}
}
}
None => {
} else {
me.errors.push(ParserError {
lo: pos,
hi: pos + 1,
@ -496,7 +484,6 @@ impl<'a> Parser<'a> {
after a `{}` escape", len, c),
})
}
}
None
}
Some((pos, ch)) => {
@ -832,10 +819,7 @@ impl<'a> Parser<'a> {
if tmp.0.contains_key(part) {
match *tmp.0.get_mut(part).unwrap() {
Value::Table(ref mut table) => {
cur = table;
continue
}
Value::Table(ref mut table) => cur = table,
Value::Array(ref mut array) => {
match array.last_mut() {
Some(&mut Value::Table(ref mut table)) => cur = table,
@ -849,7 +833,6 @@ impl<'a> Parser<'a> {
return None
}
}
continue
}
_ => {
self.errors.push(ParserError {
@ -861,6 +844,7 @@ impl<'a> Parser<'a> {
return None
}
}
continue
}
// Initialize an empty table as part of this sub-key
@ -922,11 +906,10 @@ impl<'a> Parser<'a> {
Some(pair) => pair,
None => return,
};
let key = format!("{}", key);
if !into.0.contains_key(&key) {
into.0.insert(key.clone(), Value::Array(Vec::new()));
if !into.0.contains_key(key) {
into.0.insert(key.to_owned(), Value::Array(Vec::new()));
}
match *into.0.get_mut(&key).unwrap() {
match *into.0.get_mut(key).unwrap() {
Value::Array(ref mut vec) => {
match vec.first() {
Some(ref v) if !v.same_type(&value) => {