1 # Copyright (c) 2002-2016 International Business Machines Corporation and
2 # others. All Rights Reserved.
4 # file: line_normal.txt
7 # Implement default line breaking as defined by
8 # Unicode Standard Annex #14 Revision 35 for Unicode 8.0
9 # http://www.unicode.org/reports/tr14/
11 # Includes the Emoji breaking proposals from Unicode L2/16-011R3.
12 # http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf
14 # tailored as noted in 2nd paragraph below.
16 # TODO: Rule LB 8 remains as it was in Unicode 5.2
17 # This is only because of a limitation of ICU break engine implementation,
18 # not because the older behavior is desirable.
20 # This tailors the line break behavior to correspond to CSS
21 # line-break=normal (BCP47 -u-lb-normal) as defined for languages other than
23 # It sets characters of class CJ to behave like ID.
26 # Character Classes defined by TR 14.
33 # !!lookAheadHardBreak Described here because it is (as yet) undocumented elsewhere
34 # and only used for the line break rules.
36 # It is used in the implementation of rule LB 10
37 # which says to treat any combining mark that is not attached to a base
38 # character as if it were of class AL (alphabetic).
40 # The problem occurs in the reverse rules.
42 # Consider a sequence like, with correct breaks as shown
45 # Then consider the sequence without the initial ID (ideographic)
48 # Our CM, which in the first example was attached to the ideograph,
49 # is now unattached, becomes an alpha, and joins in with the other
52 # When iterating forwards, these sequences do not present any problems
53 # When iterating backwards, we need to look ahead when encountering
54 # a CM to see whether it attaches to something further on or not.
55 # (Look-ahead in a reverse rule is looking towards the start)
57 # If the CM is unattached, we need to force a break.
59 # !!lookAheadHardBreak forces the run time state machine to
60 # stop immediately when a look ahead rule ( '/' operator) matches,
61 # and set the match position to that of the look-ahead operator,
62 # no matter what other rules may be in play at the time.
64 # See rule LB 19 for an example.
67 # Temporary definitions of Emoji Base and Emoji Modifiers, until properties are available.
69 $EB = [\u261D\u26F9\u270A-\u270D\U0001F385\U0001F3C2-\U0001F3C4\U0001F3C7\U0001F3CA-\U0001F3CC\U0001F442-\U0001F443\U0001F446-\U0001F450\U0001F466-\U0001F478\U0001F47C\U0001F481-\U0001F483\U0001F485-\U0001F487\U0001F4AA\U0001F574-\U0001F575\U0001F57A\U0001F590\U0001F595-\U0001F596\U0001F645-\U0001F647\U0001F64B-\U0001F64F\U0001F6A3\U0001F6B4-\U0001F6B6\U0001F6C0\U0001F6CC\U0001F918-\U0001F91E\U0001F926\U0001F930\U0001F933-\U0001F939\U0001F93C-\U0001F93E];
70 $EM = [\U0001F3FB-\U0001F3FF];
72 $AI = [[:LineBreak = Ambiguous:] - [\u2640\u2642]];
73 $AL = [[:LineBreak = Alphabetic:] - [$EM\u2695\u2696\u2764]];
74 $BA = [:LineBreak = Break_After:];
75 $BB = [:LineBreak = Break_Before:];
76 $BK = [:LineBreak = Mandatory_Break:];
77 $B2 = [:LineBreak = Break_Both:];
78 $CB = [:LineBreak = Contingent_Break:];
79 $CJ = [:LineBreak = Conditional_Japanese_Starter:];
80 $CL = [:LineBreak = Close_Punctuation:];
81 $CM = [[:LineBreak = Combining_Mark:] \u200d];
82 $CP = [:LineBreak = Close_Parenthesis:];
83 $CR = [:LineBreak = Carriage_Return:];
84 $EX = [:LineBreak = Exclamation:];
85 $GL = [:LineBreak = Glue:];
86 $HL = [:LineBreak = Hebrew_Letter:];
87 $HY = [:LineBreak = Hyphen:];
88 $H2 = [:LineBreak = H2:];
89 $H3 = [:LineBreak = H3:];
90 $ID = [[:LineBreak = Ideographic:] $CJ [\u2640\u2642\u2695\u2696\u2764] - $EB];
91 $IN = [:LineBreak = Inseperable:];
92 $IS = [:LineBreak = Infix_Numeric:];
93 $JL = [:LineBreak = JL:];
94 $JV = [:LineBreak = JV:];
95 $JT = [:LineBreak = JT:];
96 $LF = [:LineBreak = Line_Feed:];
97 $NL = [:LineBreak = Next_Line:];
98 $NS = [:LineBreak = Nonstarter:];
99 $NU = [:LineBreak = Numeric:];
100 $OP = [:LineBreak = Open_Punctuation:];
101 $PO = [:LineBreak = Postfix_Numeric:];
102 $PR = [:LineBreak = Prefix_Numeric:];
103 $QU = [:LineBreak = Quotation:];
104 $RI = [:LineBreak = Regional_Indicator:];
105 $SA = [:LineBreak = Complex_Context:];
106 $SG = [:LineBreak = Surrogate:];
107 $SP = [:LineBreak = Space:];
108 $SY = [:LineBreak = Break_Symbols:];
109 $WJ = [:LineBreak = Word_Joiner:];
110 $XX = [:LineBreak = Unknown:];
111 $ZW = [:LineBreak = ZWSpace:];
114 # Dictionary character set, for triggering language-based break engines. Currently
115 # limited to LineBreak=Complex_Context. Note that this set only works in Unicode
116 # 5.0 or later as the definition of Complex_Context was corrected to include all
117 # characters requiring dictionary break.
119 $dictionary = [:LineBreak = Complex_Context:];
122 # Rule LB1. By default, treat AI (characters with ambiguous east Asian width),
123 # SA (South East Asian: Thai, Lao, Khmer)
124 # SG (Unpaired Surrogates)
125 # XX (Unknown, unassigned)
126 # as $AL (Alphabetic)
128 $ALPlus = [$AL $AI $SA $SG $XX];
131 # Combining Marks. X $CM* behaves as if it were X. Rule LB6.
133 $ALcm = $ALPlus $CM*;
160 ## -------------------------------------------------
165 # Each class of character can stand by itself as an unbroken token, with trailing combining stuff
198 # CAN_CM is the set of characters that may combine with CM combining chars.
199 # Note that Linebreak UAX 14's concept of a combining char and the rules
200 # for what they can combine with are _very_ different from the rest of Unicode.
202 # Note that $CM itself is left out of this set. If CM is needed as a base
203 # it must be listed separately in the rule.
205 $CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs
206 $CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs
209 # AL_FOLLOW set of chars that can unconditionally follow an AL
210 # Needed in rules where stand-alone $CM s are treated as AL.
211 # Chaining is disabled with CM because it causes other failures,
212 # so for this one case we need to manually list out longer sequences.
214 $AL_FOLLOW_NOCM = [$BK $CR $LF $NL $ZW $SP];
215 $AL_FOLLOW_CM = [$CL $CP $EX $HL $IS $SY $WJ $GL $OP $QU $BA $HY $NS $IN $NU $ALPlus];
216 $AL_FOLLOW = [$AL_FOLLOW_NOCM $AL_FOLLOW_CM];
220 # Rule LB 4, 5 Mandatory (Hard) breaks.
222 $LB4Breaks = [$BK $CR $LF $NL];
223 $LB4NonBreaks = [^$BK $CR $LF $NL $CM];
227 # LB 6 Do not break before hard line breaks.
229 $LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks.
230 $CAN_CM $CM* $LB4Breaks {100};
231 ^$CM+ $LB4Breaks {100};
235 $LB4NonBreaks [$SP $ZW];
236 $CAN_CM $CM* [$SP $ZW];
240 # LB 8 Break after zero width space
241 # TODO: ZW SP* <break>
242 # An engine change is required to write the reverse rule for this.
243 # For now, leave the Unicode 5.2 rule, ZW <break>
245 $LB8Breaks = [$LB4Breaks $ZW];
246 $LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]];
248 # LB 8a ZWJ x ID Emoji proposal.
250 $ZWJ ($ID | $EB | $EM);
252 # LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL
253 # $CM not covered by the above needs to behave like $AL
254 # See definition of $CAN_CM.
256 $CAN_CM $CM+; # Stick together any combining sequences that don't match other rules.
260 # LB 11 Do not break before or after WORD JOINER & related characters.
270 # LB 12 Do not break after NBSP and related characters.
277 # LB 12a Do not break before NBSP and related characters ...
280 [[$LB8NonBreaks] - [$SP $BA $HY]] $CM* $GLcm;
286 # LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces.
290 ^$CM+ $CL; # by rule 10, stand-alone CM behaves as AL
294 ^$CM+ $CP; # by rule 10, stand-alone CM behaves as AL
298 ^$CM+ $EX; # by rule 10, stand-alone CM behaves as AL
302 ^$CM+ $IS; # by rule 10, stand-alone CM behaves as AL
306 ^$CM+ $SY; # by rule 10, stand-alone CM behaves as AL
310 # LB 14 Do not break after OP, even after spaces
312 $OPcm $SP* $CAN_CM $CM*;
315 $OPcm $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL
321 ($CLcm | $CPcm) $SP* $NScm;
327 # LB 18 Break after spaces.
329 $LB18NonBreaks = [$LB8NonBreaks - [$SP]];
330 $LB18Breaks = [$LB8Breaks $SP];
335 $LB18NonBreaks $CM* $QUcm;
346 $LB20NonBreaks = [$LB18NonBreaks - $CB];
348 # LB 21 x (BA | HY | NS)
351 $LB20NonBreaks $CM* ($BAcm | $HYcm | $NScm);
352 ^$CM+ ($BAcm | $HYcm | $NScm);
354 $BBcm [^$CB]; # $BB x
355 $BBcm $LB20NonBreaks $CM*;
357 # LB 21a Don't break after Hebrew + Hyphen
360 $HLcm ($HYcm | $BAcm) [^$CB]?;
362 # LB 21b (forward) Don't break between SY and HL
363 # (break between HL and SY already disallowed by LB 13 above)
367 ($ALcm | $HLcm) $INcm;
368 ^$CM+ $INcm; # by rule 10, any otherwise unattached CM behaves as AL
370 ($ID | $EB | $EM) $CM* $INcm;
376 ($ID | $EB | $EM) $CM* $POcm;
377 $ALcm $NUcm; # includes $LB19
379 ^$CM+ $NUcm; # Rule 10, any otherwise unattached CM behaves as AL
386 $PRcm ($ID | $EB | $EM);
387 $PRcm ($ALcm | $HLcm);
388 $POcm ($ALcm | $HLcm);
389 ($ALcm | $HLcm) ($PRcm | $POcm);
390 ^$CM+ ($PRcm | $POcm); # Rule 10, any otherwise unattached CM behaves as AL
395 ($PRcm | $POcm)? ($OPcm | $HYcm)? $NUcm ($NUcm | $SYcm | $IScm)* ($CLcm | $CPcm)? ($PRcm | $POcm)?;
397 # LB 26 Do not break a Korean syllable
399 $JLcm ($JLcm | $JVcm | $H2cm | $H3cm);
400 ($JVcm | $H2cm) ($JVcm | $JTcm);
401 ($JTcm | $H3cm) $JTcm;
403 # LB 27 Treat korean Syllable Block the same as ID (don't break it)
404 ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm) $INcm;
405 ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm) $POcm;
406 $PRcm ($JLcm | $JVcm | $JTcm | $H2cm | $H3cm);
409 # LB 28 Do not break between alphabetics
411 ($ALcm | $HLcm) ($ALcm | $HLcm);
412 ^$CM+ ($ALcm | $HLcm); # The $CM+ is from rule 10, an unattached CM is treated as AL
415 $IScm ($ALcm | $HLcm);
418 ($ALcm | $HLcm | $NUcm) $OPcm;
419 ^$CM+ $OPcm; # The $CM+ is from rule 10, an unattached CM is treated as AL.
420 $CPcm ($ALcm | $HLcm | $NUcm);
422 # LB 30a Do not break between regional indicators. Break after pairs of them.
423 # Tricky interaction with LB8a: ZWJ x ID
424 $RIcm $RI / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM] {eof}];
425 $RIcm $RI $CM* $ZWJ / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM $ID $EB $EM] {eof}];
426 $RIcm $RI $CM* [$CM-$ZWJ] / [[^$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS $CM] {eof}];
428 $RIcm $RIcm [$BK $CR $LF $NL $SP $ZW $WJ $CL $CP $EX $IS $SY $GL $QU $BA $HY $NS {eof}];
429 $RIcm $RIcm $ZWJ ($ID | $EB | $EM);
431 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
437 ## -------------------------------------------------
474 # Sequences of the form (shown forwards)
475 # [CANT_CM] <break> [CM] [whatever]
476 # The CM needs to behave as an AL
479 [$BK $CR $LF $NL $ZW {eof}] |
481 $SP+ $CM* ([^$OP $CM $SP] | [$AL {eof}])); # if LB 14 will match, need to surpress this break.
482 # LB14 says OP SP* x .
483 # becomes OP SP* x AL
484 # becomes OP SP* x CM+ AL_FOLLOW
486 # Further note: the $AL in [$AL {eof}] is only to work around
487 # a rule compiler bug which complains about
488 # empty sets otherwise.
491 # Sequences of the form (shown forwards)
492 # [CANT_CM] <break> [CM] <break> [PR]
493 # The CM needs to behave as an AL
494 # This rule is concerned about getting the second of the two <breaks> in place.
497 # Apple early addition, remove this, superseded by LB24
498 # [$PR ] / $CM+ [$BK $CR $LF $NL $ZW $SP {eof}];
504 $LB4Breaks [$LB4NonBreaks-$CM];
505 $LB4Breaks $CM+ $CAN_CM;
511 [$SP $ZW] [$LB4NonBreaks-$CM];
512 [$SP $ZW] $CM+ $CAN_CM;
514 # LB 8 ZW SP* <break>
515 # TODO: to implement this, we need more than one look-ahead hard break in play at a time.
516 # Requires an engine enhancement.
519 # LB 8a ZWJ x ID Unicode Emoji proposal L2/16-011R3
520 # The ZWJ will look like a CM to whatever precedes it.
522 ($ID | $EB | $EM) $ZWJ $CM* $CAN_CM?;
525 # LB 9,10 Combining marks.
526 # X $CM needs to behave like X, where X is not $SP or controls.
527 # $CM not covered by the above needs to behave like $AL
528 # Stick together any combining sequences that don't match other rules.
535 $WJ [$LB8NonBreaks-$CM];
543 $GL $CM* [$LB8NonBreaks-[$CM $SP $BA $HY]];
559 $CL [$LB8NonBreaks-$CM];
560 $CP [$LB8NonBreaks-$CM];
561 $EX [$LB8NonBreaks-$CM];
562 $IS [$LB8NonBreaks-$CM];
563 $SY [$LB8NonBreaks-$CM];
565 # Rule 13 & 14 taken together for an edge case.
566 # Match this, shown forward
567 # OP SP+ ($CM+ behaving as $AL) (CL | CP | EX | IS | IY)
568 # This really wants to chain at the $CM+ (which is acting as an $AL)
569 # except for $CM chaining being disabled.
570 [$CL $CP $EX $IS $SY] $CM+ $SP+ $CM* $OP;
574 $CAN_CM $SP* $CM* $OP;
575 $CANT_CM $SP* $CM* $OP;
576 $AL_FOLLOW? $CM+ $SP $SP* $CM* $OP; # by LB 10, behaves like $AL_FOLLOW? $AL $SP* $CM* $OP
578 $AL_FOLLOW_NOCM $CM+ $SP+ $CM* $OP;
579 $AL_FOLLOW_CM $CM+ $SP+ $CM* $OP;
586 $NS $SP* $CM* ($CL | $CP);
591 # LB 18 break after spaces
592 # Nothing explicit needed here.
598 $QU $CM* $CAN_CM; # . x QU
602 $CAN_CM $CM* $QU; # QU x .
606 # LB 20 Break before and after CB.
607 # nothing needed here.
611 ($BA | $HY | $NS) $CM* [$LB20NonBreaks-$CM]; # . x (BA | HY | NS)
613 [$LB20NonBreaks-$CM] $CM* $BB; # BB x .
617 [^$CB] $CM* ($HY | $BA) $CM* $HL;
623 $IN $CM* ($ALPlus | $HL);
625 $IN $CM* ($ID | $EB | $EM);
630 $PO $CM* ($ID | $EB | $EM);
631 $NU $CM* ($ALPlus | $HL);
632 ($ALPlus | $HL) $CM* $NU;
635 ($ID | $EB | $EM) $CM* $PR;
636 ($ALPlus | $HL) $CM* $PR;
637 ($ALPlus | $HL) $CM* $PO;
638 $CM* ($PR | $PO) $CM* ($ALPlus | $HL);
639 $CM* ($PR | $PO) $CM+ / [$BK $CR $LF $NL $ZW $SP {eof}];
642 ($CM* ($PR | $PO))? ($CM* ($CL | $CP))? ($CM* ($NU | $IS | $SY))* $CM* $NU ($CM* ($OP | $HY))? ($CM* ($PR | $PO))?;
645 ($H3 | $H2 | $JV | $JL) $CM* $JL;
646 ($JT | $JV) $CM* ($H2 | $JV);
647 $JT $CM* ($H3 | $JT);
650 $IN $CM* ($H3 | $H2 | $JT | $JV | $JL);
651 $PO $CM* ($H3 | $H2 | $JT | $JV | $JL);
652 ($H3 | $H2 | $JT | $JV | $JL) $CM* $PR;
655 ($ALPlus | $HL) $CM* ($ALPlus | $HL);
659 ($ALPlus | $HL) $CM* $IS;
662 $OP $CM* ($ALPlus | $HL | $NU);
663 ($ALPlus | $HL | $NU) $CM* $CP;
666 # Pairs of Regional Indicators.
667 # The following two rules are nearly identical. The first matches only sequences with an odd number of adjacent RIs,
668 # the second with an even number. Stripping away the cruft they look like
669 # [^RI] RI / (RI RI)+ ^RI;
670 # [^RI] RI RI / (RI RI)+ ^RI;
672 [{bof} $NS $HY $BA $QU $CL $CP $EX $IS $SY $WJ $GL $ZW $SP $BK $CR $LF $NL $ZWJ] $CM* $RI / ($CM* $RI $CM* $RI)+ $CM* [{eof}[^$RI $CM]];
673 [{bof} $NS $HY $BA $QU $CL $CP $EX $IS $SY $WJ $GL $ZW $SP $BK $CR $LF $NL $ZWJ] $CM* $RI $CM* $RI / ($CM* $RI $CM* $RI)+ $CM* [{eof}[^$RI $CM]];
675 # In general, adjacent RIs stay together. The hard-break rules, above, overide this, forcing in the boundaries between pairs.
678 # WJ, GL, QU, etc. are classes with rules like "WJ x " which includes "WJ x RI".
679 $RI $CM* ([$WJ $GL $QU $BB] | (($HY | $BA)$CM* $HL));
682 # LB 30b Do not break between an Emoji Base and an Emoji Modifier
686 ## -------------------------------------------------
691 ^$CM+ [^$CM $BK $CR $LF $NL $ZW $SP];
701 $SP+ $CM* ($CL | $CP);
707 $CM* ($HY | $BA) $CM* $HL;
710 ($CM* ($IS | $SY))+ $CM* $NU;
711 ($CL | $CP) $CM* ($NU | $IS | $SY);
716 # For dictionary-based break
717 $dictionary $dictionary;
719 ## -------------------------------------------------
723 # Skip forward over all character classes that are involved in
724 # rules containing patterns with possibly more than one char
727 # It might be slightly more efficient to have specific rules
728 # instead of one generic one, but only if we could
729 # turn off rule chaining. We don't want to move more
732 ^[$CM $OP $QU $CL $CP $B2 $PR $HY $BA $SP $RI $ZWJ $dictionary]+ [^$CM $OP $QU $CL $CP $B2 $PR $HY $BA $RI $ZWJ $dictionary];
733 $dictionary $dictionary;