2019-01-23 07:33:51 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
|
2019-01-24 08:24:20 -07:00
|
|
|
mod dict;
|
2019-06-14 14:53:34 -06:00
|
|
|
mod dict_codegen;
|
2019-01-22 15:01:33 -07:00
|
|
|
|
2019-01-24 08:24:20 -07:00
|
|
|
pub mod report;
|
2019-04-16 20:16:31 -06:00
|
|
|
pub mod tokens;
|
2019-01-23 07:44:01 -07:00
|
|
|
|
2019-01-24 08:24:20 -07:00
|
|
|
pub use crate::dict::*;
|
2019-01-22 15:01:33 -07:00
|
|
|
|
2019-01-24 08:24:20 -07:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
2019-01-23 07:33:51 -07:00
|
|
|
|
2019-06-14 06:43:21 -06:00
|
|
|
pub fn process_file(
|
|
|
|
path: &std::path::Path,
|
|
|
|
dictionary: &Dictionary,
|
|
|
|
report: report::Report,
|
|
|
|
) -> Result<(), failure::Error> {
|
2019-01-22 15:01:33 -07: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-06-22 11:57:23 -06:00
|
|
|
for ident in tokens::Identifier::parse(line) {
|
|
|
|
if let Some(correction) = dictionary.correct_ident(ident) {
|
|
|
|
let col_num = ident.offset();
|
2019-06-14 15:57:41 -06:00
|
|
|
let msg = report::Message {
|
|
|
|
path,
|
|
|
|
line,
|
|
|
|
line_num,
|
|
|
|
col_num,
|
2019-06-22 22:01:27 -06:00
|
|
|
typo: ident.token(),
|
2019-06-14 15:57:41 -06:00
|
|
|
correction,
|
|
|
|
non_exhaustive: (),
|
|
|
|
};
|
|
|
|
report(msg);
|
2019-01-22 15:01:33 -07:00
|
|
|
}
|
2019-06-22 11:57:23 -06:00
|
|
|
for word in ident.split() {
|
2019-06-15 22:21:40 -06:00
|
|
|
if let Some(correction) = dictionary.correct_word(word) {
|
|
|
|
let col_num = word.offset();
|
|
|
|
let msg = report::Message {
|
|
|
|
path,
|
|
|
|
line,
|
|
|
|
line_num,
|
|
|
|
col_num,
|
2019-06-22 22:01:27 -06:00
|
|
|
typo: word.token(),
|
2019-06-15 22:21:40 -06:00
|
|
|
correction,
|
|
|
|
non_exhaustive: (),
|
|
|
|
};
|
|
|
|
report(msg);
|
|
|
|
}
|
|
|
|
}
|
2019-01-22 15:01:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|