changeset 18:d9f4c7963c9f

rustfmt
author Lewin Bormann <lewin@lewin-bormann.info>
date Mon, 03 Jun 2019 23:51:52 +0200
parents 0427da45a728
children 8920f09345d5
files src/combinators.rs src/parser.rs src/primitives.rs
diffstat 3 files changed, 29 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/combinators.rs	Mon Jun 03 23:51:32 2019 +0200
+++ b/src/combinators.rs	Mon Jun 03 23:51:52 2019 +0200
@@ -306,7 +306,7 @@
 /// parsing if an optional input was not encountered. It is very similar to a `Repeat` parser with
 /// `RepeatSpec::Max(1)`.
 pub struct Maybe<Inner: Parser> {
-    inner: Inner
+    inner: Inner,
 }
 
 impl<Inner: Parser> Maybe<Inner> {
@@ -315,9 +315,12 @@
     }
 }
 
-impl<R, P: Parser<Result=R>> Parser for Maybe<P> {
+impl<R, P: Parser<Result = R>> Parser for Maybe<P> {
     type Result = Option<R>;
-    fn parse(&mut self, st: &mut ParseState<impl Iterator<Item=char>>) -> ParseResult<Self::Result> {
+    fn parse(
+        &mut self,
+        st: &mut ParseState<impl Iterator<Item = char>>,
+    ) -> ParseResult<Self::Result> {
         match self.inner.parse(st) {
             Ok(r) => Ok(Some(r)),
             Err(_) => Ok(None),
@@ -325,7 +328,6 @@
     }
 }
 
-
 #[cfg(test)]
 mod tests {
     use super::*;
@@ -377,7 +379,8 @@
 
     #[test]
     fn test_partial_sequence() {
-        let mut p = PartialSequence::new((StringParser::new("a"), StringParser::new("c"), Int64::new()));
+        let mut p =
+            PartialSequence::new((StringParser::new("a"), StringParser::new("c"), Int64::new()));
         let mut ps = ParseState::new("acde");
         assert_eq!(
             Ok((Some("a".to_string()), Some("c".to_string()), None)),
--- a/src/parser.rs	Mon Jun 03 23:51:32 2019 +0200
+++ b/src/parser.rs	Mon Jun 03 23:51:52 2019 +0200
@@ -29,9 +29,7 @@
             ParseError::TransformFail(s, pos, inner) => {
                 write!(f, "Transform fail: {} at {} due to ", s, pos).and_then(|()| inner.fmt(f))
             }
-            ParseError::ExecFail(s) => {
-                write!(f, "Logic error: {}", s)
-            }
+            ParseError::ExecFail(s) => write!(f, "Logic error: {}", s),
         }
     }
 }
--- a/src/primitives.rs	Mon Jun 03 23:51:32 2019 +0200
+++ b/src/primitives.rs	Mon Jun 03 23:51:52 2019 +0200
@@ -145,7 +145,12 @@
     }
 }
 
-fn assemble_float(s: Option<String>, big: String, dot: Option<String>, mut little: Option<String>) -> ParseResult<f64> {
+fn assemble_float(
+    s: Option<String>,
+    big: String,
+    dot: Option<String>,
+    mut little: Option<String>,
+) -> ParseResult<f64> {
     if dot.is_some() && little.is_none() {
         little = Some("0".to_string());
     }
@@ -162,24 +167,21 @@
             Err(e) => return Err(execerr(e.description())),
         }
     }
-    let minus = if s.is_some() {
-        -1.
-    } else {
-        1.
-    };
-    return Ok(minus * (bigf + littlef))
+    let minus = if s.is_some() { -1. } else { 1. };
+    return Ok(minus * (bigf + littlef));
 }
 
 /// float parses floats in the format of `[-]dd[.[dd]]`. Currently, `e` notation is not supported.
 ///
 /// TODO: Compare with "native" parser, i.e. without combinators, and keep this as example.
-pub fn float() -> impl Parser<Result=f64> {
-        let minus = Maybe::new(StringParser::new("-"));
-        let digits = string_of("0123456789", RepeatSpec::Min(1));
-        let point = Maybe::new(StringParser::new("."));
-        let smalldigits = Maybe::new(string_of("0123456789", RepeatSpec::Min(1)));
-        let parser = Sequence::new((minus, digits, point, smalldigits)).apply(|(m,d,p,sd)| assemble_float(m, d, p, sd));
-        parser
+pub fn float() -> impl Parser<Result = f64> {
+    let minus = Maybe::new(StringParser::new("-"));
+    let digits = string_of("0123456789", RepeatSpec::Min(1));
+    let point = Maybe::new(StringParser::new("."));
+    let smalldigits = Maybe::new(string_of("0123456789", RepeatSpec::Min(1)));
+    let parser = Sequence::new((minus, digits, point, smalldigits))
+        .apply(|(m, d, p, sd)| assemble_float(m, d, p, sd));
+    parser
 }
 
 /// Nothing is a parser that always succeeds.
@@ -187,7 +189,10 @@
 
 impl Parser for Nothing {
     type Result = ();
-    fn parse(&mut self, _: &mut ParseState<impl Iterator<Item=char>>) -> ParseResult<Self::Result> {
+    fn parse(
+        &mut self,
+        _: &mut ParseState<impl Iterator<Item = char>>,
+    ) -> ParseResult<Self::Result> {
         Ok(())
     }
 }