Add friendlier output where possible

This commit is contained in:
2024-04-06 07:09:21 -05:00
parent 8f8cfd4cb5
commit ab0a3f0cc2
6 changed files with 118 additions and 8 deletions

7
src/conlang.rs Normal file
View File

@@ -0,0 +1,7 @@
#[cfg(feature = "conlang")]
const CONLANG_SUPPLEMENTAL: &str = include_str!("conlang-supplemental.pest");
pub fn print_supplemental() {
#[cfg(feature = "conlang")]
println!("\n// CONLANG_SUPPLEMENTAL\n{CONLANG_SUPPLEMENTAL}");
}

16
src/datetime.rs Normal file
View File

@@ -0,0 +1,16 @@
#[cfg(feature = "datetime")]
use datetime::{LocalDateTime, ISO};
#[cfg(feature = "datetime")]
struct Now(LocalDateTime);
#[cfg(feature = "datetime")]
impl std::fmt::Display for Now {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
pub fn print_current_time() {
#[cfg(feature = "datetime")]
println!("// Generated {}", Now(LocalDateTime::now()))
}

View File

@@ -1,19 +1,25 @@
use grammatical::*;
use std::error::Error;
use grammatical::*;
mod conlang;
mod datetime;
fn main() -> Result<(), Box<dyn Error>> {
for file in std::env::args().skip(1) {
datetime::print_current_time();
let args: Vec<_> = std::env::args().skip(1).collect();
if args.is_empty() {
for line in std::io::stdin().lines() {
let line = line?;
let mut p = Parser::new(&line);
parse(&mut p);
}
}
for file in args {
let file = std::fs::read_to_string(file)?;
let mut p = Parser::new(&file);
parse(&mut p);
}
for line in std::io::stdin().lines() {
let line = line?;
let mut p = Parser::new(&line);
parse(&mut p);
}
conlang::print_supplemental();
Ok(())
}