diff --git a/.gitignore b/.gitignore index ea8c4bf..df76ce4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +*.pest diff --git a/Cargo.lock b/Cargo.lock index 1c90227..7e190d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,87 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "datetime" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c3f7a77f3e57fedf80e09136f2d8777ebf621207306f6d96d610af048354bc" +dependencies = [ + "libc", + "locale", + "pad", + "redox_syscall", + "winapi", +] + [[package]] name = "grammatical" version = "0.1.0" dependencies = [ + "datetime", "unicode-ident", ] +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "locale" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fdbe492a9c0238da900a1165c42fc5067161ce292678a6fe80921f30fe307fd" +dependencies = [ + "libc", +] + +[[package]] +name = "pad" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ad9b889f1b12e0b9ee24db044b5129150d5eada288edc800f789928dc8c0e3" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 90a72de..09047fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,5 +3,13 @@ name = "grammatical" version = "0.1.0" edition = "2021" +[features] +default = [] +datetime = ["dep:datetime"] +conlang = [] + [dependencies] +datetime = { version = "0.5.2", features = [ + "format", +], default_features = false, optional = true } unicode-ident = "1.0.12" diff --git a/src/conlang.rs b/src/conlang.rs new file mode 100644 index 0000000..be46b35 --- /dev/null +++ b/src/conlang.rs @@ -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}"); +} diff --git a/src/datetime.rs b/src/datetime.rs new file mode 100644 index 0000000..cd75c68 --- /dev/null +++ b/src/datetime.rs @@ -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())) +} diff --git a/src/main.rs b/src/main.rs index 66bae46..841aa4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,25 @@ +use grammatical::*; use std::error::Error; -use grammatical::*; +mod conlang; +mod datetime; fn main() -> Result<(), Box> { - 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(()) }