diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-10-01 14:45:50 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-10-01 14:45:50 +0200 |
commit | 1eb140881b26328ed1b17615fee32427baafadf6 (patch) | |
tree | b1364beef0d67ba33718750c070d351b3a23c3b9 /src/path | |
parent | 6c51d3b6b2dbe49d1b40fd0f0326b73f16357f72 (diff) |
Run cargo-fmt
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/path')
-rw-r--r-- | src/path/mod.rs | 43 | ||||
-rw-r--r-- | src/path/parser.rs | 62 |
2 files changed, 49 insertions, 56 deletions
diff --git a/src/path/mod.rs b/src/path/mod.rs index 3916010..ac28400 100644 --- a/src/path/mod.rs +++ b/src/path/mod.rs @@ -151,34 +151,30 @@ impl Expression { _ => None, }, - Expression::Subscript(ref expr, index) => { - match expr.get_mut_forcibly(root) { - Some(value) => { - match value.kind { - ValueKind::Array(_) => (), - _ => *value = Vec::<Value>::new().into(), - } - - match value.kind { - ValueKind::Array(ref mut array) => { - let index = sindex_to_uindex(index, array.len()); + Expression::Subscript(ref expr, index) => match expr.get_mut_forcibly(root) { + Some(value) => { + match value.kind { + ValueKind::Array(_) => (), + _ => *value = Vec::<Value>::new().into(), + } - if index >= array.len() { - array.resize( - (index + 1) as usize, - Value::new(None, ValueKind::Nil), - ); - } + match value.kind { + ValueKind::Array(ref mut array) => { + let index = sindex_to_uindex(index, array.len()); - Some(&mut array[index]) + if index >= array.len() { + array + .resize((index + 1) as usize, Value::new(None, ValueKind::Nil)); } - _ => None, + Some(&mut array[index]) } + + _ => None, } - _ => None, } - } + _ => None, + }, } } @@ -246,10 +242,7 @@ impl Expression { if let ValueKind::Array(ref mut array) = parent.kind { let uindex = sindex_to_uindex(index, array.len()); if uindex >= array.len() { - array.resize( - (uindex + 1) as usize, - Value::new(None, ValueKind::Nil), - ); + array.resize((uindex + 1) as usize, Value::new(None, ValueKind::Nil)); } array[uindex] = value; diff --git a/src/path/parser.rs b/src/path/parser.rs index d783f3e..7a40cb5 100644 --- a/src/path/parser.rs +++ b/src/path/parser.rs @@ -1,49 +1,49 @@ use super::Expression; use nom::{ - IResult, Err, - error::ErrorKind, - bytes::complete::{is_a, tag}, - character::complete::{char, digit1, space0}, - sequence::{delimited, pair, preceded}, - branch::alt, - combinator::{map, map_res, opt, recognize}, + branch::alt, + bytes::complete::{is_a, tag}, + character::complete::{char, digit1, space0}, + combinator::{map, map_res, opt, recognize}, + error::ErrorKind, + sequence::{delimited, pair, preceded}, + Err, IResult, }; use std::str::{from_utf8, FromStr}; fn raw_ident(i: &str) -> IResult<&str, String> { - map(is_a( - "abcdefghijklmnopqrstuvwxyz \ + map( + is_a( + "abcdefghijklmnopqrstuvwxyz \ ABCDEFGHIJKLMNOPQRSTUVWXYZ \ 0123456789 \ - _-" - ), |s:&str| s.to_string())(i) + _-", + ), + |s: &str| s.to_string(), + )(i) } fn integer(i: &str) -> IResult<&str, isize> { - map_res( - delimited( - space0, - recognize(pair(opt(tag("-")), digit1)), - space0 - ), - FromStr::from_str - )(i) + map_res( + delimited(space0, recognize(pair(opt(tag("-")), digit1)), space0), + FromStr::from_str, + )(i) } fn ident(i: &str) -> IResult<&str, Expression> { - map(raw_ident, Expression::Identifier)(i) + map(raw_ident, Expression::Identifier)(i) } fn postfix<'a>(expr: Expression) -> impl Fn(&'a str) -> IResult<&'a str, Expression> { - let e2 = expr.clone(); - let child = map(preceded(tag("."), raw_ident), move |id| Expression::Child(Box::new(expr.clone()), id)); + let e2 = expr.clone(); + let child = map(preceded(tag("."), raw_ident), move |id| { + Expression::Child(Box::new(expr.clone()), id) + }); - let subscript = map(delimited(char('['), integer, char(']')), move |num| Expression::Subscript(Box::new(e2.clone()), num)); + let subscript = map(delimited(char('['), integer, char(']')), move |num| { + Expression::Subscript(Box::new(e2.clone()), num) + }); - alt(( - child, - subscript - )) + alt((child, subscript)) } pub fn from_str(input: &str) -> Result<Expression, ErrorKind> { @@ -72,10 +72,10 @@ pub fn from_str(input: &str) -> Result<Expression, ErrorKind> { } pub fn to_error_kind(e: Err<(&str, ErrorKind)>) -> ErrorKind { - match e { - Err::Incomplete(_) => ErrorKind::Complete, - Err::Failure((_, e)) | Err::Error((_, e)) => e, - } + match e { + Err::Incomplete(_) => ErrorKind::Complete, + Err::Failure((_, e)) | Err::Error((_, e)) => e, + } } #[cfg(test)] |