Debian Codegraph @

intl/icu/source/data/brkitr/rules/line.txt

raw
1 # Copyright (C) 2016 and later: Unicode, Inc. and others.
2 # License & terms of use: http://www.unicode.org/copyright.html
3 # Copyright (c) 2002-2016 International Business Machines Corporation and
4 # others. All Rights Reserved.
5 #
6 # file: line.txt
7 #
8 # Line Breaking Rules
9 # Implement default line breaking as defined by
10 # Unicode Standard Annex #14 (https://www.unicode.org/reports/tr14/)
11 # for Unicode 14.0, with the following modification:
12 #
13 # Boundaries between hyphens and following letters are suppressed when
14 # there is a boundary preceding the hyphen. See rule 20.9
15 #
16 # This corresponds to CSS line-break=strict (BCP47 -u-lb-strict).
17 # It sets characters of class CJ to behave like NS.
18
19 #
20 # Character Classes defined by TR 14.
21 #
22
23 !!chain;
24 !!quoted_literals_only;
25
26 $AI = [:LineBreak = Ambiguous:];
27 $AK = [:LineBreak = Aksara:];
28 $AL = [:LineBreak = Alphabetic:];
29 $AP = [:LineBreak = Aksara_Prebase:];
30 $AS = [:LineBreak = Aksara_Start:];
31 $BA = [:LineBreak = Break_After:];
32 $HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA.
33 $BB = [:LineBreak = Break_Before:];
34 $BK = [:LineBreak = Mandatory_Break:];
35 $B2 = [:LineBreak = Break_Both:];
36 $CB = [:LineBreak = Contingent_Break:];
37 $CJ = [:LineBreak = Conditional_Japanese_Starter:];
38 $CL = [:LineBreak = Close_Punctuation:];
39 # $CM = [:LineBreak = Combining_Mark:];
40 $CP = [:LineBreak = Close_Parenthesis:];
41 $CR = [:LineBreak = Carriage_Return:];
42 $EB = [:LineBreak = EB:];
43 $EM = [:LineBreak = EM:];
44 $EX = [:LineBreak = Exclamation:];
45 $GL = [:LineBreak = Glue:];
46 $HL = [:LineBreak = Hebrew_Letter:];
47 $HY = [:LineBreak = Hyphen:];
48 $H2 = [:LineBreak = H2:];
49 $H3 = [:LineBreak = H3:];
50 $ID = [:LineBreak = Ideographic:];
51 $IN = [:LineBreak = Inseperable:];
52 $IS = [:LineBreak = Infix_Numeric:];
53 $JL = [:LineBreak = JL:];
54 $JV = [:LineBreak = JV:];
55 $JT = [:LineBreak = JT:];
56 $LF = [:LineBreak = Line_Feed:];
57 $NL = [:LineBreak = Next_Line:];
58 # NS includes CJ for CSS strict line breaking.
59 $NS = [[:LineBreak = Nonstarter:] $CJ];
60 $NU = [:LineBreak = Numeric:];
61 $OP = [:LineBreak = Open_Punctuation:];
62 $PO = [:LineBreak = Postfix_Numeric:];
63 $PR = [:LineBreak = Prefix_Numeric:];
64 $QU = [:LineBreak = Quotation:];
65 $RI = [:LineBreak = Regional_Indicator:];
66 $SA = [:LineBreak = Complex_Context:];
67 $SG = [:LineBreak = Surrogate:];
68 $SP = [:LineBreak = Space:];
69 $SY = [:LineBreak = Break_Symbols:];
70 $VF = [:LineBreak = Virama_Final:];
71 $VI = [:LineBreak = Virama:];
72 $WJ = [:LineBreak = Word_Joiner:];
73 $XX = [:LineBreak = Unknown:];
74 $ZW = [:LineBreak = ZWSpace:];
75 $ZWJ = [:LineBreak = ZWJ:];
76
77 $EastAsian = [\p{ea=F}\p{ea=W}\p{ea=H}];
78
79 $ExtPictUnassigned = [\p{Extended_Pictographic} & \p{Cn}];
80
81 # By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
82 # list it in the numerous rules that use CM.
83 # By LB1, SA characters with general categor of Mn or Mc also resolve to CM.
84
85 $CM = [[:LineBreak = Combining_Mark:] $ZWJ [$SA & [[:Mn:][:Mc:]]]];
86 $CMX = [[$CM] - [$ZWJ]];
87
88 # Dictionary character set, for triggering language-based break engines. Currently
89 # limited to LineBreak=Complex_Context (SA).
90
91 $dictionary = [$SA];
92
93 #
94 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
95 # SA (Dictionary chars, excluding Mn and Mc)
96 # SG (Unpaired Surrogates)
97 # XX (Unknown, unassigned)
98 # as $AL (Alphabetic)
99 #
100 $ALPlus = [$AL $AI $SG $XX [$SA-[[:Mn:][:Mc:]]]];
101
102
103 ## -------------------------------------------------
104
105 #
106 # CAN_CM is the set of characters that may combine with CM combining chars.
107 # Note that Linebreak UAX 14's concept of a combining char and the rules
108 # for what they can combine with are _very_ different from the rest of Unicode.
109 #
110 # Note that $CM itself is left out of this set. If CM is needed as a base
111 # it must be listed separately in the rule.
112 #
113 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
114 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
115
116 #
117 # AL_FOLLOW set of chars that can unconditionally follow an AL
118 # Needed in rules where stand-alone $CM s are treated as AL.
119 #
120 $AL_FOLLOW = [$BK $CR $LF $NL $ZW $SP $CL $CP $EX $HL $IS $SY $WJ $GL [$OP - $EastAsian] $QU $BA $HY $NS $IN $NU $PR $PO $ALPlus];
121
122
123 #
124 # Rule LB 4, 5 Mandatory (Hard) breaks.
125 #
126 $LB4Breaks = [$BK $CR $LF $NL];
127 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
128 $CR $LF {100};
129
130 #
131 # LB 6 Do not break before hard line breaks.
132 #
133 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
134 $CAN_CM $CM* $LB4Breaks {100};
135 ^$CM+ $LB4Breaks {100};
136
137 # LB 7 x SP
138 # x ZW
139 $LB4NonBreaks [$SP $ZW];
140 $CAN_CM $CM* [$SP $ZW];
141 ^$CM+ [$SP $ZW];
142
143 #
144 # LB 8 Break after zero width space
145 # ZW SP* ÷
146 #
147 $LB8Breaks = [$LB4Breaks $ZW];
148 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
149 $ZW $SP* / [^$SP $ZW $LB4Breaks];
150
151 # LB 8a ZWJ x Do not break Emoji ZWJ sequences.
152 #
153 $ZWJ [^$CM];
154
155 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
156 # $CM not covered by the above needs to behave like $AL
157 # See definition of $CAN_CM.
158
159 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
160 ^$CM+;
161
162 #
163 # LB 11 Do not break before or after WORD JOINER & related characters.
164 #
165 $CAN_CM $CM* $WJ;
166 $LB8NonBreaks $WJ;
167 ^$CM+ $WJ;
168
169 $WJ $CM* .;
170
171 #
172 # LB 12 Do not break after NBSP and related characters.
173 # GL x
174 #
175 $GL $CM* .;
176
177 #
178 # LB 12a Do not break before NBSP and related characters ...
179 # [^SP BA HY] x GL
180 #
181 [[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GL;
182 ^$CM+ $GL;
183
184
185
186
187 # LB 13 Don't break before ']' or '!' or '/', even after spaces.
188 #
189 $LB8NonBreaks $CL;
190 $CAN_CM $CM* $CL;
191 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
192
193 $LB8NonBreaks $CP;
194 $CAN_CM $CM* $CP;
195 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
196
197 $LB8NonBreaks $EX;
198 $CAN_CM $CM* $EX;
199 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
200
201 $LB8NonBreaks $SY;
202 $CAN_CM $CM* $SY;
203 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
204
205
206 #
207 # LB 14 Do not break after OP, even after spaces
208 # Note subtle interaction with "SP IS /" rules in LB14a.
209 # This rule consumes the SP, chaining happens on the IS, effectivley overriding the SP IS rules,
210 # which is the desired behavior.
211 #
212 $OP $CM* $SP* .;
213
214 $OP $CM* $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
215 # by rule 8, CM following a SP is stand-alone.
216
217
218 # LB 15a
219 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ .;
220 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
221 ^([\p{Pi} & $QU] $CM* $SP*)+ .;
222 ^([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
223
224 # LB 15b
225 $LB8NonBreaks [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}];
226 $CAN_CM $CM* [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}];
227 ^$CM+ [\p{Pf} & $QU] $CM* [$SP $GL $WJ $CL $QU $CP $EX $IS $SY $BK $CR $LF $NL $ZW {eof}];
228
229 # Messy interaction: manually chain between LB 15b and LB 15a on Pf Pi.
230 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .;
231 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
232 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .;
233 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
234 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ .;
235 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP $CM+ $AL_FOLLOW?;
236
237
238 # LB 15c Force a break before start of a number with a leading decimal pt, e.g. " .23"
239 # Note: would be simpler to express as "$SP / $IS $CM* $NU;", but ICU rules have limitations.
240 # See issue ICU-20303
241
242
243 $CanFollowIS = [$BK $CR $LF $NL $SP $ZW $WJ $GL $CL $CP $EX $IS $SY $QU $BA $HY $NS $ALPlus $HL $IN];
244 $SP $IS / [^ $CanFollowIS $NU $CM];
245 $SP $IS $CM* $CMX / [^ $CanFollowIS $NU $CM];
246
247 #
248 # LB 15d Do not break before numeric separators (IS), even after spaces.
249 # SP IS QU is handled below as part of LB 19.
250
251 [$LB8NonBreaks - $SP] $IS;
252 $SP $IS $CM* [$CanFollowIS {eof}];
253 $SP $IS $CM* $ZWJ [^$CM $NU];
254
255 $CAN_CM $CM* $IS;
256 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
257
258
259 # LB 16
260 ($CL | $CP) $CM* $SP* $NS;
261
262 # LB 17
263 $B2 $CM* $SP* $B2;
264
265 #
266 # LB 18 Break after spaces.
267 #
268 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
269 $LB18Breaks = [$LB8Breaks $SP];
270
271
272 # LB 19 and LB 19a.
273 # Instead of implementing both as keep-together rules as in UAX #14, we have an
274 # East_Asian_Width and General_Category-insensitive keep-together rule
275 # equivalent to the old LB19 × QU and QU ×, and then we poke holes into it based
276 # on context. This avoids having to do manual chaining over multiple characters
277 # with many other rules over multiple characters, as a keep-together LB19a would
278 # overlap in context with at least LB14, LB15a, LB15a, LB15d, LB30a, and itself.
279 $LB18NonBreaks $CM* $QU;
280 ^$CM+ $QU;
281
282 [$LB18NonBreaks & $EastAsian - [$OP $GL]] / [\p{Pi} & $QU] $CM* [ $EastAsian - $CM];
283 [$LB18NonBreaks & $EastAsian - [$OP $GL]] $CM* $CMX / [\p{Pi} & $QU] $CM* [ $EastAsian - $CM];
284
285 $QU $CM* .;
286 [$LB18NonBreaks & $EastAsian] $CM* [\p{Pf} & $QU] / [ $EastAsian - [$NS $BA $EX $CL $IN $IS $GL $CM]];
287 [$LB18NonBreaks & $EastAsian] $CM* [\p{Pf} & $QU] $CM* $CMX / [ $EastAsian - [$NS $BA $EX $CL $IN $IS $GL $CM]];
288
289 # LB 20
290 # <break> $CB
291 # $CB <break>
292 #
293 $LB20NonBreaks = [$LB18NonBreaks - $CB];
294
295 # LB 20a Don't break between Hyphens and Letters when there is a break preceding the hyphen.
296 # Originally added as a Finnish tailoring, promoted to default ICU behavior (ICU-8151),
297 # and then to default UAX #14 behaviour (UTC-179-C32).
298 #
299 ^($HY | $HH) $CM* $ALPlus;
300 $GL $CM* ($HY | $HH) $CM* $ALPlus;
301 # Non-breaking CB from LB8a:
302 $CB $CM* $ZWJ ($HY | $HH) $CM* $ALPlus;
303 # Non-breaking SP from LB14:
304 $OP $CM* $SP+ ($HY | $HH) $CM* $ALPlus;
305 # Non-breaking SP from LB15a:
306 ($OP $CM* $SP+ | [$OP $QU $GL] $CM*) ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
307 ^([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
308 # Non-breaking SP from LB15a following LB15b:
309 $LB8NonBreaks [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
310 $CAN_CM $CM* [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
311 ^$CM+ [\p{Pf} & $QU] $CM* ([\p{Pi} & $QU] $CM* $SP*)+ $SP ($HY | $HH) $CM* $ALPlus;
312
313 # LB 21 x (BA | HY | NS)
314 # BB x
315 #
316 $LB20NonBreaks $CM* ($BA | $HY | $NS);
317
318
319 ^$CM+ ($BA | $HY | $NS);
320
321 $BB $CM* [^$CB]; # $BB x
322 $BB $CM* $LB20NonBreaks;
323
324 # LB 21a Do not break after the hyphen in Hebrew + Hyphen + non-Hebrew
325 # HL (HY | BA) x [^HL]
326 #
327 $HL $CM* ($HY | [ $BA - $EastAsian ] ) $CM* [^$CB $HL]?;
328
329 # LB 21b (forward) Don't break between SY and HL
330 # (break between HL and SY already disallowed by LB 13 above)
331 $SY $CM* $HL;
332
333 # LB 22 Do not break before ellipses
334 #
335 $LB20NonBreaks $CM* $IN;
336 ^$CM+ $IN;
337
338
339 # LB 23
340 #
341 ($ALPlus | $HL) $CM* $NU;
342 ^$CM+ $NU; # Rule 10, any otherwise unattached CM behaves as AL
343 $NU $CM* ($ALPlus | $HL);
344
345 # LB 23a
346 #
347 $PR $CM* ($ID | $EB | $EM);
348 ($ID | $EB | $EM) $CM* $PO;
349
350
351 #
352 # LB 24
353 #
354 ($PR | $PO) $CM* ($ALPlus | $HL);
355 ($ALPlus | $HL) $CM* ($PR | $PO);
356 ^$CM+ ($PR | $PO); # Rule 10, any otherwise unattached CM behaves as AL
357
358 #
359 # LB 25 Numbers.
360 #
361 (($PR | $PO) $CM*)? (($OP | $HY) $CM*)? ($IS $CM*)? $NU ($CM* ($NU | $SY | $IS))*
362 ($CM* ($CL | $CP))? ($CM* ($PR | $PO))?;
363
364 # LB 26 Do not break a Korean syllable
365 #
366 $JL $CM* ($JL | $JV | $H2 | $H3);
367 ($JV | $H2) $CM* ($JV | $JT);
368 ($JT | $H3) $CM* $JT;
369
370 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
371 ($JL | $JV | $JT | $H2 | $H3) $CM* $PO;
372 $PR $CM* ($JL | $JV | $JT | $H2 | $H3);
373
374
375 # LB 28 Do not break between alphabetics
376 #
377 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
378 ^$CM+ ($ALPlus | $HL); # The $CM+ is from rule 10, an unattached CM is treated as AL
379
380 #LB 28a Do not break Orthographic syllables
381 ($AP $CM*)? ($AS | $AK | [◌] ) ($CM* $VI $CM* ($AK | [◌] ))* ($CM* $VI | (($CM* ($AS | $AK | [◌] ) )? $CM* $VF))?;
382
383 # LB 29
384 $IS $CM* ($ALPlus | $HL);
385
386 # LB 30
387 ($ALPlus | $HL | $NU) $CM* [$OP - $EastAsian];
388 ^$CM+ [$OP - $EastAsian]; # The $CM+ is from rule 10, an unattached CM is treated as AL.
389 [$CP - $EastAsian] $CM* ($ALPlus | $HL | $NU);
390
391 # LB 30a Do not break between regional indicators. Break after pairs of them.
392 # Tricky interaction with LB8a: ZWJ x . together with ZWJ acting like a CM.
393 $RI $CM* $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]];
394 $RI $CM* $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $CM]];
395 $RI $CM* $RI $CM* [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $IN $ZWJ {eof}];
396 # note: the preceding rule includes {eof} rather than having the last [set] term qualified with '?'
397 # because of the chain-out behavior difference. The rule must chain out only from the [set characters],
398 # not from the preceding $RI or $CM, which it would be able to do if the set were optional.
399
400 # LB30b Do not break between an emoji base (or potential emoji) and an emoji modifier.
401 $EB $CM* $EM;
402 $ExtPictUnassigned $CM* $EM;
403
404 # LB 31 Break everywhere else.
405 # Match a single code point if no other rule applies.
406 .;