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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
macro_rules! encode_space_arm {
($tokens:ident, $out:ident, $prev_was_number:ident, $numeric_mode:ident, $skip_to:ident, $line_mode_active:ident, $preserve_spatial_newlines:ident, $flatten_line_layout:ident, $spatial_grade1_passage:ident, $poem_linear_context:ident, $collapse_prose_double_space:ident, $skip_flattened_line_indent:ident, $numeric_separator_count:ident, $i:ident) => {
{
if $poem_linear_context && $out.is_empty() {
$prev_was_number = false;
$numeric_mode = false;
continue;
}
if $flatten_line_layout && $out.is_empty() {
$prev_was_number = false;
$numeric_mode = false;
continue;
}
if $skip_flattened_line_indent {
$prev_was_number = false;
$numeric_mode = false;
continue;
}
if matches!(
(
$i.checked_sub(1).and_then(|p| $tokens.get(p)),
$tokens.get($i + 1)
),
(Some(EnglishToken::Symbol('_')), Some(EnglishToken::Symbol('_')))
) {
$prev_was_number = false;
$numeric_mode = false;
$line_mode_active = false;
continue;
}
if is_numeric_space($tokens, $i) {
$numeric_separator_count += 1;
$skip_to = encode_following_number_as_numeric_space(
$tokens,
$i,
&mut $out,
$numeric_separator_count == 6,
)?;
$prev_was_number = true;
$numeric_mode = true;
$line_mode_active = false;
continue;
}
// §15.2.1 scansion notation (`. - . - / . . - -`): a space
// between two scansion marks (`.`, `-`, `/`) collapses in
// braille so the metrical pattern reads as one unbroken run
// of `⠲⠤⠸⠌…`. Detected by both flanking tokens being scansion
// symbols — a broader (letter-containing) prose context is
// left alone.
let is_scan = |t: Option<&EnglishToken>| {
matches!(t, Some(EnglishToken::Symbol('.' | '-' | '/')))
};
if is_scan($i.checked_sub(1).and_then(|p| $tokens.get(p)))
&& is_scan($tokens.get($i + 1))
{
$prev_was_number = false;
$numeric_mode = false;
continue;
}
if bibliography_entry_context($tokens)
&& matches!($tokens.get($i + 1), Some(EnglishToken::Space))
&& matches!(
$i.checked_sub(1).and_then(|p| $tokens.get(p)),
Some(EnglishToken::Symbol('.' | ':') | EnglishToken::Styled('.', _))
)
{
$out.push(SPACE);
$skip_to = $i + 2;
$prev_was_number = false;
$numeric_mode = false;
continue;
}
// §12.4/§7 prose: collapse a double space between prose
// words (`not: For`) to one cell. A wider gap or column
// context (`has_wide_space_run`) is preserved. Skip the
// collapse inside a Korean context — Korean tests use the
// legacy path but land here for Latin-embedded inputs like
// `1in는 2.54cm이다.`, where the token stream contains no
// multi-space runs and this branch would be a no-op anyway.
if $collapse_prose_double_space
&& matches!($tokens.get($i + 1), Some(EnglishToken::Space))
&& styled_prose_double_space($tokens, $i)
{
$prev_was_number = false;
$numeric_mode = false;
continue;
}
if $preserve_spatial_newlines {
let mut end = $i;
while matches!($tokens.get(end), Some(EnglishToken::Space)) {
end += 1;
}
if matches!($i.checked_sub(1).and_then(|p| $tokens.get(p)), Some(EnglishToken::Symbol('│')))
&& matches!($tokens.get(end), Some(EnglishToken::Symbol('│')))
&& end - $i >= 10
{
$out.extend(std::iter::repeat_n(SPACE, end - $i - 1));
$skip_to = end;
$prev_was_number = false;
$numeric_mode = false;
$line_mode_active = false;
continue;
}
if matches!($i.checked_sub(1).and_then(|p| $tokens.get(p)), Some(EnglishToken::Symbol('┐' | '┘')))
&& matches!($tokens.get(end), Some(EnglishToken::Symbol('┌' | '└')))
&& end - $i >= 5
{
$out.extend(std::iter::repeat_n(SPACE, end - $i + 1));
$skip_to = end;
$prev_was_number = false;
$numeric_mode = false;
$line_mode_active = false;
continue;
}
if $spatial_grade1_passage
&& matches!($i.checked_sub(1).and_then(|p| $tokens.get(p)), Some(EnglishToken::Symbol('╲' | '╱')))
&& matches!($tokens.get(end), Some(EnglishToken::Symbol('│')))
{
$out.extend(std::iter::repeat_n(SPACE, end - $i - 1));
$skip_to = end;
$prev_was_number = false;
$numeric_mode = false;
$line_mode_active = false;
continue;
}
}
if let Some((end, dots)) = wide_table_gap_before_word($tokens, $i) {
$out.push(SPACE);
$out.extend(std::iter::repeat_n(decode_unicode('⠐'), dots));
$out.extend([SPACE, SPACE]);
$skip_to = end;
$prev_was_number = false;
$numeric_mode = false;
$line_mode_active = false;
continue;
}
if let Some(end) = styled_column_gap($tokens, $i) {
$out.push(SPACE);
$skip_to = end;
$prev_was_number = false;
$numeric_mode = false;
$line_mode_active = false;
continue;
}
if let Some((end, dots)) = wide_table_gap_before_number($tokens, $i) {
// §16.5.1: a wide blank run between a row label and a numeric
// column is guide-dot space. Keep a blank cell before and
// after the dot-5 run so the columns remain visually aligned.
// For a 3+ digit number (dots=0), the gap collapses to a single
// blank cell — the wide number already reaches the column edge.
$out.push(SPACE);
if dots > 0 {
$out.extend(std::iter::repeat_n(decode_unicode('⠐'), dots));
$out.extend(std::iter::repeat_n(SPACE, (end - $i).saturating_sub(5).max(2)));
}
$skip_to = end;
$prev_was_number = false;
$numeric_mode = false;
$line_mode_active = false;
continue;
}
if $preserve_spatial_newlines
&& $line_mode_active
&& matches!(
$i.checked_sub(1).and_then(|p| $tokens.get(p)),
Some(EnglishToken::Symbol('┼'))
)
{
let mut end = $i;
while matches!($tokens.get(end), Some(EnglishToken::Space)) {
end += 1;
}
if matches!($tokens.get(end), Some(EnglishToken::Symbol(c)) if super::rule_16::is_line_char(*c)) {
$out.push(SPACE);
$skip_to = end;
$prev_was_number = false;
$numeric_mode = false;
$line_mode_active = false;
continue;
}
}
$out.push(SPACE);
$prev_was_number = false;
$numeric_mode = false;
$numeric_separator_count = 0;
$line_mode_active = false;
}
};
}