Skip to content

Commit 1623519

Browse files
committed
Add (unfinished) support for begnum and endnum
The handling of non-consuming transitions when walking the search graph needs to be improved
1 parent 7f5ca8a commit 1623519

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/translator.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,42 @@ impl TranslationTable {
237237
Boundary::None,
238238
Boundary::NotWord,
239239
),
240+
Rule::Begnum { chars, dots, .. } => translations.insert(
241+
chars.to_string(),
242+
dots_to_unicode(dots),
243+
Boundary::Word,
244+
Boundary::WordNumber,
245+
),
246+
Rule::Midnum { chars, dots, .. } => translations.insert(
247+
chars.to_string(),
248+
dots_to_unicode(dots),
249+
Boundary::Number,
250+
Boundary::Number,
251+
),
252+
Rule::Endnum {
253+
chars,
254+
dots: Braille::Explicit(dots),
255+
..
256+
} => translations.insert(
257+
chars.to_string(),
258+
dots_to_unicode(dots),
259+
Boundary::NumberWord,
260+
Boundary::Word,
261+
),
262+
Rule::Endnum {
263+
chars,
264+
dots: Braille::Implicit,
265+
..
266+
} => translations.insert(
267+
chars.to_string(),
268+
resolve_implicit_dots(&chars, &character_definitions)?,
269+
Boundary::NumberWord,
270+
Boundary::Word,
271+
),
272+
// the base rule is handled in the second pass
273+
Rule::Base { .. } => (),
274+
// display rules are ignored for translation tables
275+
Rule::Display { .. } => (),
240276
_ => (),
241277
}
242278
}
@@ -611,6 +647,37 @@ mod tests {
611647
assert_eq!(table.translate("foo bar foo"), "⠉⠀⠂⠁⠐⠀⠉"); // bar should not be contracted
612648
}
613649

650+
#[test]
651+
#[ignore = "Not implemented properly"]
652+
fn begnum_test() {
653+
let rules = vec![
654+
parse_rule("digit 1 1"),
655+
parse_rule("sign a 3456"),
656+
parse_rule("begnum a 4"),
657+
];
658+
let table = TranslationTable::compile(rules, Direction::Forward).unwrap();
659+
assert_eq!(table.translate("1"), "⠁");
660+
assert_eq!(table.translate("a"), "⠼");
661+
assert_eq!(table.translate("a1"), "⠈⠁");
662+
}
663+
664+
#[test]
665+
#[ignore = "Not implemented properly"]
666+
fn endnum_test() {
667+
let rules = vec![
668+
parse_rule("digit 1 1"),
669+
parse_rule("lowercase h 125"),
670+
parse_rule("lowercase t 2345"),
671+
parse_rule("punctuation . 6"),
672+
parse_rule("always th 14"),
673+
parse_rule("endnum th 15"),
674+
];
675+
let table = TranslationTable::compile(rules, Direction::Forward).unwrap();
676+
assert_eq!(table.translate("th"), "⠉");
677+
assert_eq!(table.translate("1th"), "⠁⠑");
678+
assert_eq!(table.translate("1th."), "⠁⠑⠠");
679+
}
680+
614681
#[test]
615682
fn base_test() {
616683
let rules = vec![

src/translator/trie.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub enum Boundary {
99
Word,
1010
NotWord,
1111
Number,
12+
NumberWord,
13+
WordNumber,
1214
None,
1315
}
1416

0 commit comments

Comments
 (0)