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