diskmat-tools/src/main.rs

77 lines
2.0 KiB
Rust

mod boolean_algebra;
mod traits;
mod truthtable;
use boolean_algebra::parser::BAParser;
use truthtable::parser::TTParser;
// use boolean_algebra::parser::parse;
// use clap::Parser;
// use pest::iterators::Pair;
use std::{fs::File, io::Read};
use traits::{graphvizable::Graphvizable, parser::{Pair, Parser}};
/// Simple tool to visualize and process concepts from TMA4140 and MA0301
#[derive(clap::Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
///
// #[clap(with_name)]
// t: String,
/// Input file
#[clap(short = 'i', long)]
input: Option<String>,
/// Input text
#[clap(short = 'e', long)]
input_text: Option<String>,
/// Input type
#[clap(short, long = "type")]
t: Option<String>,
/// Output file
#[clap(short = 'o', long)]
output: Option<String>,
/// Print syntax tree
#[clap(short = 's', long)]
export_syntax_tree: bool,
}
// union Rule {
// ba: boolean_algebra::parser::BARule,
// tt: truthtable::parser::TTRule,
// }
fn main() -> std::io::Result<()> {
let args = <Args as clap::Parser>::parse();
let mut input = String::new();
let root: Pair = if args.input_text.is_some() {
input = args.input_text.unwrap();
match args.t.as_deref() {
Some("ba") => BAParser::parse(&mut input),
Some("tt") => TTParser::parse(&mut input),
_ => panic!("Doesn't recognize file"),
}
// parse(&mut input)
} else if args.input.is_some() {
// } else {
let t = args.input.unwrap();
let mut file = File::open(&t)?;
file.read_to_string(&mut input)?;
match t.split('.').last() {
Some("ba") => BAParser::parse(&mut input),
Some("tt") => TTParser::parse(&mut input),
_ => panic!("Doesn't recognize file"),
}
} else {
panic!("Provide an input");
// Err(std::io::Error::new(std::io::ErrorKind::Other, "Provide some kind of input"))
};
root.print_graphviz_diagram();
Ok(())
}