summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@gmail.com>2020-12-26 00:41:25 -0800
committerIrene Knapp <ireneista@gmail.com>2020-12-26 00:41:25 -0800
commit0448d438d13d1486fdbc678e54685e5c9b5a12b8 (patch)
tree8f886c884b8a82a94f965e61566040823c6b6f3b
parentda5655f12b0ea1a7d7fb2b56a8128d5962450c15 (diff)
fix indentation to 2 spaces
-rw-r--r--src/error.rs68
-rw-r--r--src/main.rs87
2 files changed, 77 insertions, 78 deletions
diff --git a/src/error.rs b/src/error.rs
index adb19bc..8e51880 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -2,54 +2,54 @@ use crate::path::GenericPath;
 
 
 type ParseError<'a> =
-    lalrpop_util::ParseError<usize, lalrpop_util::lexer::Token<'a>, &'a str>;
+  lalrpop_util::ParseError<usize, lalrpop_util::lexer::Token<'a>, &'a str>;
 
 #[derive(Debug)]
 pub enum Error {
-    IO(std::io::Error),
-    Parse(String),
-    PathListHasEmptyComponents(String),
-    PathIsAFile(GenericPath),
-    PathIsRelative(GenericPath),
-    PathInvalid(GenericPath),
+  IO(std::io::Error),
+  Parse(String),
+  PathListHasEmptyComponents(String),
+  PathIsAFile(GenericPath),
+  PathIsRelative(GenericPath),
+  PathInvalid(GenericPath),
 }
 
 impl std::error::Error for Error { }
 
 impl std::fmt::Display for Error {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        match self {
-            Error::IO(e) => e.fmt(f),
-            Error::Parse(e) => e.fmt(f),
-            Error::PathListHasEmptyComponents(path_list) =>
-              f.write_fmt(format_args!(
-                  "Path list has empty components: {}",
-                  path_list)),
-            Error::PathIsAFile(path) =>
-              f.write_fmt(format_args!(
-                  "There's a file at {}, not a directory.",
-                  path)),
-            Error::PathIsRelative(path) =>
-              f.write_fmt(format_args!(
-                  "The path {} is relative, not absolute.",
-                  path)),
-            Error::PathInvalid(path) =>
-              f.write_fmt(format_args!(
-                  "This isn't a valid path. {}",
-                  path)),
-        }
+  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+    match self {
+      Error::IO(e) => e.fmt(f),
+      Error::Parse(e) => e.fmt(f),
+      Error::PathListHasEmptyComponents(path_list) =>
+        f.write_fmt(format_args!(
+            "Path list has empty components: {}",
+            path_list)),
+      Error::PathIsAFile(path) =>
+        f.write_fmt(format_args!(
+            "There's a file at {}, not a directory.",
+            path)),
+      Error::PathIsRelative(path) =>
+        f.write_fmt(format_args!(
+            "The path {} is relative, not absolute.",
+            path)),
+      Error::PathInvalid(path) =>
+        f.write_fmt(format_args!(
+            "This isn't a valid path. {}",
+            path)),
     }
+  }
 }
 
 impl From<std::io::Error> for Error {
-    fn from(e: std::io::Error) -> Error {
-        Error::IO(e)
-    }
+  fn from(e: std::io::Error) -> Error {
+    Error::IO(e)
+  }
 }
 
 impl From<ParseError<'_>> for Error {
-    fn from(e: ParseError<'_>) -> Error {
-        Error::Parse(format!("{}", e))
-    }
+  fn from(e: ParseError<'_>) -> Error {
+    Error::Parse(format!("{}", e))
+  }
 }
 
diff --git a/src/main.rs b/src/main.rs
index 36fb284..60c14ca 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,76 +12,75 @@ pub mod result;
 
 
 pub enum Input {
-    String(String),
-    End,
+  String(String),
+  End,
 }
 
 
 fn main() -> Result<()> {
-    std::process::exit(match repl() {
-        Ok(()) => 0,
-        Err(ref e) => {
-            eprintln!("{}", e);
-            1
-        }
-    })
+  std::process::exit(match repl() {
+    Ok(()) => 0,
+    Err(ref e) => {
+      eprintln!("{}", e);
+      1
+    }
+  })
 }
 
 
 fn repl() -> Result<()> {
-    println!("Hello, terminal!");
+  println!("Hello, terminal!");
 
-    loop {
-        prompt()?;
+  loop {
+    prompt()?;
 
-        let input = read()?;
-        match input {
-            Input::String(string) => execute(&string)?,
-            Input::End => break,
-        }
+    let input = read()?;
+    match input {
+      Input::String(string) => execute(&string)?,
+      Input::End => break,
     }
+  }
 
-    Ok(())
+  Ok(())
 }
 
 
 fn prompt() -> Result<()> {
-    print!("$ ");
-    io::stdout().flush()?;
+  print!("$ ");
+  io::stdout().flush()?;
 
-    Ok(())
+  Ok(())
 }
 
 
 fn read() -> Result<Input> {
-    let mut input = String::new();
-    let n_bytes = io::stdin().read_line(&mut input)?;
-
-    if n_bytes == 0 {
-        Ok(Input::End)
-    } else {
-        Ok(Input::String(input))
-    }
+  let mut input = String::new();
+  let n_bytes = io::stdin().read_line(&mut input)?;
+
+  if n_bytes == 0 {
+    Ok(Input::End)
+  } else {
+    Ok(Input::String(input))
+  }
 }
 
 
 fn execute(input: &str) -> Result<()> {
-    let invocation = commandline::InvocationParser::new().parse(input)?;
-
-    println!("{}", input);
-
-    match invocation.as_slice() {
-      ["paths", path_list, ..] => {
-        let paths = path::parse_path_list(path_list)?;
-        for path in &paths {
-          println!("{}", path);
-        }
-      },
-      _ => {
-        println!("invocation '{:?}'", invocation);
+  let invocation = commandline::InvocationParser::new().parse(input)?;
+
+  println!("{}", input);
+
+  match invocation.as_slice() {
+    ["paths", path_list, ..] => {
+      let paths = path::parse_path_list(path_list)?;
+      for path in &paths {
+        println!("{}", path);
       }
+    },
+    _ => {
+      println!("invocation '{:?}'", invocation);
     }
+  }
 
-    Ok(())
+  Ok(())
 }
-