Skip to content

Commit

Permalink
chore: clippy and cargofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
slbsh committed Aug 5, 2024
1 parent bfd47cc commit 7fb479c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
10 changes: 4 additions & 6 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ macro_rules! error {
#[derive(Copy, Clone)]
pub struct Arg<T> {
pub value: T,
set: bool,
set: bool,
}

impl<T> Arg<T> {
fn new(default: T) -> Self {
Self {
value: default,
set: false,
}
Self { value: default, set: false }
}

fn try_mut<N: std::fmt::Display>(&mut self, name: N, value: T) {
Expand Down Expand Up @@ -75,7 +72,8 @@ impl Args {
fn handle_arg(&mut self, argument: &str, arguments: &mut std::vec::IntoIter<String>) {
let args: Vec<String> = if argument.starts_with("--") {
vec![argument.into()]
} else {
}
else {
argument.chars().skip(1).map(|c| format!("-{c}")).collect()
};
let args_len = args.len();
Expand Down
7 changes: 6 additions & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ impl<'source> Lexer<'source> {
while Some('\n') == self.current {
self.advance();
}
if self.tokens.last().is_some_and(|token| token.kind != TokenKind::NewLine) {

if self
.tokens
.get_offset(-1)
.is_some_and(|token| token.kind != TokenKind::NewLine)
{
self.push_token(TokenKind::NewLine, span_to!(start_index), "");
}
continue;
Expand Down
14 changes: 4 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ fn main() {
let (sender, receiver) = std::sync::mpsc::channel::<Box<Report>>();

let tokens = {
let mut lexer = Lexer::new(
*args.file,
Scanner::get_file(*args.file),
ReportSender::new(sender.clone()),
);
let mut lexer =
Lexer::new(*args.file, Scanner::get(*args.file), ReportSender::new(sender.clone()));
lexer.lex_tokens();
lexer.tokens.goto_front();

Expand All @@ -109,11 +106,8 @@ fn main() {
};

let (tokens, tags) = {
let mut preprocessor = preprocessor::PreProcessor::new(
*args.file,
tokens,
ReportSender::new(sender.clone()),
);
let mut preprocessor =
preprocessor::PreProcessor::new(*args.file, tokens, ReportSender::new(sender.clone()));

let (tokens, tags) = preprocessor.process();

Expand Down
4 changes: 1 addition & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ impl<'t, 'contents> Parser<'t, 'contents> {
}
Ok(())
},
TokenKind::EOF => {
Ok(())
},
TokenKind::EOF => Ok(()),
_ => ReportKind::UnexpectedToken
.new(format!("expected NewLine got '{kind:?}'"))
.with_label(ReportLabel::new(span.clone()))
Expand Down
14 changes: 5 additions & 9 deletions src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ impl Scanner {

let contents = Self::new(filename)
.unwrap_or_fatal(
ReportKind::IOError
.new(format!("Failed to open file: '{filename}'"))
.into(),
ReportKind::IOError.new(format!("Failed to open file: '{filename}'")).into(),
)
.read()
.unwrap_or_fatal(
ReportKind::IOError
.new(format!("Failed to read file: '{filename}'"))
.into(),
ReportKind::IOError.new(format!("Failed to read file: '{filename}'")).into(),
)
.contents;

Expand Down Expand Up @@ -69,8 +65,8 @@ impl Scanner {
'\n' => {
li = index;
ln += 1;
}
_ => {}
},
_ => {},
};
(li, ln)
},
Expand All @@ -82,7 +78,7 @@ impl Scanner {
.with_label(ReportLabel::new(span))
.display(false);
std::process::exit(1);
}
},
}
self.index += 1;
}
Expand Down

0 comments on commit 7fb479c

Please sign in to comment.