2019-01-23 09:33:51 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
|
2019-01-24 10:24:20 -05:00
|
|
|
mod dict;
|
2019-01-22 17:01:33 -05:00
|
|
|
|
2019-01-24 10:24:20 -05:00
|
|
|
pub mod identifier;
|
|
|
|
pub mod report;
|
2019-01-23 09:44:01 -05:00
|
|
|
|
2019-01-24 10:24:20 -05:00
|
|
|
pub use crate::dict::*;
|
2019-01-22 17:01:33 -05:00
|
|
|
|
2019-01-24 10:24:20 -05:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
2019-01-23 09:33:51 -05:00
|
|
|
|
2019-01-24 10:24:20 -05:00
|
|
|
pub fn process_file(path: &std::path::Path, dictionary: &Dictionary, report: report::Report) -> Result<(), failure::Error> {
|
2019-01-22 17:01:33 -05:00
|
|
|
let mut buffer = Vec::new();
|
|
|
|
File::open(path)?.read_to_end(&mut buffer)?;
|
|
|
|
for (line_idx, line) in grep_searcher::LineIter::new(b'\n', &buffer).enumerate() {
|
|
|
|
let line_num = line_idx + 1;
|
2019-01-24 10:24:20 -05:00
|
|
|
for token in identifier::tokenize(line) {
|
2019-01-22 17:01:33 -05:00
|
|
|
if let Some(word) = std::str::from_utf8(token.token).ok() {
|
2019-04-16 19:41:07 -04:00
|
|
|
// Correct tokens as-is
|
2019-01-22 17:01:33 -05:00
|
|
|
if let Some(correction) = dictionary.correct_str(word) {
|
2019-01-23 09:33:51 -05:00
|
|
|
let col_num = token.offset;
|
2019-01-24 10:24:20 -05:00
|
|
|
let msg = report::Message {
|
2019-01-23 09:33:51 -05:00
|
|
|
path,
|
|
|
|
line,
|
|
|
|
line_num,
|
|
|
|
col_num,
|
|
|
|
word,
|
|
|
|
correction,
|
2019-01-24 10:24:20 -05:00
|
|
|
non_exhaustive: (),
|
2019-01-23 09:33:51 -05:00
|
|
|
};
|
|
|
|
report(msg);
|
2019-01-22 17:01:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|