]> git.saurik.com Git - apple/icu.git/blob - icuSources/data/brkitr/line.txt
ICU-400.42.tar.gz
[apple/icu.git] / icuSources / data / brkitr / line.txt
1 # Copyright (c) 2002-2008 International Business Machines Corporation and
2 # others. All Rights Reserved.
3 #
4 # file: line.txt
5 #
6 # Line Breaking Rules
7 # Implement default line breaking as defined by
8 # Unicode Standard Annex #14 Revision 21 for Unicode 5.1
9 # http://www.unicode.org/reports/tr14/
10
11
12
13 #
14 # Character Classes defined by TR 14.
15 #
16
17 !!chain;
18 !!LBCMNoChain;
19
20
21 !!lookAheadHardBreak;
22 #
23 # !!lookAheadHardBreak Described here because it is (as yet) undocumented elsewhere
24 # and only used for the line break rules.
25 #
26 # It is used in the implementation of the incredibly annoying rule LB 10
27 # which says to treat any combining mark that is not attached to a base
28 # character as if it were of class AL (alphabetic).
29 #
30 # The problem occurs in the reverse rules.
31 #
32 # Consider a sequence like, with correct breaks as shown
33 # LF ID CM AL AL
34 # ^ ^ ^
35 # Then consider the sequence without the initial ID (ideographic)
36 # LF CM AL AL
37 # ^ ^
38 # Our CM, which in the first example was attached to the ideograph,
39 # is now unattached, becomes an alpha, and joins in with the other
40 # alphas.
41 #
42 # When iterating forwards, these sequences do not present any problems
43 # When iterating backwards, we need to look ahead when encountering
44 # a CM to see whether it attaches to something further on or not.
45 # (Look-ahead in a reverse rule is looking towards the start)
46 #
47 # If the CM is unattached, we need to force a break.
48 #
49 # !!lookAheadHardBreak forces the run time state machine to
50 # stop immediately when a look ahead rule ( '/' operator) matches,
51 # and set the match position to that of the look-ahead operator,
52 # no matter what other rules may be in play at the time.
53 #
54 # See rule LB 19 for an example.
55 #
56
57 $AI = [:LineBreak = Ambiguous:];
58 $AL = [:LineBreak = Alphabetic:];
59 $BA = [:LineBreak = Break_After:];
60 $BB = [:LineBreak = Break_Before:];
61 $BK = [:LineBreak = Mandatory_Break:];
62 $B2 = [:LineBreak = Break_Both:];
63 $CB = [:LineBreak = Contingent_Break:];
64 $CL = [:LineBreak = Close_Punctuation:];
65 $CM = [:LineBreak = Combining_Mark:];
66 $CR = [:LineBreak = Carriage_Return:];
67 $EX = [:LineBreak = Exclamation:];
68 $GL = [:LineBreak = Glue:];
69 $HY = [:LineBreak = Hyphen:];
70 $H2 = [:LineBreak = H2:];
71 $H3 = [:LineBreak = H3:];
72 $ID = [:LineBreak = Ideographic:];
73 $IN = [:LineBreak = Inseperable:];
74 $IS = [:LineBreak = Infix_Numeric:];
75 $JL = [:LineBreak = JL:];
76 $JV = [:LineBreak = JV:];
77 $JT = [:LineBreak = JT:];
78 $LF = [:LineBreak = Line_Feed:];
79 $NL = [:LineBreak = Next_Line:];
80 $NS = [:LineBreak = Nonstarter:];
81 $NU = [:LineBreak = Numeric:];
82 $OP = [:LineBreak = Open_Punctuation:];
83 $PO = [:LineBreak = Postfix_Numeric:];
84 $PR = [:LineBreak = Prefix_Numeric:];
85 $QU = [:LineBreak = Quotation:];
86 $SA = [:LineBreak = Complex_Context:];
87 $SG = [:LineBreak = Surrogate:];
88 $SP = [:LineBreak = Space:];
89 $SY = [:LineBreak = Break_Symbols:];
90 $WJ = [:LineBreak = Word_Joiner:];
91 $XX = [:LineBreak = Unknown:];
92 $ZW = [:LineBreak = ZWSpace:];
93
94 # Dictionary character set, for triggering language-based break engines. Currently
95 # limited to LineBreak=Complex_Context. Note that this set only works in Unicode
96 # 5.0 or later as the definition of Complex_Context was corrected to include all
97 # characters requiring dictionary break.
98
99 $dictionary = [:LineBreak = Complex_Context:];
100
101 #
102 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
103 # SA (South East Asian: Thai, Lao, Khmer)
104 # SG (Unpaired Surrogates)
105 # XX (Unknown, unassigned)
106 # as $AL (Alphabetic)
107 #
108 $ALPlus = [$AL $AI $SA $SG $XX];
109
110 #
111 # Combining Marks. X $CM* behaves as if it were X. Rule LB6.
112 #
113 $ALcm = $ALPlus $CM*;
114 $BAcm = $BA $CM*;
115 $BBcm = $BB $CM*;
116 $B2cm = $B2 $CM*;
117 $CLcm = $CL $CM*;
118 $EXcm = $EX $CM*;
119 $GLcm = $GL $CM*;
120 $HYcm = $HY $CM*;
121 $H2cm = $H2 $CM*;
122 $H3cm = $H3 $CM*;
123 $IDcm = $ID $CM*;
124 $INcm = $IN $CM*;
125 $IScm = $IS $CM*;
126 $JLcm = $JL $CM*;
127 $JVcm = $JV $CM*;
128 $JTcm = $JT $CM*;
129 $NScm = $NS $CM*;
130 $NUcm = $NU $CM*;
131 $OPcm = $OP $CM*;
132 $POcm = $PO $CM*;
133 $PRcm = $PR $CM*;
134 $QUcm = $QU $CM*;
135 $SYcm = $SY $CM*;
136 $WJcm = $WJ $CM*;
137
138 ## -------------------------------------------------
139
140 !!forward;
141
142 #
143 # Each class of character can stand by itself as an unbroken token, with trailing combining stuff
144 #
145 $ALPlus $CM+;
146 $BA $CM+;
147 $BB $CM+;
148 $B2 $CM+;
149 $CL $CM+;
150 $EX $CM+;
151 $GL $CM+;
152 $HY $CM+;
153 $H2 $CM+;
154 $H3 $CM+;
155 $ID $CM+;
156 $IN $CM+;
157 $IS $CM+;
158 $JL $CM+;
159 $JV $CM+;
160 $JT $CM+;
161 $NS $CM+;
162 $NU $CM+;
163 $OP $CM+;
164 $PO $CM+;
165 $PR $CM+;
166 $QU $CM+;
167 $SY $CM+;
168 $WJ $CM+;
169
170 #
171 # CAN_CM is the set of characters that may combine with CM combining chars.
172 # Note that Linebreak UAX 14's concept of a combining char and the rules
173 # for what they can combine with are _very_ different from the rest of Unicode.
174 #
175 # Note that $CM itself is left out of this set. If CM is needed as a base
176 # it must be listed separately in the rule.
177 #
178 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
179 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
180
181 #
182 # AL_FOLLOW set of chars that can unconditionally follow an AL
183 # Needed in rules where stand-alone $CM s are treated as AL.
184 # Chaining is disabled with CM because it causes other failures,
185 # so for this one case we need to manually list out longer sequences.
186 #
187 $AL_FOLLOW_NOCM = [$BK $CR $LF $NL $ZW $SP];
188 $AL_FOLLOW_CM = [$CL $EX $IS $SY $WJ $GL $QU $BA $HY $NS $IN $NU $ALPlus];
189 $AL_FOLLOW = [$AL_FOLLOW_NOCM $AL_FOLLOW_CM];
190
191
192 #
193 # Rule LB 4, 5 Mandatory (Hard) breaks.
194 #
195 $LB4Breaks = [$BK $CR $LF $NL];
196 $LB4NonBreaks = [^$BK $CR $LF $NL];
197 $CR $LF {100};
198
199 #
200 # LB 6 Do not break before hard line breaks.
201 #
202 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
203 $CAN_CM $CM* $LB4Breaks {100};
204 $CM+ $LB4Breaks {100};
205
206 # LB 7 x SP
207 # x ZW
208 $LB4NonBreaks [$SP $ZW];
209 $CAN_CM $CM* [$SP $ZW];
210 $CM+ [$SP $ZW];
211
212 #
213 # LB 8 Break after zero width space
214 #
215 $LB8Breaks = [$LB4Breaks $ZW];
216 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
217
218
219 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
220 # $CM not covered by the above needs to behave like $AL
221 # See definition of $CAN_CM.
222
223 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
224 $CM+;
225
226 #
227 # LB 11 Do not break before or after WORD JOINER & related characters.
228 #
229 $CAN_CM $CM* $WJcm;
230 $LB8NonBreaks $WJcm;
231 $CM+ $WJcm;
232
233 $WJcm $CANT_CM;
234 $WJcm $CAN_CM $CM*;
235
236 #
237 # LB 12 Do not break after NBSP and related characters.
238 # GL x
239 #
240 $GLcm $CAN_CM $CM*;
241 $GLcm $CANT_CM;
242
243 #
244 # LB 12a Do not break before NBSP and related characters ...
245 # [^SP BA HY] x GL
246 #
247 [[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GLcm;
248 $CM+ GLcm;
249
250
251
252 #
253 # LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces.
254 #
255 $LB8NonBreaks $CL;
256 $CAN_CM $CM* $CL;
257 $CM+ $CL; # by rule 10, stand-alone CM behaves as AL
258
259 $LB8NonBreaks $EX;
260 $CAN_CM $CM* $EX;
261 $CM+ $EX; # by rule 10, stand-alone CM behaves as AL
262
263 $LB8NonBreaks $IS;
264 $CAN_CM $CM* $IS;
265 $CM+ $IS; # by rule 10, stand-alone CM behaves as AL
266
267 $LB8NonBreaks $SY;
268 $CAN_CM $CM* $SY;
269 $CM+ $SY; # by rule 10, stand-alone CM behaves as AL
270
271
272 #
273 # LB 14 Do not break after OP, even after spaces
274 #
275 $OPcm $SP* $CAN_CM $CM*;
276 $OPcm $SP* $CANT_CM;
277
278 $OPcm $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
279
280 # LB 15
281 $QUcm $SP* $OPcm;
282
283 # LB 16
284 $CLcm $SP* $NScm;
285
286 # LB 17
287 $B2cm $SP* $B2cm;
288
289 #
290 # LB 18 Break after spaces.
291 #
292 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
293 $LB18Breaks = [$LB8Breaks $SP];
294
295
296 # LB 19
297 # x QU
298 $LB18NonBreaks $CM* $QUcm;
299 $CM+ $QUcm;
300
301 # QU x
302 $QUcm .?;
303 $QUcm $LB18NonBreaks $CM*; # Don't let a combining mark go onto $CR, $BK, etc.
304 # TODO: I don't think this rule is needed.
305
306
307 # LB 20
308 # <break> $CB
309 # $CB <break>
310
311 $LB20NonBreaks = [$LB18NonBreaks - $CB];
312
313 # LB 21 x (BA | HY | NS)
314 # BB x
315 #
316 $LB20NonBreaks $CM* ($BAcm | $HYcm | $NScm);
317
318 $BBcm [^$CB]; # $BB x
319 $BBcm $LB20NonBreaks $CM*;
320
321 # LB 22
322 $ALcm $INcm;
323 $CM+ $INcm; # by rule 10, any otherwise unattached CM behaves as AL
324 $IDcm $INcm;
325 $INcm $INcm;
326 $NUcm $INcm;
327
328
329 # $LB 23
330 $IDcm $POcm;
331 $ALcm $NUcm; # includes $LB19
332 $CM+ $NUcm; # Rule 10, any otherwise unattached CM behaves as AL
333 $NUcm $ALcm;
334
335 #
336 # LB 24
337 #
338 $PRcm $IDcm;
339 $PRcm $ALcm;
340 $POcm $ALcm;
341
342 #
343 # LB 25 Numbers.
344 #
345 ($PRcm | $POcm)? ($OPcm | $HYcm)? $NUcm ($NUcm | $SYcm | $IScm)* $CLcm? ($PRcm | $POcm)?;
346
347 # LB 26 Do not break a Korean syllable
348 #
349 $JLcm ($JLcm | $JVcm | $H2cm | $H3cm);
350 ($JVcm | $H2cm) ($JVcm | $JTcm);
351 ($JTcm | $H3cm) $JTcm;
352
353 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
354 ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm) $INcm;
355 ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm) $POcm;
356 $PRcm ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm);
357
358
359 # LB 28 Do not break between alphabetics
360 #
361 $ALcm $ALcm;
362 $CM+ $ALcm; # The $CM+ is from rule 10, and unattached CM is treated as AL
363
364 # LB 29
365 $IScm $ALcm;
366
367
368 #
369 # Reverse Rules.
370 #
371 ## -------------------------------------------------
372
373 !!reverse;
374
375 $CM+ $ALPlus;
376 $CM+ $BA;
377 $CM+ $BB;
378 $CM+ $B2;
379 $CM+ $CL;
380 $CM+ $EX;
381 $CM+ $GL;
382 $CM+ $HY;
383 $CM+ $H2;
384 $CM+ $H3;
385 $CM+ $ID;
386 $CM+ $IN;
387 $CM+ $IS;
388 $CM+ $JL;
389 $CM+ $JV;
390 $CM+ $JT;
391 $CM+ $NS;
392 $CM+ $NU;
393 $CM+ $OP;
394 $CM+ $PO;
395 $CM+ $PR;
396 $CM+ $QU;
397 $CM+ $SY;
398 $CM+ $WJ;
399 $CM+;
400
401
402 #
403 # Sequences of the form (shown forwards)
404 # [CANT_CM] <break> [CM] [whatever]
405 # The CM needs to behave as an AL
406 #
407 $AL_FOLLOW $CM+ / (
408 [$BK $CR $LF $NL $ZW {eof}] |
409 $SP+ $CM+ $SP |
410 $SP+ $CM* ([^$OP $CM $SP] | [$AL {eof}])); # if LB 14 will match, need to surpress this break.
411 # LB14 says OP SP* x .
412 # becomes OP SP* x AL
413 # becomes OP SP* x CM+ AL_FOLLOW
414 #
415 # Further note: the $AL in [$AL {eof}] is only to work around
416 # a rule compiler bug which complains about
417 # empty sets otherwise.
418
419 #
420 # Sequences of the form (shown forwards)
421 # [CANT_CM] <break> [CM] <break> [PR]
422 # The CM needs to behave as an AL
423 # This rule is concerned about getting the second of the two <breaks> in place.
424 #
425
426 [$PR ] / $CM+ [$BK $CR $LF $NL $ZW $SP {eof}];
427
428
429
430 # LB 4, 5, 5
431
432 $LB4Breaks [$LB4NonBreaks-$CM];
433 $LB4Breaks $CM+ $CAN_CM;
434 $LF $CR;
435
436
437 # LB 7 x SP
438 # x ZW
439 [$SP $ZW] [$LB4NonBreaks-$CM];
440 [$SP $ZW] $CM+ $CAN_CM;
441
442 # LB 8 Break after zero width space
443
444
445 # LB 9,10 Combining marks.
446 # X $CM needs to behave like X, where X is not $SP or controls.
447 # $CM not covered by the above needs to behave like $AL
448 # Stick together any combining sequences that don't match other rules.
449 $CM+ $CAN_CM;
450
451
452 # LB 11
453 $CM* $WJ $CM* $CAN_CM;
454 $CM* $WJ [$LB8NonBreaks-$CM];
455
456 $CANT_CM $CM* $WJ;
457 $CM* $CAN_CM $CM* $WJ;
458
459 # LB 12a
460 # [^SP BA HY] x GL
461 #
462 $CM* $GL $CM* [$LB8NonBreaks-[$CM $SP $BA $HY]];
463
464 # LB 12
465 # GL x
466 #
467 $CANT_CM $CM* $GL;
468 $CM* $CAN_CM $CM* $GL;
469
470
471 # LB 13
472 $CL $CM+ $CAN_CM;
473 $EX $CM+ $CAN_CM;
474 $IS $CM+ $CAN_CM;
475 $SY $CM+ $CAN_CM;
476
477 $CL [$LB8NonBreaks-$CM];
478 $EX [$LB8NonBreaks-$CM];
479 $IS [$LB8NonBreaks-$CM];
480 $SY [$LB8NonBreaks-$CM];
481
482 # Rule 13 & 14 taken together for an edge case.
483 # Match this, shown forward
484 # OP SP+ ($CM+ behaving as $AL) (CL | EX | IS | IY)
485 # This really wants to chain at the $CM+ (which is acting as an $AL)
486 # except for $CM chaining being disabled.
487 [$CL $EX $IS $SY] $CM+ $SP+ $CM* $OP;
488
489 # LB 14 OP SP* x
490 #
491 $CM* $CAN_CM $SP* $CM* $OP;
492 $CANT_CM $SP* $CM* $OP;
493 $AL_FOLLOW? $CM+ $SP $SP* $CM* $OP; # by LB 10, behaves like $AL_FOLLOW? $AL $SP* $CM* $OP
494
495 $AL_FOLLOW_NOCM $CM+ $SP+ $CM* $OP;
496 $CM* $AL_FOLLOW_CM $CM+ $SP+ $CM* $OP;
497 $SY $CM $SP+ $OP; # TODO: Experiment. Remove.
498
499
500
501 # LB 15
502 $CM* $OP $SP* $CM* $QU;
503
504 # LB 16
505 $CM* $NS $SP* $CM* $CL;
506
507 # LB 17
508 $CM* $B2 $SP* $CM* $B2;
509
510 # LB 18 break after spaces
511 # Nothing explicit needed here.
512
513
514 #
515 # LB 19
516 #
517 $CM* $QU $CM* $CAN_CM; # . x QU
518 $CM* $QU $LB18NonBreaks;
519
520
521 $CM* $CAN_CM $CM* $QU; # QU x .
522 $CANT_CM $CM* $QU;
523
524 #
525 # LB 20 Break before and after CB.
526 # nothing needed here.
527 #
528
529 # LB 21
530 $CM* ($BA | $HY | $NS) $CM* [$LB20NonBreaks-$CM]; # . x (BA | HY | NS)
531
532 $CM* [$LB20NonBreaks-$CM] $CM* $BB; # BB x .
533 [^$CB] $CM* $BB; #
534
535
536
537 # LB 22
538 $CM* $IN $CM* $ALPlus;
539 $CM* $IN $CM* $ID;
540 $CM* $IN $CM* $IN;
541 $CM* $IN $CM* $NU;
542
543 # LB 23
544 $CM* $PO $CM* $ID;
545 $CM* $NU $CM* $ALPlus;
546 $CM* $ALPlus $CM* $NU;
547
548 # LB 24
549 $CM* $ID $CM* $PR;
550 $CM* $ALPlus $CM* $PR;
551 $CM* $ALPlus $CM* $PO;
552
553
554 # LB 25
555 ($CM* ($PR | $PO))? ($CM* $CL)? ($CM* ($NU | $IS | $SY))* $CM* $NU ($CM* ($OP | $HY))? ($CM* ($PR | $PO))?;
556
557 # LB 26
558 $CM* ($H3 | $H2 | $JV | $JL) $CM* $JL;
559 $CM* ($JT | $JV) $CM* ($H2 | $JV);
560 $CM* $JT $CM* ($H3 | $JT);
561
562 # LB 27
563 $CM* $IN $CM* ($H3 | $H2 | $JT | $JV | $JL);
564 $CM* $PO $CM* ($H3 | $H2 | $JT | $JV | $JL);
565 $CM* ($H3 | $H2 | $JT | $JV | $JL) $CM* $PR;
566
567 # LB 28
568 $CM* $ALPlus $CM* $ALPlus;
569
570
571 # LB 29
572 $CM* $ALPlus $CM* $IS;
573
574
575 ## -------------------------------------------------
576
577 !!safe_reverse;
578
579 # LB 9
580 $CM+ [^$CM $BK $CR $LF $NL $ZW $SP];
581 $CM+ $SP / .;
582
583 # LB 14
584 $SP+ $CM* $OP;
585
586 # LB 15
587 $SP+ $CM* $QU;
588
589 # LB 16
590 $SP+ $CM* $CL;
591
592 # LB 17
593 $SP+ $CM* $B2;
594
595 # LB 25
596 ($CM* ($IS | $SY))+ $CM* $NU;
597 $CL $CM* ($NU | $IS | $SY);
598
599 # For dictionary-based break
600 $dictionary $dictionary;
601
602 ## -------------------------------------------------
603
604 !!safe_forward;
605
606 # Skip forward over all character classes that are involved in
607 # rules containing patterns with possibly more than one char
608 # of context.
609 #
610 # It might be slightly more efficient to have specific rules
611 # instead of one generic one, but only if we could
612 # turn off rule chaining. We don't want to move more
613 # than necessary.
614 #
615 [$CM $OP $QU $CL $B2 $PR $HY $SP $dictionary]+ [^$CM $OP $QU $CL $B2 $PR $HY $dictionary];
616 $dictionary $dictionary;
617