Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
suaviloquence committed Aug 16, 2024
1 parent 775061c commit 1379b54
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
- name: verify formatting
uses: actions-rust-lang/rustfmt@v1
- name: run clippy
run: cargo clippy --all-targets -- --deny clippy::all --warn clippy::pedantic --warn warnings
run: cargo clippy --all-targets --workspace -- --deny clippy::all --warn clippy::pedantic --warn warnings
2 changes: 1 addition & 1 deletion src/frontend/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ mod tests {
};
};"#;
let parser = Parser::new(&string);
let parser = Parser::new(string);
let (arena, r) = parser.parse().expect("parsing failed");

let stmts = arena.flatten(r);
Expand Down
32 changes: 17 additions & 15 deletions src/frontend/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,27 +171,29 @@ impl<'a> Scanner<'a> {
.as_str(),
})
.max_by_key(|x| x.value.len())
.map(|lx| {
.map_or(
(
Span {
line: self.line,
start: self.idx,
end: self.idx + lx.value.len(),
end: self.idx + 1,
},
lx,
)
})
.unwrap_or((
Span {
line: self.line,
start: self.idx,
end: self.idx + 1,
},
Lexeme {
token: Token::Unknown,
value: &self.slice[self.idx..=self.idx],
Lexeme {
token: Token::Unknown,
value: &self.slice[self.idx..=self.idx],
},
),
|lx| {
(
Span {
line: self.line,
start: self.idx,
end: self.idx + lx.value.len(),
},
lx,
)
},
))
)
}

pub fn eat_token(&mut self) -> (Span, Lexeme<'a>) {
Expand Down
14 changes: 7 additions & 7 deletions src/interpreter/filter/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
//! - Specifying an arg type with a question mark (e.g., `value: Value | dbg(msg: String?): Value`)
//! means that that argument (e.g., `msg`) is *optional* and can be omitted.
//! - List shorthand: a `List` is represented as `[a_0, a_1, a_2, ..., a_n]` to mean that
//! its elements are `a_0, ..., a_n` in that order. Indexing starts at 0. This syntax is currently
//! not valid `scrapelect`, but it is useful to express in documentation.
//! - Structure shorthand: similarly, a structure is represented as { key_1: value_1, key_2: value_2, ... } to
//! indicate that it has keys that correspond to the given values. This is not valid `scrapelect`,
//! but it is useful in documentation.
//! its elements are `a_0, ..., a_n` in that order. Indexing starts at 0. This syntax is currently
//! not valid `scrapelect`, but it is useful to express in documentation.
//! - Structure shorthand: similarly, a structure is represented as `{ key_1: value_1, key_2: value_2, ... }` to
//! indicate that it has keys that correspond to the given values. This is not valid `scrapelect`,
//! but it is useful in documentation.
//! - Element shorthand: an inline HTML element (e.g., `<a href=\"github.com/suaviloquence/scrapelect\">Link text</a>`)
//! is also not valid `scrapelect`, but is useful to demonstrate how `Element`s are used
//! in filters.
//! is also not valid `scrapelect`, but is useful to demonstrate how `Element`s are used
//! in filters.
use std::{
collections::BTreeMap,
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ mod tests {
panic!("got {output:?}, expected a: [ .. ]");
};

let Some(Structure(a)) = a.get(0) else {
let Some(Structure(a)) = a.first() else {
panic!("got {output:?}");
};

Expand Down
4 changes: 2 additions & 2 deletions tests/grammar_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'a> Grammar<'a> {
});
}

if let Some(x) = rules.get(0) {
if let Some(x) = rules.first() {
let nt = x.nonterminal;
rules
.iter_mut()
Expand Down Expand Up @@ -282,7 +282,7 @@ impl<'a> Grammar<'a> {

predict_sets
.into_iter()
.map(|x| x.into_iter().filter_map(|x| x).collect())
.map(|x| x.into_iter().flatten().collect())
.collect()
}

Expand Down

0 comments on commit 1379b54

Please sign in to comment.