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