Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jofas committed Mar 16, 2022
1 parent 15569e7 commit 6034d22
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,11 @@ The error includes all normal `io` mishaps, like a missing file:
```rust
use env_file_reader::read_file;

fn main() {
let err = read_file(".env.which.does.not.exist")
.err()
.unwrap();
let err = read_file(".env.which.does.not.exist")
.err()
.unwrap();

assert_eq!(err.kind(), std::io::ErrorKind::NotFound);
}
assert_eq!(err.kind(), std::io::ErrorKind::NotFound);
```

Additionally, parsing can fail due to an ill-formatted environment
Expand All @@ -415,12 +413,10 @@ If that is the case, a custom error, `ParseError`, is returned:
```rust
use env_file_reader::read_str;

fn main() {
let err = read_str("badly formatted env file")
.err()
.unwrap();
let err = read_str("badly formatted env file")
.err()
.unwrap();

assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
assert_eq!(err.to_string(), "ParseError");
}
assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
assert_eq!(err.to_string(), "ParseError");
```
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

* [x] test suite

* [ ] clippy action

* [ ] release `v0.3.0`

* [ ] type support through `serde`
8 changes: 4 additions & 4 deletions src/env_file.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ extern {
"ident" => Token::Ident(<String>),
"qs" => Token::QuotedString(<String>),
"\n" => Token::NewLine,
"EOF" => Token::EOF,
"eof" => Token::Eof,
}
}

pub EnvFile: HashMap<String, String> = {
<Line*> => HashMap::from_iter(<>.into_iter().filter_map(|x| x)),
<Line*> => HashMap::from_iter(<>.into_iter().flatten()),
}

Line: Option<(String, String)> = {
<k:Key> "=" <v:Value> => Some((k, v)),
"\n" => None,
"EOF" => None,
"eof" => None,
};

Key: String = "export"? <k:"ident"> => k;
Expand All @@ -35,5 +35,5 @@ Value: String = {
"ident" => <>,
"qs" => <>,
"\n" => String::new(),
"EOF" => String::new(),
"eof" => String::new(),
};
28 changes: 12 additions & 16 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ use std::error::Error;
/// ```rust
/// use env_file_reader::read_str;
///
/// fn main() {
/// let err = read_str("badly formatted env file")
/// .err()
/// .unwrap();
/// let err = read_str("badly formatted env file")
/// .err()
/// .unwrap();
///
/// assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
/// assert_eq!(err.to_string(), "ParseError");
/// }
/// assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
/// assert_eq!(err.to_string(), "ParseError");
/// ```
///
#[derive(Debug)]
Expand All @@ -46,7 +44,7 @@ fn remove_quotes(lex: &mut logos::Lexer<Token>) -> String {
let escaped_newline_pattern = "\\n";

slice[1..slice.len() - 1]
.replace(&escaped_quote_pattern, &quote)
.replace(&escaped_quote_pattern, quote)
.replace(escaped_newline_pattern, "\n")
}

Expand All @@ -64,7 +62,7 @@ pub enum Token {
#[regex(r"`[^`]*`", remove_quotes)]
#[regex(r#""([^"]|\\")*""#, remove_quotes)]
QuotedString(String),
EOF,
Eof,
#[error]
#[regex(r"#.*", logos::skip)]
#[regex(r"\s+", logos::skip)]
Expand Down Expand Up @@ -98,18 +96,16 @@ impl<'input> Iterator for Lexer<'input> {

fn next(&mut self) -> Option<Self::Item> {
match self.token_stream.next() {
Some((token, span)) => {
match token {
Token::Error => Some(Err(ParseError)),
_ => Some(Ok((span.start, token, span.end))),
}
}
Some((token, span)) => match token {
Token::Error => Some(Err(ParseError)),
_ => Some(Ok((span.start, token, span.end))),
},
None => {
if self.finished() {
None
} else {
self.finish();
Some(Ok((0, Token::EOF, 0)))
Some(Ok((0, Token::Eof, 0)))
}
}
}
Expand Down

0 comments on commit 6034d22

Please sign in to comment.