1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#[macro_use]
extern crate serde_derive;
use std::fs::{ File };
use std::io::{ BufRead, BufReader };

pub mod flex;
pub mod io;
pub mod mapper;

macro_rules! args {
    ($m:expr, $ma:ident, $w:ident) => {
        Ok(Args {
            mapper: Some($m),
            mapper_arg: $ma,
            words: $w
        })
    };
}

pub fn load_flex_file(file_name: &str) -> Result<Vec<String>, String> {
    match File::open(file_name) {
        Ok(f) => {
            let reader = BufReader::new(f);
            let lines = reader.lines();
            let mut ln: Vec<String> = vec![];
            for line in lines {
                ln.push(line.unwrap());
            }
            Ok(ln)
        },
        Err(_e) => Err("The FlexMapper needs two lines in the flex file.".to_string())
    }
}