diff --git a/.cargo/config.toml b/.cargo/config.toml index c4bb6e0..aef34ed 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [build] -rustflags = ["-Clink-arg=-fuse-ld=lld", "-Ctarget-cpu=native"] +rustflags = ["-Clink-arg=-fuse-ld=lld", "-Ctarget-cpu=native", "-Zthreads=24"] diff --git a/Cargo.toml b/Cargo.toml index 235f299..f3b76e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,3 +42,12 @@ lto = true codegen-units = 1 incremental = false panic = "abort" + +[profile.base] +inherits = "dev" +opt-level = 0 +debug = 0 +strip = "none" +lto = false +codegen-units = 256 +incremental = false diff --git a/src/makepdf.rs b/src/makepdf.rs index 8d8e972..e6f7f39 100644 --- a/src/makepdf.rs +++ b/src/makepdf.rs @@ -1,7 +1,7 @@ //! Make a pdf using pdflatex // use std::fmt::Display; -use logos::Logos; +use logos::{Lexer, Logos}; use std::str; use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::process::Command; @@ -128,35 +128,55 @@ async fn launch_subprocess(args: &MakeConfig) -> Result { /// The line encountered // #[allow(unused)] #[derive(Debug, Logos, PartialEq)] -// #[logos()] +#[logos(skip r"[) ]+")] enum LineType { /// The tex building mode #[regex("entering[_ ]extended[_ ]mode")] Mode, - // s if s.starts_with("Package tabularray Warning") => LineType::TabularWarn(s.to_string()), - // s if s.starts_with(" [") => LineType::WriteMode(s.to_string()), - // s if s.starts_with("Library") => LineType::Library(s.to_string()), - // s if s.starts_with("(/usr/share/texlive/") => LineType::Loading(s.to_string()), - // // "LaTeX Warning: Reference" /// Info level - #[token("L3 programming layer")] - Info, + #[token("L3 programming layer", |lex| lex.slice().to_string())] + #[token("For additional information", |lex| lex.slice().to_string())] + #[token("Pictures in Paragraphs", |lex| lex.slice().to_string())] + #[token("2021/01/20 v 2.00 tkz-graph.sty", |lex| lex.slice().to_string())] + Info(String), - /// TabularArray - TabularWarn(String), + /// Strange starting sequence + #[token("? [1{")] + StartingSequence, - /// Warning level + /// Strange end sequence + #[token(" ){/")] + EndSequence, + + /// Converter [Loading MPS to PDF converter (version 2006.09.02).] + #[token("[Loading MPS to PDF converter")] + MPSConverter, + + /// A chapter was processed + #[regex(r"Chapitre [0-9]+", |lex| lex.slice()[9..].to_string())] + Chapter(String), + + /// Missing reference + #[token(r"LaTeX Warning: Reference")] + MissingReference, + + /// Generic Latex Warning + #[regex(r"(LaTex |Warning:){2}[^\n]+", |lex| lex.slice()[14..].to_string())] Warning(String), + // /// Runaway argument + // #[token("Runaway argument?")] + // RunAway, /// PdfTex VersionThis is pdfTeX, Version 3.141592653-2.6-1.40.22 #[token("This is pdfTeX")] PdfTexVersion, /// Context, mosty for boxes + #[regex(r"\[\d[^\]]+", |lex| lex.slice()[1..lex.slice().len()-1].to_string())] Context(String), /// Overfull and underfull boxes - #[regex("(over|under)full")] + #[regex("(Over|Under)full")] BoxFullness, /// The Latex Version #[regex("LaTeX2e")] @@ -171,44 +191,103 @@ enum LineType { DocumentClass, /// Signals that the parser entered a document - #[regex(r"\(\./\w+\.tex", |lex| lex.slice()[3..].to_string())] + //TODO: Fix name collection + // #[regex(r"(\)+ )?\(\./[A-z/]+\.tex", |lex| lex.slice().split("(").next().unwrap_or("").to_string())] + // #[regex(r"(\)+ )?(\[\w+\])?\(\./[A-z/]+\.tex", |lex| lex.slice().split("(").next().unwrap_or("").to_string())] + + // #[regex(r"[\) ]*\(\./[A-z/]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())] + // #[regex(r"[\) ]*(\[[0-9]+\] )?\(\./[A-z/-_]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())] + // #[regex(r"[\) 0-9\[\]]*\(\./[A-z/-_]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())] + #[regex(r"\(\./[A-z/_-]+\.tex", |lex| lex.slice().split("(").nth(1).unwrap_or("").to_string())] EnteringDocument(String), /// Info on the loading of a library - Library(String), + #[regex(r"Library \(\w+\)[^\n]+", |lex| split_by(":",&lex.slice()[8..]))] + Library((String, String)), + + /// The warning generated by a package + #[regex(r"Package [A-z_-]+ Warning: [^\n]+", |lex| split_by(":",lex.slice()))] + PackageWarning((String, String)), + + /// The warning context generated by a package + #[regex(r"\([A-z_-]+\) [^\n]+", |lex| split_by(")",&lex.slice()[1..]))] + PackageContextWarning((String, String)), /// Loading (Load something) - #[regex(r"(\) )?\(/usr[^)]*", |lex| lex.slice().split("/").last().unwrap_or("").to_string() )] + #[regex(r"(\)+ )?\(/usr[^)]*", |lex| lex.slice().split("/").last().unwrap_or("").to_string())] Loading(String), /// Unknown type Unknown(String), + + /// Building blocks, signals pages being rendered ? + #[token(" []")] + #[token("[]")] + PageGen, + + /// Output + // #[regex(r"Output written on", |lex| lex.slice()[18..].to_string())] + #[token(r"Output written on")] + Output, + + /// Log + // #[regex("Transcript written on [^\n]+", |lex| lex.slice()[18..].to_string())] + #[token("Transcript written on")] + Log, + + // /// Barely parsable data + // #[regex(r"\)+")] + // Garbage, /// Empty line, to discard Empty, + + /// Geometry package + #[token("*geometry* driver: auto-detecting")] + GeometryResolution, + + /// Geometry found + #[token("*geometry* detected driver: pdftex")] + GeometryFound, + + /// Transcript + #[token("(see the transcript file for additional information)")] + Transcript, +} + +/// Tries to split the token and return two string +fn split_by(delim: &str, text: &str) -> Option<(String, String)> { + let mut slice = text.split(delim); + // println!("{:?}", text); + if let Some(one) = slice.next() { + // println!("{:?}", one); + if let Some(two) = slice.next() { + // println!("{} {:?}", one, slice.next()); + return Some((one.to_string(), two.trim_start().to_string())); + } + } + None } /// Check each line and changes the status and/or display according warnings -fn checkline(s: &str, status: &mut Status, context: &mut Vec) -> Result<()> { +fn checkline(s: &str, status: &mut Status, context: &mut [String]) -> Result<()> { // Match the line to guess what is happening let mut lex = LineType::lexer(s); - // println!("{:?}", lex); - // println!("{:?}", lex.next()); let line = match lex.next() { Some(Ok(m)) => m, None => LineType::Empty, - // Some(Err(e)) => { - // return Err(anyhow!( - // "Encountered an error while parsing line {}: {:?}", - // s.to_string(), - // e - // )) - // } _ => LineType::Unknown(s.to_string()), }; match line { - LineType::Warning(w) => println!("{}", w), - LineType::Unknown(w) => println!("Unknown: {}", w), - _ => println!("{:?}", line), + LineType::Unknown(w) => println!("[UKWN] {}", w), + LineType::Empty => (), + LineType::EnteringDocument(_) => println!("{:?}", line), + // LineType::TabWarn(_) => println!("{:?}", line), + // LineType::Library(_) => println!("{:?}", line), + // LineType::PackageWarning(_) => println!("{:?},{}", line, s), + LineType::PackageContextWarning(_) => println!("{:?}", line), + LineType::MissingReference => println!("{:?} {}", line, s), + // LineType::=> (), + _ => (), } Ok(()) }