Skip to content

Commit

Permalink
[0.4.2] Use warn!() rather than just println for dictionary-compilati…
Browse files Browse the repository at this point in the history
…on warnings.
  • Loading branch information
jfkthame committed Oct 12, 2020
1 parent 69f6ae4 commit d0d2e86
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[package]
name = "mapped_hyph"
description = "Hyphenation using precompiled memory-mapped tables"
version = "0.4.1"
version = "0.4.2"
authors = ["Jonathan Kew <[email protected]>"]
license = "MIT/Apache-2.0"
edition = "2018"

[dependencies]
memmap = "0.7.0"
arrayref = "0.3.5"
log = "0.4"
env_logger = "0.7.1"

[dev-dependencies]
criterion = "0.3"
Expand Down
2 changes: 2 additions & 0 deletions src/bin/hyf_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
// except according to those terms.

extern crate mapped_hyph;
extern crate env_logger;

use std::env;
use std::fs::File;

fn main() -> std::io::Result<()> {
env_logger::init();
let args: Vec<String> = env::args().collect();
if args.len() == 3 {
let in_file = File::open(&args[1])?;
Expand Down
16 changes: 8 additions & 8 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl LevelBuilder {
for byte in bytes {
if *byte <= b'9' && *byte >= b'0' {
if got_digit {
println!("invalid pattern \"{}\": consecutive digits", pattern);
warn!("invalid pattern \"{}\": consecutive digits", pattern);
return;
}
digits.push(*byte);
Expand Down Expand Up @@ -161,7 +161,7 @@ impl LevelBuilder {
let start = if text[0] == b'.' { 1 } else { 0 };
if start == 1 {
if digits[0] != b'0' {
println!("invalid pattern \"{}\": unexpected digit before start of word", pattern);
warn!("invalid pattern \"{}\": unexpected digit before start of word", pattern);
return;
}
digits.remove(0);
Expand All @@ -178,7 +178,7 @@ impl LevelBuilder {
let mut state_num = self.find_state_number_for(&text);
let mut state = &mut self.states[state_num as usize];
if state.match_string.is_some() {
println!("duplicate pattern \"{}\" discarded", pattern);
warn!("duplicate pattern \"{}\" discarded", pattern);
return;
}
if !digits.is_empty() {
Expand Down Expand Up @@ -389,7 +389,7 @@ fn read_dic_file<T: Read>(dic_file: T, compress: bool) -> Result<Vec<LevelBuilde
if trimmed.contains(' ') {
let parts: Vec<&str> = trimmed.split(' ').collect();
if parts.len() != 2 {
println!("unrecognized keyword/values: {}", trimmed);
warn!("unrecognized keyword/values: {}", trimmed);
continue;
}
let keyword = parts[0];
Expand All @@ -400,7 +400,7 @@ fn read_dic_file<T: Read>(dic_file: T, compress: bool) -> Result<Vec<LevelBuilde
"COMPOUNDLEFTHYPHENMIN" => builder.clh_min = value.parse::<u8>().unwrap(),
"COMPOUNDRIGHTHYPHENMIN" => builder.crh_min = value.parse::<u8>().unwrap(),
"NOHYPHEN" => builder.nohyphen = Some(trimmed),
_ => println!("unknown keyword: {}", trimmed),
_ => warn!("unknown keyword: {}", trimmed),
}
continue;
}
Expand All @@ -410,13 +410,13 @@ fn read_dic_file<T: Read>(dic_file: T, compress: bool) -> Result<Vec<LevelBuilde
builder = builders.last_mut().unwrap();
continue;
}
println!("unknown keyword: {}", trimmed);
warn!("unknown keyword: {}", trimmed);
continue;
}
// Patterns should always be provided in lowercase; complain if not, and discard
// the bad pattern.
if trimmed != trimmed.to_lowercase() {
println!("pattern \"{}\" not lowercased at line {}", trimmed, index);
warn!("pattern \"{}\" not lowercased at line {}", trimmed, index);
continue;
}
builder.add_pattern(&trimmed);
Expand Down Expand Up @@ -502,7 +502,7 @@ pub fn compile<T1: Read, T2: Write>(dic_file: T1, hyf_file: &mut T2, compress: b
match read_dic_file(dic_file, compress) {
Ok(dic) => write_hyf_file(hyf_file, dic),
Err(e) => {
println!("parse error: {}", e);
warn!("parse error: {}", e);
return Err(Error::from(ErrorKind::InvalidData))
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#[macro_use]
extern crate arrayref;
extern crate memmap;
#[macro_use]
extern crate log;

use std::slice;
use std::str;
Expand Down

0 comments on commit d0d2e86

Please sign in to comment.