From ad514f56b6cda288e605c44990ef16d30e6dee53 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 2 Sep 2021 23:31:39 +0200 Subject: remove grmtools the parser using grmtools was way oversized for just doing escape sequences, and only really existed since I wanted to play around with it. The new implementation depends on no external crates, uses just an iter wrapped into a nicely composable function, and appears to be exactly equivalent (but faster). --- isabelle-dump/src/calc.l | 5 ---- isabelle-dump/src/calc.y | 54 ----------------------------------- isabelle-dump/src/main.rs | 71 ----------------------------------------------- 3 files changed, 130 deletions(-) delete mode 100644 isabelle-dump/src/calc.l delete mode 100644 isabelle-dump/src/calc.y delete mode 100644 isabelle-dump/src/main.rs (limited to 'isabelle-dump/src') diff --git a/isabelle-dump/src/calc.l b/isabelle-dump/src/calc.l deleted file mode 100644 index 2bf98dc..0000000 --- a/isabelle-dump/src/calc.l +++ /dev/null @@ -1,5 +0,0 @@ -%% -\\ "AOPEN" -< "LT" -<[^\\<>]+> "NAME" -[^<\\][^\\]* "TEXT" diff --git a/isabelle-dump/src/calc.y b/isabelle-dump/src/calc.y deleted file mode 100644 index 2dd3bd3..0000000 --- a/isabelle-dump/src/calc.y +++ /dev/null @@ -1,54 +0,0 @@ -%start AbbrList - -%% - -AbbrList -> Result, ()>: - 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: - 'AOPEN' Name { Ok($2?) } - ; - -Text -> Result: - '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: - '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 deleted file mode 100644 index 891108f..0000000 --- a/isabelle-dump/src/main.rs +++ /dev/null @@ -1,71 +0,0 @@ -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::>() - .join(""); - println!("{}", rendered); - } - _ => { - eprintln!("could not parse file (probably spurious \\, <, or >)"); - std::process::exit(1); - } - } - } - _ => break, - } - } -} -- cgit v1.2.3