Skip to content

Format imports #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions awk/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@

#![allow(clippy::result_large_err)]

use crate::program::{
Action, AwkRule, BuiltinFunction, Constant, DebugInfo, Function, OpCode, Pattern, Program,
SourceLocation, SpecialVar, VarId,
};
use crate::regex::Regex;

use pest::error::InputLocation;
use pest::iterators::{Pair, Pairs};
use pest::pratt_parser::{Assoc, Op, PrattParser};
use pest::Parser;
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::ffi::CString;
Expand All @@ -27,6 +17,17 @@ use std::rc::Rc;
use std::str::Chars;
use std::sync::LazyLock;

use pest::error::InputLocation;
use pest::iterators::{Pair, Pairs};
use pest::pratt_parser::{Assoc, Op, PrattParser};
use pest::Parser;

use crate::program::{
Action, AwkRule, BuiltinFunction, Constant, DebugInfo, Function, OpCode, Pattern, Program,
SourceLocation, SpecialVar, VarId,
};
use crate::regex::Regex;

struct BuiltinFunctionInfo {
function: BuiltinFunction,
min_args: u16,
Expand Down
7 changes: 3 additions & 4 deletions awk/src/interpreter/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
// SPDX-License-Identifier: MIT
//

use std::{
collections::{hash_map::Entry, HashMap},
rc::Rc,
};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::rc::Rc;

use super::AwkValue;

Expand Down
3 changes: 2 additions & 1 deletion awk/src/interpreter/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// SPDX-License-Identifier: MIT
//

use std::{fmt::Write, str::Chars};
use std::fmt::Write;
use std::str::Chars;

const BASE_8_DIGITS: [char; 8] = ['0', '1', '2', '3', '4', '5', '6', '7'];
const BASE_10_DIGITS: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
Expand Down
13 changes: 6 additions & 7 deletions awk/src/interpreter/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
//

use core::panic;
use std::{
collections::{hash_map::Entry, HashMap},
ffi::CString,
fs::File,
io::{BufReader, Bytes, Read, Write},
rc::Rc,
};
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::ffi::CString;
use std::fs::File;
use std::io::{BufReader, Bytes, Read, Write};
use std::rc::Rc;

use super::string::AwkString;

Expand Down
27 changes: 14 additions & 13 deletions awk/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@
// SPDX-License-Identifier: MIT
//

use std::cell::{RefCell, UnsafeCell};
use std::collections::HashMap;
use std::ffi::CString;
use std::fmt::Write;
use std::iter;
use std::marker::PhantomData;
use std::rc::Rc;
use std::time::SystemTime;

use array::{Array, KeyIterator, ValueIndex};
use format::{
fmt_write_decimal_float, fmt_write_float_general, fmt_write_hex_float,
fmt_write_scientific_float, fmt_write_signed, fmt_write_string, fmt_write_unsigned,
parse_conversion_specifier_args, IntegerFormat,
};
use io::{
EmptyRecordReader, FileStream, ReadFiles, ReadPipes, RecordReader, RecordSeparator,
StdinRecordReader, WriteFiles, WritePipes,
Expand All @@ -22,19 +36,6 @@ use crate::program::{
SpecialVar,
};
use crate::regex::Regex;
use format::{
fmt_write_decimal_float, fmt_write_float_general, fmt_write_hex_float,
fmt_write_scientific_float, fmt_write_signed, fmt_write_string, fmt_write_unsigned,
parse_conversion_specifier_args, IntegerFormat,
};
use std::cell::{RefCell, UnsafeCell};
use std::collections::HashMap;
use std::ffi::CString;
use std::fmt::Write;
use std::iter;
use std::marker::PhantomData;
use std::rc::Rc;
use std::time::SystemTime;

mod array;
mod format;
Expand Down
4 changes: 3 additions & 1 deletion awk/src/interpreter/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
//

use core::fmt;
use std::{ffi::CString, ops::Deref, rc::Rc};
use std::ffi::CString;
use std::ops::Deref;
use std::rc::Rc;

#[cfg_attr(test, derive(Debug))]
#[derive(Clone, PartialEq)]
Expand Down
12 changes: 7 additions & 5 deletions awk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
// SPDX-License-Identifier: MIT
//

use crate::compiler::compile_program;
use crate::interpreter::interpret;
use clap::Parser;
use compiler::SourceFile;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use std::error::Error;
use std::fmt::Display;
use std::io::Read;

use clap::Parser;
use compiler::SourceFile;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};

use crate::compiler::compile_program;
use crate::interpreter::interpret;

mod compiler;
mod interpreter;
mod program;
Expand Down
4 changes: 3 additions & 1 deletion awk/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
// SPDX-License-Identifier: MIT
//

use std::collections::HashMap;
use std::rc::Rc;

use crate::regex::Regex;
use std::{collections::HashMap, rc::Rc};

pub type VarId = u32;

Expand Down
10 changes: 4 additions & 6 deletions calc/bc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@

use std::ffi::OsString;

use bc_util::{
interpreter::{ExecutionResult, Interpreter},
parser::parse_program,
};
use bc_util::interpreter::{ExecutionResult, Interpreter};
use bc_util::parser::parse_program;
use clap::Parser;

use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use rustyline::{error::ReadlineError, DefaultEditor, Result};
use rustyline::error::ReadlineError;
use rustyline::{DefaultEditor, Result};

mod bc_util;

Expand Down
16 changes: 7 additions & 9 deletions calc/bc_util/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
// SPDX-License-Identifier: MIT
//

use std::{fmt::Write, rc::Rc};
use std::fmt::Write;
use std::rc::Rc;

use crate::bc_util::instructions::Variable;

use super::{
instructions::{
BuiltinFunction, ConditionInstruction, ExprInstruction, Function, FunctionArgument,
NamedExpr, Program, Register, StmtInstruction,
},
number::Number,
use super::instructions::{
BuiltinFunction, ConditionInstruction, ExprInstruction, Function, FunctionArgument, NamedExpr,
Program, Register, StmtInstruction,
};
use super::number::Number;
use crate::bc_util::instructions::Variable;

#[derive(Debug)]
struct ErrorCall {
Expand Down
3 changes: 2 additions & 1 deletion calc/bc_util/number.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bigdecimal::{num_bigint::BigInt, BigDecimal, Num, One, Signed, ToPrimitive, Zero};
use bigdecimal::num_bigint::BigInt;
use bigdecimal::{BigDecimal, Num, One, Signed, ToPrimitive, Zero};

/// Converts a character to a number
/// # Panics
Expand Down
7 changes: 4 additions & 3 deletions calc/bc_util/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
// SPDX-License-Identifier: MIT
//

use super::instructions::*;
use std::rc::Rc;
use std::sync::LazyLock;

use pest::error::InputLocation;
use pest::iterators::Pair;
use pest::pratt_parser::{Assoc, Op, PrattParser};
use pest::{Parser, Position};
use std::rc::Rc;
use std::sync::LazyLock;

use super::instructions::*;

static PRATT_PARSER: LazyLock<PrattParser<Rule>> = LazyLock::new(|| {
// Precedence is defined lowest to highest
Expand Down
3 changes: 2 additions & 1 deletion datetime/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
// SPDX-License-Identifier: MIT
//

use std::{thread, time};

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use std::{thread, time};

#[derive(Parser)]
#[command(version, about = gettext("sleep - suspend execution for an interval"))]
Expand Down
6 changes: 2 additions & 4 deletions datetime/tests/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
// SPDX-License-Identifier: MIT
//

use std::{
io::Write,
process::{Command, Output, Stdio},
};
use std::io::Write;
use std::process::{Command, Output, Stdio};

use plib::testing::TestPlan;

Expand Down
7 changes: 4 additions & 3 deletions dev/ar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
// SPDX-License-Identifier: MIT
//

use chrono::DateTime;
use clap::{Parser, Subcommand};
use object::{Object, ObjectSymbol, SymbolKind};
use std::ffi::{OsStr, OsString};
use std::io::{stdout, Write};
use std::os::unix::ffi::{OsStrExt, OsStringExt};
use std::os::unix::fs::MetadataExt;
use std::path::Path;

use chrono::DateTime;
use clap::{Parser, Subcommand};
use object::{Object, ObjectSymbol, SymbolKind};

#[derive(clap::Args)]
#[group(required = false, multiple = false)]
struct InsertArgs {
Expand Down
10 changes: 5 additions & 5 deletions dev/nm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
// - sort output
//

use std::collections::HashMap;
use std::fs;

use clap::{Parser, ValueEnum};
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use object::{
Object, ObjectSection, ObjectSymbol, SectionIndex, SectionKind, Symbol, SymbolKind,
SymbolSection,
};

use clap::{Parser, ValueEnum};
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use std::collections::HashMap;
use std::fs;

#[derive(ValueEnum, Clone)]
enum OutputType {
D,
Expand Down
14 changes: 5 additions & 9 deletions dev/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
// SPDX-License-Identifier: MIT
//

use std::ffi::{OsStr, OsString};
use std::io::Read;

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use object::{
archive,
build::elf::{Builder, Section, SectionData},
elf,
};
use std::{
ffi::{OsStr, OsString},
io::Read,
};
use object::build::elf::{Builder, Section, SectionData};
use object::{archive, elf};

#[derive(Parser)]
#[command(version, about = gettext("strip - remove unnecessary information from strippable files"))]
Expand Down
3 changes: 2 additions & 1 deletion dev/tests/dev-tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs;

use object::{Object, ObjectSection, ObjectSymbol};
use plib::testing::{run_test, run_test_with_checker, TestPlan};
use std::fs;

fn ar_compare_test(
args: &[&str],
Expand Down
3 changes: 2 additions & 1 deletion display/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
// Write an 8-bit value that is the 0, 1, 2 or 3-digit octal number _num_.
//

use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
use std::io::{self, Write};

use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};

fn translate_str(skip_nl: bool, s: &str) -> String {
let mut output = String::with_capacity(s.len());

Expand Down
20 changes: 14 additions & 6 deletions display/more.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
// SPDX-License-Identifier: MIT
//

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use libc::{
getegid, getgid, getuid, regcomp, regex_t, regexec, setgid, setuid, REG_ICASE, REG_NOMATCH,
};
use std::collections::HashMap;
use std::ffi::CString;
use std::fs::File;
Expand All @@ -25,7 +20,20 @@ use std::str::FromStr;
use std::sync::mpsc::{channel, Receiver, TryRecvError};
use std::sync::Mutex;
use std::time::Duration;
use termion::{clear::*, cursor::*, event::*, input::*, raw::*, screen::*, style::*, *};

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use libc::{
getegid, getgid, getuid, regcomp, regex_t, regexec, setgid, setuid, REG_ICASE, REG_NOMATCH,
};
use termion::clear::*;
use termion::cursor::*;
use termion::event::*;
use termion::input::*;
use termion::raw::*;
use termion::screen::*;
use termion::style::*;
use termion::*;

const LINES_PER_PAGE: u16 = 24;
const NUM_COLUMNS: u16 = 80;
Expand Down
Loading