1# Copyright (c) 2002-2015 International Business Machines Corporation and 2# others. All Rights Reserved. 3# 4# file: line_fi.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 for Finnish, while otherwise behaving 17# per UAX 14 which corresponds to CSS line-break=strict (BCP47 -u-lb-strict). 18# It sets characters of class CJ to behave like NS. 19 20# 21# Character Classes defined by TR 14. 22# 23 24!!chain; 25!!LBCMNoChain; 26 27 28!!lookAheadHardBreak; 29# 30# !!lookAheadHardBreak Described here because it is (as yet) undocumented elsewhere 31# and only used for the line break rules. 32# 33# It is used in the implementation of rule LB 10 34# which says to treat any combining mark that is not attached to a base 35# character as if it were of class AL (alphabetic). 36# 37# The problem occurs in the reverse rules. 38# 39# Consider a sequence like, with correct breaks as shown 40# LF ID CM AL AL 41# ^ ^ ^ 42# Then consider the sequence without the initial ID (ideographic) 43# LF CM AL AL 44# ^ ^ 45# Our CM, which in the first example was attached to the ideograph, 46# is now unattached, becomes an alpha, and joins in with the other 47# alphas. 48# 49# When iterating forwards, these sequences do not present any problems 50# When iterating backwards, we need to look ahead when encountering 51# a CM to see whether it attaches to something further on or not. 52# (Look-ahead in a reverse rule is looking towards the start) 53# 54# If the CM is unattached, we need to force a break. 55# 56# !!lookAheadHardBreak forces the run time state machine to 57# stop immediately when a look ahead rule ( '/' operator) matches, 58# and set the match position to that of the look-ahead operator, 59# no matter what other rules may be in play at the time. 60# 61# See rule LB 19 for an example. 62# 63 64$AI = [:LineBreak = Ambiguous:]; 65$AL = [:LineBreak = Alphabetic:]; 66$BA = [[:LineBreak = Break_After:] - [\u2010]]; 67$HH = [\u2010]; 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:]; 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:] $CJ]; 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$HHcm = $HH $CM*; 128$BBcm = $BB $CM*; 129$B2cm = $B2 $CM*; 130$CLcm = $CL $CM*; 131$CPcm = $CP $CM*; 132$EXcm = $EX $CM*; 133$GLcm = $GL $CM*; 134$HLcm = $HL $CM*; 135$HYcm = $HY $CM*; 136$H2cm = $H2 $CM*; 137$H3cm = $H3 $CM*; 138$IDcm = $ID $CM*; 139$INcm = $IN $CM*; 140$IScm = $IS $CM*; 141$JLcm = $JL $CM*; 142$JVcm = $JV $CM*; 143$JTcm = $JT $CM*; 144$NScm = $NS $CM*; 145$NUcm = $NU $CM*; 146$OPcm = $OP $CM*; 147$POcm = $PO $CM*; 148$PRcm = $PR $CM*; 149$QUcm = $QU $CM*; 150$RIcm = $RI $CM*; 151$SYcm = $SY $CM*; 152$WJcm = $WJ $CM*; 153 154## ------------------------------------------------- 155 156!!forward; 157 158# 159# Each class of character can stand by itself as an unbroken token, with trailing combining stuff 160# 161$ALPlus $CM+; 162$BA $CM+; 163$HH $CM+; 164$BB $CM+; 165$B2 $CM+; 166$CL $CM+; 167$CP $CM+; 168$EX $CM+; 169$GL $CM+; 170$HL $CM+; 171$HY $CM+; 172$H2 $CM+; 173$H3 $CM+; 174$ID $CM+; 175$IN $CM+; 176$IS $CM+; 177$JL $CM+; 178$JV $CM+; 179$JT $CM+; 180$NS $CM+; 181$NU $CM+; 182$OP $CM+; 183$PO $CM+; 184$PR $CM+; 185$QU $CM+; 186$RI $CM+; 187$SY $CM+; 188$WJ $CM+; 189 190# 191# CAN_CM is the set of characters that may combine with CM combining chars. 192# Note that Linebreak UAX 14's concept of a combining char and the rules 193# for what they can combine with are _very_ different from the rest of Unicode. 194# 195# Note that $CM itself is left out of this set. If CM is needed as a base 196# it must be listed separately in the rule. 197# 198$CAN_CM = [^$SP $BK $CR $LF $NL $ZW $CM]; # Bases that can take CMs 199$CANT_CM = [ $SP $BK $CR $LF $NL $ZW $CM]; # Bases that can't take CMs 200 201# 202# AL_FOLLOW set of chars that can unconditionally follow an AL 203# Needed in rules where stand-alone $CM s are treated as AL. 204# Chaining is disabled with CM because it causes other failures, 205# so for this one case we need to manually list out longer sequences. 206# 207$AL_FOLLOW_NOCM = [$BK $CR $LF $NL $ZW $SP]; 208$AL_FOLLOW_CM = [$CL $CP $EX $HL $IS $SY $WJ $GL $OP $QU $BA $HH $HY $NS $IN $NU $ALPlus]; 209$AL_FOLLOW = [$AL_FOLLOW_NOCM $AL_FOLLOW_CM]; 210 211 212# 213# Rule LB 4, 5 Mandatory (Hard) breaks. 214# 215$LB4Breaks = [$BK $CR $LF $NL]; 216$LB4NonBreaks = [^$BK $CR $LF $NL]; 217$CR $LF {100}; 218 219# 220# LB 6 Do not break before hard line breaks. 221# 222$LB4NonBreaks? $LB4Breaks {100}; # LB 5 do not break before hard breaks. 223$CAN_CM $CM* $LB4Breaks {100}; 224$CM+ $LB4Breaks {100}; 225 226# LB 7 x SP 227# x ZW 228$LB4NonBreaks [$SP $ZW]; 229$CAN_CM $CM* [$SP $ZW]; 230$CM+ [$SP $ZW]; 231 232# 233# LB 8 Break after zero width space 234# TODO: ZW SP* <break> 235# An engine change is required to write the reverse rule for this. 236# For now, leave the Unicode 5.2 rule, ZW <break> 237# 238$LB8Breaks = [$LB4Breaks $ZW]; 239$LB8NonBreaks = [[$LB4NonBreaks] - [$ZW]]; 240 241 242# LB 9 Combining marks. X $CM needs to behave like X, where X is not $SP, $BK $CR $LF $NL 243# $CM not covered by the above needs to behave like $AL 244# See definition of $CAN_CM. 245 246$CAN_CM $CM+; # Stick together any combining sequences that don't match other rules. 247$CM+; 248 249# 250# LB 11 Do not break before or after WORD JOINER & related characters. 251# 252$CAN_CM $CM* $WJcm; 253$LB8NonBreaks $WJcm; 254$CM+ $WJcm; 255 256$WJcm $CANT_CM; 257$WJcm $CAN_CM $CM*; 258 259# 260# LB 12 Do not break after NBSP and related characters. 261# GL x 262# 263$GLcm $CAN_CM $CM*; 264$GLcm $CANT_CM; 265 266# 267# LB 12a Do not break before NBSP and related characters ... 268# [^SP BA HY] x GL 269# 270[[$LB8NonBreaks] - [$SP $BA $HH $HY]] $CM* $GLcm; 271$CM+ GLcm; 272 273 274 275# 276# LB 13 Don't break before ']' or '!' or ';' or '/', even after spaces. 277# 278$LB8NonBreaks $CL; 279$CAN_CM $CM* $CL; 280$CM+ $CL; # by rule 10, stand-alone CM behaves as AL 281 282$LB8NonBreaks $CP; 283$CAN_CM $CM* $CP; 284$CM+ $CP; # by rule 10, stand-alone CM behaves as AL 285 286$LB8NonBreaks $EX; 287$CAN_CM $CM* $EX; 288$CM+ $EX; # by rule 10, stand-alone CM behaves as AL 289 290$LB8NonBreaks $IS; 291$CAN_CM $CM* $IS; 292$CM+ $IS; # by rule 10, stand-alone CM behaves as AL 293 294$LB8NonBreaks $SY; 295$CAN_CM $CM* $SY; 296$CM+ $SY; # by rule 10, stand-alone CM behaves as AL 297 298 299# 300# LB 14 Do not break after OP, even after spaces 301# 302$OPcm $SP* $CAN_CM $CM*; 303$OPcm $SP* $CANT_CM; 304 305$OPcm $SP+ $CM+ $AL_FOLLOW?; # by rule 10, stand-alone CM behaves as AL 306 307# LB 15 308$QUcm $SP* $OPcm; 309 310# LB 16 311($CLcm | $CPcm) $SP* $NScm; 312 313# LB 17 314$B2cm $SP* $B2cm; 315 316# 317# LB 18 Break after spaces. 318# 319$LB18NonBreaks = [$LB8NonBreaks - [$SP]]; 320$LB18Breaks = [$LB8Breaks $SP]; 321 322 323# LB 19 324# x QU 325$LB18NonBreaks $CM* $QUcm; 326$CM+ $QUcm; 327 328# QU x 329$QUcm .?; 330$QUcm $LB18NonBreaks $CM*; # Don't let a combining mark go onto $CR, $BK, etc. 331 # TODO: I don't think this rule is needed. 332 333 334# LB 20 335# <break> $CB 336# $CB <break> 337 338$LB20NonBreaks = [$LB18NonBreaks - $CB]; 339 340# LB 20.09 added rule for Finnish tailoring 341# LB 21 x (BA | HY | NS) 342# BB x 343# 344$LB20NonBreaks $CM* ($BAcm | $HHcm | $HYcm | $NScm) / $AL; 345$LB20NonBreaks $CM* ($BAcm | $HHcm | $HYcm | $NScm); 346($HY | $HH) $AL; 347 348$BBcm [^$CB]; # $BB x 349$BBcm $LB20NonBreaks $CM*; 350 351# LB 21a Don't break after Hebrew + Hyphen 352# HL (HY | BA) x 353# 354$HLcm ($HYcm | $BAcm | $HHcm) [^$CB]?; 355 356# LB 21b (forward) Don't break between SY and HL 357# (break between HL and SY already disallowed by LB 13 above) 358$SYcm $HLcm; 359 360# LB 22 361($ALcm | $HLcm) $INcm; 362$CM+ $INcm; # by rule 10, any otherwise unattached CM behaves as AL 363$EXcm $INcm; 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* $EX; 604$CM* $IN $CM* $ID; 605$CM* $IN $CM* $IN; 606$CM* $IN $CM* $NU; 607 608# LB 23 609$CM* $PO $CM* $ID; 610$CM* $NU $CM* ($ALPlus | $HL); 611$CM* ($ALPlus | $HL) $CM* $NU; 612 613# LB 24 614$CM* $ID $CM* $PR; 615$CM* ($ALPlus | $HL) $CM* $PR; 616$CM* ($ALPlus | $HL) $CM* $PO; 617 618 619# LB 25 620($CM* ($PR | $PO))? ($CM* ($CL | $CP))? ($CM* ($NU | $IS | $SY))* $CM* $NU ($CM* ($OP | $HY))? ($CM* ($PR | $PO))?; 621 622# LB 26 623$CM* ($H3 | $H2 | $JV | $JL) $CM* $JL; 624$CM* ($JT | $JV) $CM* ($H2 | $JV); 625$CM* $JT $CM* ($H3 | $JT); 626 627# LB 27 628$CM* $IN $CM* ($H3 | $H2 | $JT | $JV | $JL); 629$CM* $PO $CM* ($H3 | $H2 | $JT | $JV | $JL); 630$CM* ($H3 | $H2 | $JT | $JV | $JL) $CM* $PR; 631 632# LB 28 633$CM* ($ALPlus | $HL) $CM* ($ALPlus | $HL); 634 635 636# LB 29 637$CM* ($ALPlus | $HL) $CM* $IS; 638 639# LB 30 640$CM* $OP $CM* ($ALPlus | $HL | $NU); 641$CM* ($ALPlus | $HL | $NU) $CM* $CP; 642 643# LB 30a 644$CM* $RI $CM* $RI; 645 646## ------------------------------------------------- 647 648!!safe_reverse; 649 650# LB 9 651$CM+ [^$CM $BK $CR $LF $NL $ZW $SP]; 652$CM+ $SP / .; 653 654# LB 14 655$SP+ $CM* $OP; 656 657# LB 15 658$SP+ $CM* $QU; 659 660# LB 16 661$SP+ $CM* ($CL | $CP); 662 663# LB 17 664$SP+ $CM* $B2; 665 666# LB 21 667$CM* ($HY | $BA | $HH) $CM* $HL; 668 669# LB 25 670($CM* ($IS | $SY))+ $CM* $NU; 671($CL | $CP) $CM* ($NU | $IS | $SY); 672 673# For dictionary-based break 674$dictionary $dictionary; 675 676## ------------------------------------------------- 677 678!!safe_forward; 679 680# Skip forward over all character classes that are involved in 681# rules containing patterns with possibly more than one char 682# of context. 683# 684# It might be slightly more efficient to have specific rules 685# instead of one generic one, but only if we could 686# turn off rule chaining. We don't want to move more 687# than necessary. 688# 689[$CM $OP $QU $CL $CP $B2 $PR $HY $BA $SP $dictionary]+ [^$CM $OP $QU $CL $CP $B2 $PR $HY $BA $dictionary]; 690$dictionary $dictionary; 691 692