diff options
Diffstat (limited to '')
-rw-r--r-- | isabelle-dump/Cargo.lock | 464 | ||||
-rw-r--r-- | isabelle-dump/Cargo.toml | 17 | ||||
-rw-r--r-- | isabelle-dump/build.rs | 13 | ||||
-rw-r--r-- | isabelle-dump/src/calc.l | 5 | ||||
-rw-r--r-- | isabelle-dump/src/calc.y | 54 | ||||
-rw-r--r-- | isabelle-dump/src/main.rs | 71 |
6 files changed, 624 insertions, 0 deletions
diff --git a/isabelle-dump/Cargo.lock b/isabelle-dump/Cargo.lock new file mode 100644 index 0000000..2f0d1ca --- /dev/null +++ b/isabelle-dump/Cargo.lock @@ -0,0 +1,464 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "cactus" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf034765b7d19a011c6d619e880582bf95e8186b580e6fab56589872dd87dcf5" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfgrammar" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c63bd74c5d141c1ff743fad7e1c56e50d934131f503b048324b0eb68549376d8" +dependencies = [ + "indexmap", + "lazy_static", + "num-traits", + "regex", + "serde", + "vob", +] + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + +[[package]] +name = "filetime" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "winapi", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + +[[package]] +name = "indexmap" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "isabelle-dump" +version = "0.1.0" +dependencies = [ + "cfgrammar", + "lrlex", + "lrpar", + "symbolmacro", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" + +[[package]] +name = "lrlex" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccc0ee64acad6ea2e83d152de81c845523a8eedbed67cad6ebeec7058e87c1a" +dependencies = [ + "getopts", + "lazy_static", + "lrpar", + "num-traits", + "regex", + "try_from", +] + +[[package]] +name = "lrpar" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56b920e6cef1188595dc4e6e3ffcc9a81ffc9801af5582df49fa3ade23350f71" +dependencies = [ + "bincode", + "cactus", + "cfgrammar", + "filetime", + "indexmap", + "lazy_static", + "lrtable", + "num-traits", + "packedvec", + "regex", + "serde", + "static_assertions", + "vergen", + "vob", +] + +[[package]] +name = "lrtable" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48212e9df591939f87311b824ff21ea93310f8ec2b06459139bdbd7feb067ad2" +dependencies = [ + "cfgrammar", + "fnv", + "num-traits", + "serde", + "sparsevec", + "static_assertions", + "try_from", + "vob", +] + +[[package]] +name = "memchr" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "packedvec" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330ecfcb0ad33d2e3fb49bc09742dab081112272c8252c5b5bf760f96d8d2b7f" +dependencies = [ + "num-traits", + "serde", +] + +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "proc-macro2" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.3", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f3aac57ee7f3272d8395c6e4f502f434f0e289fcd62876f70daa008c20dcabe" + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + +[[package]] +name = "serde" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sparsevec" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a182a1fc36753f8a2e3eea04cc3cd28065d2949cbda1e3a453cd183dace42bbb" +dependencies = [ + "num-traits", + "packedvec", + "serde", + "vob", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "symbolmacro" +version = "0.1.0" + +[[package]] +name = "syn" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]] +name = "try_from" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" +dependencies = [ + "cfg-if 0.1.10", +] + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "vergen" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7141e445af09c8919f1d5f8a20dae0b20c3b57a45dee0d5823c6ed5d237f15a" +dependencies = [ + "bitflags", + "chrono", + "rustc_version 0.4.0", +] + +[[package]] +name = "vob" +version = "2.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8af6d79df9ae93c259d5d076bad5741c3dd650bc10a13dd83704b0c29a280f15" +dependencies = [ + "num-traits", + "rustc_version 0.3.3", + "serde", +] + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[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/isabelle-dump/Cargo.toml b/isabelle-dump/Cargo.toml new file mode 100644 index 0000000..924737f --- /dev/null +++ b/isabelle-dump/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "isabelle-dump" +version = "0.1.0" +authors = ["stuebinm <stuebinm@disroot.org>"] +edition = "2018" + + +[build-dependencies] +cfgrammar = "0.10" +lrlex = "0.10" +lrpar = "0.10" + +[dependencies] +cfgrammar = "0.10" +lrlex = "0.10" +lrpar = "0.10" +symbolmacro = { path = "../symbolmacro", version = "0.1" } diff --git a/isabelle-dump/build.rs b/isabelle-dump/build.rs new file mode 100644 index 0000000..b11761d --- /dev/null +++ b/isabelle-dump/build.rs @@ -0,0 +1,13 @@ +use cfgrammar::yacc::YaccKind; +use lrlex::LexerBuilder; +use lrpar::{CTParserBuilder}; + +fn main() -> Result<(), Box<dyn std::error::Error>> { + let lex_rule_ids_map = CTParserBuilder::new() + .yacckind(YaccKind::Grmtools) + .process_file_in_src("calc.y")?; + LexerBuilder::new() + .rule_ids_map(lex_rule_ids_map) + .process_file_in_src("calc.l")?; + Ok(()) +} diff --git a/isabelle-dump/src/calc.l b/isabelle-dump/src/calc.l new file mode 100644 index 0000000..2bf98dc --- /dev/null +++ b/isabelle-dump/src/calc.l @@ -0,0 +1,5 @@ +%% +\\ "AOPEN" +< "LT" +<[^\\<>]+> "NAME" +[^<\\][^\\]* "TEXT" diff --git a/isabelle-dump/src/calc.y b/isabelle-dump/src/calc.y new file mode 100644 index 0000000..2dd3bd3 --- /dev/null +++ b/isabelle-dump/src/calc.y @@ -0,0 +1,54 @@ +%start AbbrList + +%% + +AbbrList -> Result<Vec<Isabelle>, ()>: + Text { Ok(vec![Isabelle::Text($1?)]) } + | Abbr { Ok(vec![Isabelle::Symbol($1?)]) } + | AbbrList Abbr + { + let mut $1 = $1?; + $1.push(Isabelle::Symbol($2?)); + Ok($1) + } + | AbbrList Text + { + let mut $1 = $1?; + $1.push(Isabelle::Text($2?)); + Ok($1) + } + ; + +Abbr -> Result<String, ()>: + 'AOPEN' Name { Ok($2?) } + ; + +Text -> Result<String, ()>: + 'TEXT' + { + let v = $1.map_err(|_| ())?; + Ok($lexer.span_str(v.span()).to_string()) + } + | 'AOPEN' + { + //let v = $2.map_err(|_| ())?; + Ok("\\".to_string()) + } + | 'LT' + { + //let v = $2.map_err(|_| ())?; + Ok("<".to_string()) //format!("<{}", $lexer.span_str(v.span()))) + } + ; + +Name -> Result<String, ()>: + 'NAME' + { + let v = $1.map_err(|_| ())?; + let name = $lexer.span_str(v.span()); + Ok(name[1..name.len()-1].to_string()) + } + ; +%% + +use crate::Isabelle; diff --git a/isabelle-dump/src/main.rs b/isabelle-dump/src/main.rs new file mode 100644 index 0000000..891108f --- /dev/null +++ b/isabelle-dump/src/main.rs @@ -0,0 +1,71 @@ +use std::io::{self, BufRead, Write}; + +use lrlex::lrlex_mod; +use lrpar::lrpar_mod; + +#[derive(Debug)] +pub enum Isabelle { + Symbol(String), + Text(String), +} + + +lrlex_mod!("calc.l"); +lrpar_mod!("calc.y"); + + +symbolmacro::make_symbols!(); + + +fn main() { + // Get the `LexerDef` for the `calc` language. + let lexerdef = calc_l::lexerdef(); + let stdin = io::stdin(); + loop { + io::stdout().flush().ok(); + match stdin.lock().lines().next() { + Some(Ok(ref l)) => { + if l.trim().is_empty() { + println!(""); + continue; + } + let lexer = lexerdef.lexer(l); + let (res, errs) = calc_y::parse(&lexer); + for e in errs { + eprintln!( + "{}", + e.pp(&lexer, &calc_y::token_epp) + ); + } + match res { + Some(r) => { + //eprintln!("Result: {:?}", r); + let rendered = r + .unwrap() + .iter() + .map(|token| match token { + Isabelle::Text(ref t) => + t, + Isabelle::Symbol(name) => + symbol(name) + .unwrap_or_else(|| { + Box::leak( + format!("\\<{}>", name) + .into() + ) + }) + }) + .collect::<Vec<&str>>() + .join(""); + println!("{}", rendered); + } + _ => { + eprintln!("could not parse file (probably spurious \\, <, or >)"); + std::process::exit(1); + } + } + } + _ => break, + } + } +} |