Skeletton for the formatter
This commit is contained in:
parent
4cf73ff243
commit
11e5c6c5c5
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use config::{
|
||||
formatter::FormatterConfig,
|
||||
graph::GraphConfig,
|
||||
make::{
|
||||
HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, MakeTargets,
|
||||
|
|
@ -42,6 +43,8 @@ pub enum Commands {
|
|||
Make(MakeConfig),
|
||||
/// Make all graphs
|
||||
Graphs(GraphConfig),
|
||||
/// Format the file given on input
|
||||
Format(FormatterConfig),
|
||||
}
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
// Workspace: config
|
||||
// File: config/src/formatter.rs
|
||||
//! The inner config for formatter module
|
||||
|
||||
use clap::Args;
|
||||
|
||||
#[derive(Args, Debug, Clone)]
|
||||
/// The configuration struct for the Formatter
|
||||
pub struct FormatterConfig {
|
||||
/// Export the config
|
||||
#[arg(short, long)]
|
||||
pub config: bool,
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
// Internal Modules
|
||||
pub mod fast_tables;
|
||||
pub mod formatter;
|
||||
pub mod graph;
|
||||
pub mod make;
|
||||
pub mod statsolver;
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
//! active, crowd-control). This enum is defined for readability but the
|
||||
//! current `Skill::t_type` field uses raw `u8` values - see the note in
|
||||
//! `Skill` for guidance on converting between the two.
|
||||
//
|
||||
//!
|
||||
//! The module is free of external dependencies except for `facet`, which provides
|
||||
//! the procedural macro used for deriving serialisation support.
|
||||
//! the procedural macro used for deriving serialisation support.
|
||||
|
||||
use facet::Facet;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "formatter"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
config = {path = "../config"}
|
||||
cli_parser = {path = "../cli_parser"}
|
||||
regex = "1.11.1"
|
||||
serde = { version = "1.0.217", features = ["derive", "alloc"] }
|
||||
toml = "0.8.20"
|
||||
anyhow = "1.0.95"
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
//! A simple formatter that reads patterns from a TOML file,
|
||||
//! applies them to stdin, and writes the formatted text to stdout.
|
||||
use anyhow::{Context, Result};
|
||||
use cli_parser::Config;
|
||||
use config::formatter::FormatterConfig;
|
||||
use regex::Regex;
|
||||
use std::fs;
|
||||
use std::io::{self, Read};
|
||||
|
||||
const SAMPLE_CONFIG: &str = r#"[[patterns]]
|
||||
regex = "\\p{Pd}"
|
||||
replacement = "-"
|
||||
|
||||
[[patterns]]
|
||||
regex = "[\u2018\u2019\u201A\u201B\u02BC\u02BB\u00B4\uFF40\uFF07]"
|
||||
replacement = "'"
|
||||
|
||||
[[patterns]]
|
||||
regex = "[\\u00AD\\u200B\\u200C\\u200D\\uFEFF\\u2060-\\u2064\\uFE00-\\uFE0F]"
|
||||
replacement = ""
|
||||
|
||||
[[patterns]]
|
||||
regex = "[\\u202F]"
|
||||
replacement = " ""
|
||||
"#;
|
||||
|
||||
pub fn format_file(args: &FormatterConfig, _config: &Config) -> Result<()> {
|
||||
// If --config was requested, print the sample config and exit.
|
||||
// if args.config {
|
||||
// println!("{}", SAMPLE_CONFIG);
|
||||
// return Ok(());
|
||||
// }
|
||||
|
||||
// // ------------------------------------------------------------------
|
||||
// // 1. Read and parse the .fmtconfig.toml file.
|
||||
// // ------------------------------------------------------------------
|
||||
// let toml_text = fs::read_to_string(".fmtconfig.toml")
|
||||
// .map_err(|e| format!("Failed to read .fmtconfig.toml: {}", e))?;
|
||||
|
||||
// let config: Config = toml::from_str(&toml_text)
|
||||
// .map_err(|e| format!("Failed to parse .fmtconfig.toml: {}", e))?;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 2. Read the entire stdin into a string.
|
||||
// ------------------------------------------------------------------
|
||||
// let mut input = String::new();
|
||||
// io::stdin()
|
||||
// .read_to_string(&mut input)
|
||||
// .map_err(|e| format!("Failed to read stdin: {}", e))?;
|
||||
|
||||
// // ------------------------------------------------------------------
|
||||
// // 3. Apply the patterns sequentially.
|
||||
// // ------------------------------------------------------------------
|
||||
// let mut output = input;
|
||||
// for pat in &config.patterns {
|
||||
// // Compile the regex lazily; panic on bad patterns in this demo.
|
||||
// let re = Regex::new(&pat.regex)?;
|
||||
// output = re
|
||||
// .replace_all(&output, pat.replacement.as_str())
|
||||
// .into_owned();
|
||||
// }
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 4. Write the result to stdout.
|
||||
// ------------------------------------------------------------------
|
||||
// print!("{}", output);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
//! This workspace_crate is a Rust library designed to Format latex documents on save.
|
||||
|
||||
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
||||
// Internal modules
|
||||
mod formating;
|
||||
//
|
||||
// Re Export
|
||||
pub use formating::format_file;
|
||||
|
|
@ -11,6 +11,7 @@ cli_parser = {path = "../cli_parser"}
|
|||
# config = {path = "../config"}
|
||||
stats = {path = "../stats"}
|
||||
make = {path = "../make"}
|
||||
formatter = {path = "../formatter"}
|
||||
|
||||
anyhow = "1.0.95"
|
||||
clap = { version = "4.5.28", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#![warn(clippy::missing_docs_in_private_items)]
|
||||
|
||||
// Workspace
|
||||
use formatter::format_file;
|
||||
use graphs::make_graphs;
|
||||
use make::make_pdf;
|
||||
use stats::stat_solver;
|
||||
|
|
@ -31,6 +32,7 @@ fn main() -> Result<()> {
|
|||
Commands::Stats(args) => stat_solver(&args, &config),
|
||||
Commands::Make(args) => make_pdf(&args, &config),
|
||||
Commands::Graphs(args) => make_graphs(&args, &config),
|
||||
Commands::Format(args) => format_file(&args, &config),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue