From 82b54be0b8c275befc681be9dde95b8aa8d6998e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 14 Jan 2025 17:02:09 -0800 Subject: [PATCH] cargo fmt --- rust/Cargo.lock | 10 ++++++++++ rust/pspp-derive/src/lib.rs | 5 +++-- rust/pspp-lsp/src/main.rs | 6 +----- rust/pspp/Cargo.toml | 1 + rust/pspp/src/lex/mod.rs | 6 +++--- rust/pspp/src/lex/scan/mod.rs | 6 +++--- rust/pspp/src/lex/segment/mod.rs | 5 ++++- rust/pspp/src/lex/segment/test.rs | 4 ++-- rust/pspp/src/output/csv.rs | 8 +++++++- rust/pspp/src/output/render.rs | 14 +++----------- 10 files changed, 37 insertions(+), 28 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 5e691e5ca2..33edf04474 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -607,6 +607,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -900,6 +909,7 @@ dependencies = [ "float_next_after", "hexplay", "indexmap", + "itertools", "lazy_static", "libc", "libm", diff --git a/rust/pspp-derive/src/lib.rs b/rust/pspp-derive/src/lib.rs index 28438ad9bf..d3bbd943ea 100644 --- a/rust/pspp-derive/src/lib.rs +++ b/rust/pspp-derive/src/lib.rs @@ -35,14 +35,15 @@ fn derive_enum(ast: &DeriveInput, e: &DataEnum) -> Result { let ident = &variant.ident; let field_attrs = FieldAttrs::parse(&variant.attrs)?; let selector = field_attrs.selector.unwrap_or(struct_attrs.selector); - let construction = construct_fields(&variant.fields, quote! { #name::#ident }, selector, None); + let construction = + construct_fields(&variant.fields, quote! { #name::#ident }, selector, None); let fnname = format_ident!("construct_{ident}"); body.extend(quote! { fn #fnname #impl_generics(input: &TokenSlice) -> ParseResult<#name #ty_generics> #where_clause { let input = input.clone(); #construction } }); } - for variant in &e.variants { + for variant in &e.variants { let ident = &variant.ident; let fnname = format_ident!("construct_{ident}"); let field_attrs = FieldAttrs::parse(&variant.attrs)?; diff --git a/rust/pspp-lsp/src/main.rs b/rust/pspp-lsp/src/main.rs index 349b1afee0..db982a454c 100644 --- a/rust/pspp-lsp/src/main.rs +++ b/rust/pspp-lsp/src/main.rs @@ -1,11 +1,7 @@ use std::collections::HashMap; use tokio::sync::Mutex; -use tower_lsp::{ - jsonrpc::Result, - lsp_types::*, - Client, LanguageServer, LspService, Server, -}; +use tower_lsp::{jsonrpc::Result, lsp_types::*, Client, LanguageServer, LspService, Server}; #[tokio::main] async fn main() { diff --git a/rust/pspp/Cargo.toml b/rust/pspp/Cargo.toml index 027a8440ff..0536ee4ec0 100644 --- a/rust/pspp/Cargo.toml +++ b/rust/pspp/Cargo.toml @@ -34,6 +34,7 @@ enum-iterator = "2.1.0" smallvec = { version = "1.13.2", features = ["const_generics", "write"] } libm = "0.2.11" smallstr = "0.3.0" +itertools = "0.14.0" [target.'cfg(windows)'.dependencies] windows-sys = { version = "0.48.0", features = ["Win32_Globalization"] } diff --git a/rust/pspp/src/lex/mod.rs b/rust/pspp/src/lex/mod.rs index e87b088cf4..97b347ff2e 100644 --- a/rust/pspp/src/lex/mod.rs +++ b/rust/pspp/src/lex/mod.rs @@ -10,8 +10,8 @@ //! are the same as the tokens used by the PSPP parser with a few additional //! types. -pub mod segment; -pub mod scan; pub mod command_name; -pub mod token; pub mod lexer; +pub mod scan; +pub mod segment; +pub mod token; diff --git a/rust/pspp/src/lex/scan/mod.rs b/rust/pspp/src/lex/scan/mod.rs index 1de961be7f..398c8827a6 100644 --- a/rust/pspp/src/lex/scan/mod.rs +++ b/rust/pspp/src/lex/scan/mod.rs @@ -13,7 +13,7 @@ use crate::identifier::{Identifier, ReservedWord}; use super::{ - segment::{Syntax, Segment, Segmenter}, + segment::{Segment, Segmenter, Syntax}, token::{Punct, Token}, }; use std::collections::VecDeque; @@ -403,8 +403,8 @@ impl<'a> Iterator for StringScanner<'a> { return Some(token); } self.input = rest; - return Some(ScanToken::Error(error)) - }, + return Some(ScanToken::Error(error)); + } Some(ScanToken::Token(token)) => { self.tokens.push_back(token); } diff --git a/rust/pspp/src/lex/segment/mod.rs b/rust/pspp/src/lex/segment/mod.rs index 5448aa81ae..ffa6de3137 100644 --- a/rust/pspp/src/lex/segment/mod.rs +++ b/rust/pspp/src/lex/segment/mod.rs @@ -1097,7 +1097,10 @@ impl Segmenter { } return Ok(Some((rest, Segment::DoRepeatCommand))); } - fn parse_do_repeat_4<'a>(&mut self, input: &'a str) -> Result, Incomplete> { + fn parse_do_repeat_4<'a>( + &mut self, + input: &'a str, + ) -> Result, Incomplete> { self.state.0 = State::DoRepeat3; Ok(Some((input, Segment::DoRepeatOverflow))) } diff --git a/rust/pspp/src/lex/segment/test.rs b/rust/pspp/src/lex/segment/test.rs index 79f92fed36..3c36186a14 100644 --- a/rust/pspp/src/lex/segment/test.rs +++ b/rust/pspp/src/lex/segment/test.rs @@ -1,6 +1,6 @@ use crate::prompt::PromptStyle; -use super::{Syntax, Segment, Segmenter}; +use super::{Segment, Segmenter, Syntax}; fn push_segment<'a>( segmenter: &mut Segmenter, @@ -1517,7 +1517,7 @@ end repeat mod define { use crate::{ - lex::segment::{Syntax, Segment}, + lex::segment::{Segment, Syntax}, prompt::PromptStyle, }; diff --git a/rust/pspp/src/output/csv.rs b/rust/pspp/src/output/csv.rs index df0b158db9..a8edb849e6 100644 --- a/rust/pspp/src/output/csv.rs +++ b/rust/pspp/src/output/csv.rs @@ -1,4 +1,10 @@ -use std::{borrow::Cow, fmt::Display, fs::File, io::{Error, Write}, sync::Arc}; +use std::{ + borrow::Cow, + fmt::Display, + fs::File, + io::{Error, Write}, + sync::Arc, +}; use crate::output::pivot::Coord2; diff --git a/rust/pspp/src/output/render.rs b/rust/pspp/src/output/render.rs index 5057a6bb36..7fdb5d53a4 100644 --- a/rust/pspp/src/output/render.rs +++ b/rust/pspp/src/output/render.rs @@ -1,9 +1,11 @@ use std::cmp::max; use std::collections::HashMap; +use std::iter::once; use std::ops::Range; use std::sync::Arc; use enum_map::EnumMap; +use itertools::interleave; use smallvec::SmallVec; use super::pivot::{Axis2, BorderStyle, Coord2, Look, PivotTable, Rect2, Stroke}; @@ -491,17 +493,7 @@ impl Page { } fn use_row_widths(rows: &[usize], rules: &[usize]) -> Vec { - debug_assert_eq!(rows.len() + 1, rules.len()); - let mut cp = Vec::with_capacity(2 * (rows.len()) + 1); - - cp.push(0); - for (rule, row) in rules.iter().zip(rows.iter()) { - cp.push(*rule); - cp.push(*row); - } - cp.push(*rules.last().unwrap()); - - Self::accumulate_vec(cp) + once(0).chain(interleave(rules, rows).copied()).collect() } fn interpolate_row_widths( -- 2.30.2