diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e77950e..dbf32d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/src/frontend/parser.rs b/src/frontend/parser.rs index 867fce6..fd55697 100644 --- a/src/frontend/parser.rs +++ b/src/frontend/parser.rs @@ -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); diff --git a/src/frontend/scanner.rs b/src/frontend/scanner.rs index 222d318..4f77dcd 100644 --- a/src/frontend/scanner.rs +++ b/src/frontend/scanner.rs @@ -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>) { diff --git a/src/interpreter/filter/builtin.rs b/src/interpreter/filter/builtin.rs index f147d06..dee790d 100644 --- a/src/interpreter/filter/builtin.rs +++ b/src/interpreter/filter/builtin.rs @@ -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., `Link text`) -//! 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, diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 6f0a6d4..c07bdf0 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -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:?}"); }; diff --git a/tests/grammar_tests.rs b/tests/grammar_tests.rs index 4ed634c..f129a6a 100644 --- a/tests/grammar_tests.rs +++ b/tests/grammar_tests.rs @@ -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() @@ -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() }