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