refactor main

This commit is contained in:
notafile 2022-01-04 17:24:21 +01:00
parent ed3ff17c89
commit 76d24042ce
2 changed files with 21 additions and 2 deletions

View File

@ -3,14 +3,29 @@ mod parser;
mod rtlil;
use nom::error::{convert_error, VerboseError};
use std::path::PathBuf;
use std::fs::File;
use std::io::prelude::*;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(name = "example", about = "An example of StructOpt usage.")]
struct Opt {
/// Input file
#[structopt(parse(from_os_str))]
input: PathBuf,
}
// custom IResult type for verboseerror
pub type IResult<I, O, E = VerboseError<I>> = nom::IResult<I, O, E>;
fn main() {
let input = include_str!("../identity.fut");
let parsed = parser::module(input);
let opt = Opt::from_args();
let mut infile = File::open(opt.input).expect("could not open file");
let mut input = String::new();
infile.read_to_string(&mut input).expect("error reading file");
let input: &str = input.as_str();
let parsed = parser::parse(&input);
match parsed {
Err(nom::Err::Error(err) | nom::Err::Failure(err)) => {
print!("{}", convert_error(input, err))

View File

@ -204,6 +204,10 @@ pub fn module(input: &str) -> IResult<&str, Module> {
)(input)
}
fn parse(input: &str) -> IResult<&str, Module> {
module(input)
}
#[cfg(test)]
mod test {
use super::*;