Cleaning up the mess with logos
This commit is contained in:
parent
8b110c9d6d
commit
8f113ffdc3
|
|
@ -15,6 +15,7 @@ dynfmt = { version = "0.1.5", features = ["curly"] }
|
|||
enum_dispatch = "0.3.13"
|
||||
futures = "0.3.30"
|
||||
glob = "0.3.1"
|
||||
logos = "0.14.0"
|
||||
phf = { version = "0.11.2", features = ["macros"] }
|
||||
regex = "1.10.5"
|
||||
regex_static = "0.1.1"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
//! Make a pdf using pdflatex
|
||||
|
||||
// use std::fmt::Display;
|
||||
use logos::Logos;
|
||||
use std::str;
|
||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||
use tokio::process::Command;
|
||||
|
|
@ -74,7 +75,7 @@ async fn launch_subprocess(args: &MakeConfig) -> Result<Status> {
|
|||
let mut status = Status::zero();
|
||||
let mut context = Vec::new();
|
||||
cmd.arg(&args.filename);
|
||||
cmd.env("max_print_line", "1000");
|
||||
cmd.env("max_print_line", "3000");
|
||||
|
||||
// Specify that we want the command's standard output piped back to us.
|
||||
cmd.stdout(Stdio::piped());
|
||||
|
|
@ -126,68 +127,88 @@ async fn launch_subprocess(args: &MakeConfig) -> Result<Status> {
|
|||
|
||||
/// The line encountered
|
||||
// #[allow(unused)]
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Logos, PartialEq)]
|
||||
// #[logos()]
|
||||
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,
|
||||
|
||||
/// TabularArray
|
||||
//TODO: Change to size and not full line ?
|
||||
TabularWarn(String),
|
||||
|
||||
/// Warning level
|
||||
Warning(String),
|
||||
/// PdfTex Version
|
||||
PdfTexVersion(String),
|
||||
|
||||
/// PdfTex VersionThis is pdfTeX, Version 3.141592653-2.6-1.40.22
|
||||
#[token("This is pdfTeX")]
|
||||
PdfTexVersion,
|
||||
|
||||
/// Context, mosty for boxes
|
||||
Context(String),
|
||||
|
||||
/// Overfull and underfull boxes
|
||||
#[regex("(over|under)full")]
|
||||
BoxFullness,
|
||||
/// The Latex Version
|
||||
#[regex("LaTeX2e")]
|
||||
LaTexVersion,
|
||||
/// The write18 mode, whatever that is
|
||||
#[token(" restricted \\write18 enabled.")]
|
||||
WriteMode,
|
||||
|
||||
/// The class of document (book, article, etc)
|
||||
// s if s.starts_with("Document Class") => LineType::DocumentClass(s.to_string()),
|
||||
#[token("Document Class:")]
|
||||
DocumentClass,
|
||||
|
||||
/// Signals that the parser entered a document
|
||||
#[regex(r"\(\./\w+\.tex", |lex| lex.slice()[3..].to_string())]
|
||||
EnteringDocument(String),
|
||||
|
||||
/// Info on the loading of a library
|
||||
Library(String),
|
||||
|
||||
/// Loading (Load something)
|
||||
#[regex(r"(\) )?\(/usr[^)]*", |lex| lex.slice().split("/").last().unwrap_or("").to_string() )]
|
||||
Loading(String),
|
||||
|
||||
/// Unknown type
|
||||
Unknown(String),
|
||||
/// Empty line, to discard
|
||||
Empty,
|
||||
/// The Latex Version
|
||||
LaTexVersion(String),
|
||||
/// The write18 mode, whatever that is
|
||||
WriteMode(String),
|
||||
/// The class of document (book, article, etc)
|
||||
DocumentClass(String),
|
||||
/// Signals that the parser entered a document
|
||||
EnteringDocument(String),
|
||||
/// Info on the loading of a library
|
||||
Library(String),
|
||||
/// Loading (Load something)
|
||||
Loading(String),
|
||||
}
|
||||
|
||||
/// Check each line and changes the status and/or display according warnings
|
||||
fn checkline(s: &str, status: &mut Status, context: &mut Vec<String>) -> Result<()> {
|
||||
// Match the line to guess what is happening
|
||||
let line = match s {
|
||||
s if s.starts_with("entering_extended_mode") => LineType::Mode,
|
||||
s if s.starts_with("entering extended mode") => LineType::Mode,
|
||||
s if s.starts_with("This is pdfTeX") => LineType::PdfTexVersion(s.to_string()),
|
||||
s if s.starts_with("LaTeX2e") => LineType::LaTexVersion(s.to_string()),
|
||||
s if s.starts_with("Package tabularray Warning") => LineType::TabularWarn(s.to_string()),
|
||||
s if s.starts_with("Overfull") => LineType::BoxFullness,
|
||||
s if s.starts_with("Underfull") => LineType::BoxFullness,
|
||||
s if s.starts_with("L3 programming layer") => LineType::Info,
|
||||
s if s.starts_with(" restricted \\write18 enabled.") => LineType::Context(s.to_string()),
|
||||
s if s.starts_with(" [") => LineType::WriteMode(s.to_string()),
|
||||
s if s.starts_with("Document Class") => LineType::DocumentClass(s.to_string()),
|
||||
s if s.starts_with("Library") => LineType::Library(s.to_string()),
|
||||
s if s.starts_with("(./") => LineType::EnteringDocument(s.to_string()),
|
||||
s if s.starts_with("(/usr/share/texlive/") => LineType::Loading(s.to_string()),
|
||||
// "LaTeX Warning: Reference"
|
||||
"" => LineType::Empty,
|
||||
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()),
|
||||
};
|
||||
// status.warnings += 1;
|
||||
match line {
|
||||
LineType::Warning(w) => println!("{}", w),
|
||||
LineType::Unknown(w) => println!("Unknown: {}", w),
|
||||
_ => (),
|
||||
_ => println!("{:?}", line),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue