#
+# Copyright (C) 2016 and later: Unicode, Inc. and others.
+# License & terms of use: http://www.unicode.org/copyright.html
# Copyright (c) 2016, International Business Machines Corporation and others. All Rights Reserved.
#
# file: line_loose_cj.txt
#
-# Reference Line Break rules for intltest rbbi/RBBIMonkeyTest
+# Reference Line Break rules for intltest rbbi/RBBIMonkeyTest.
+# Rules derived from Unicode Standard Annex #14 Revision 44 for Unicode 13.0
#
# Note: Rule syntax and the monkey test itself are still a work in progress.
# They are expected to change with review and the addition of support for rule tailoring.
#
# Line Breaking Rules
-# Implement default line breaking as defined by
-# Unicode Standard Annex #14 Revision 34 for Unicode 8.0
-# http://www.unicode.org/reports/tr14/
-# tailored as noted in 2nd paragraph below..
+# Implement default line breaking as defined by
+# Unicode Standard Annex #14
+# http://www.unicode.org/reports/tr14/, tailored as noted below.
#
# This tailors the line break behavior to correspond to CSS
# line-break=loose (BCP47 -u-lb-loose) as defined for Chinese & Japanese.
# this includes: 00B0 2030 2032 2033 2035 2103 2109 FE6A FF05 FFE0
# * after prefix characters with LineBreak class PR and EastAsianWidth A,F,W;
# this includes: 00A4 00B1 20AC 2116 FE69 FF04 FFE1 FFE5 FFE6
+# It allows breaking before 201C and after 201D, for zh_Hans, zh_Hant, and ja.
type = line;
AI = [:LineBreak = Ambiguous:];
-AL = [[:LineBreak = Alphabetic:]-[\u2764]];
+AL = [:LineBreak = Alphabetic:];
BAX = [\u2010 \u2013];
BA = [[:LineBreak = Break_After:] - BAX];
+HH = [\u2010]; # \u2010 is HYPHEN, default line break is BA.
BB = [:LineBreak = Break_Before:];
BK = [:LineBreak = Mandatory_Break:];
B2 = [:LineBreak = Break_Both:];
CB = [:LineBreak = Contingent_Break:];
CJ = [:LineBreak = Conditional_Japanese_Starter:];
-CL = [:LineBreak = Close_Punctuation:];
-CM = [:LineBreak = Combining_Mark:];
+CL = [[:LineBreak = Close_Punctuation:] \u201d];
+CMS = [:LineBreak = Combining_Mark:];
CP = [:LineBreak = Close_Parenthesis:];
CR = [:LineBreak = Carriage_Return:];
-
-EB = [\u261D\u26F9\u270A-\u270D\U0001F385\U0001F3C3-\U0001F3C4\U0001F3CA-\U0001F3CB\U0001F442-\U0001F443\U0001F446-\U0001F450\U0001F466-\U0001F469\U0001F46E\U0001F470-\U0001F478\U0001F47C\U0001F481-\U0001F483\U0001F485-\U0001F487\U0001F4AA\U0001F575\U0001F590\U0001F595-\U0001F596\U0001F645-\U0001F647\U0001F64B-\U0001F64F\U0001F6A3\U0001F6B4-\U0001F6B6\U0001F6C0\U0001F918];
-EM = [\U0001F3FB-\U0001F3FF];
-
+EB = [[:LineBreak = EB:] \U0001F46A-\U0001F46D\U0001F46F\U0001F91D\U0001F93C];
+EM = [:LineBreak = EM:];
EXX = [\uFF01 \uFF1F];
EX = [[:LineBreak = Exclamation:] - EXX];
GL = [:LineBreak = Glue:];
HY = [:LineBreak = Hyphen:];
H2 = [:LineBreak = H2:];
H3 = [:LineBreak = H3:];
-ID = [[:LineBreak = Ideographic:][\u2764]CJ];
+ID = [[:LineBreak = Ideographic:] CJ]; # CSS Loose tailoring: CJ resolves to ID
IN = [:LineBreak = Inseperable:];
IS = [:LineBreak = Infix_Numeric:];
JL = [:LineBreak = JL:];
NSX = [\u301C \u30A0 \u3005 \u303B \u309D \u309E \u30FD \u30FE \u203C \u2047 \u2048 \u2049 \u30FB \uFF1A \uFF1B \uFF65];
NS = [[:LineBreak = Nonstarter:] - NSX];
NU = [:LineBreak = Numeric:];
-OP = [:LineBreak = Open_Punctuation:];
+OP = [[:LineBreak = Open_Punctuation:] \u201c];
POX = [\u00B0 \u2030 \u2032 \u2033 \u2035 \u2103 \u2109 \uFE6A \uFF05 \uFFE0];
PO = [[:LineBreak = Postfix_Numeric:] - POX];
PRX = [\u00A4 \u00B1 \u20AC \u2116 \uFE69 \uFF04 \uFFE1 \uFFE5 \uFFE6];
PR = [[:LineBreak = Prefix_Numeric:] - PRX];
-QU = [:LineBreak = Quotation:];
+QU = [[:LineBreak = Quotation:] - [\u201c\u201d]];
RI = [:LineBreak = Regional_Indicator:];
SA = [:LineBreak = Complex_Context:];
SG = [:LineBreak = Surrogate:];
WJ = [:LineBreak = Word_Joiner:];
XX = [:LineBreak = Unknown:];
ZW = [:LineBreak = ZWSpace:];
-ZJ = [\u200D];
+ZWJ = [:LineBreak = ZWJ:];
+
+# OP30 and CP30 are variants of OP and CP that appear in rule LB30 from UAX 14.
+# Limitations of this monkey test rule parser require that these definitions be pulled out
+# rather than appearing in-line in LB 30.
-# TODO: adjustment to sets needed only until Unicode properties are updated for Emoji.
-ID = [ID - EB];
-AL = [AL - EM];
+OP30 = [OP - [\p{ea=F}\p{ea=W}\p{ea=H}]];
+CP30 = [CP - [\p{ea=F}\p{ea=W}\p{ea=H}]];
-dictionary = [:LineBreak = Complex_Context:];
+# LB1 - Resolve AI, CB, CJ, SA, SG, and XX into other line breaking classes
+AL = [AL AI SG XX ];
+dictionary = SA;
-# Redfine AL. LB1. TODO: refine according to latest UAX.
-AL = [ AL AI SA SG XX ];
+# By LB9, a ZWJ also behaves as a CM. Including it in the definition of CM avoids having to explicitly
+# list it in the numerous rules that use CM.
+CM = [CMS ZWJ];
LB4: BK ÷;
LB5: CR LF;
LB6: . (BK | CR | LF | NL);
LB6.1: [^BK CR LF NL SP ZW] CM* (BK | CR | LF | NL);
+# LB8 break after ZW SP*.
+# Precedes LB7 because both rules will match the sequences like ZW SP,
+# and LB8 must take precedence.
+
+LB8: ZW SP* ÷ [^ZW SP BK CR LF NL];
+
+# Numbers. Equivalent to Tailoring example 8 from UAX 14.
+# Moved up, before LB14, because it can match longer sequences which must take precedence.
+# Loose_cj tailoring: do not include $PRX at the beginning or $POX at the end.
+LB25: ((PR | PO | POX)CM*)? ((OP | HY)CM*)? (IS CM*)? NU (CM*(NU | SY | IS))* (CM*(CL | CP))? (CM*(PR | PRX | PO))?;
+
# Rules LB14 - LB17.
-# Moved before LB7, because they can match a longer sequence that would also match LB7,
-# for example, the sequence "OP CM SP AL" matches LB14 while the prefix of it,
-# "while only the prefix "OP CM SP" matches LB7.1
+# Moved up, before LB7, because they can match a longer sequence that would also match LB7.
+# For example, the sequence "OP CM SP AL" matches LB14
+# while the prefix of it, "OP CM SP" matches LB7.1
LB14: OP CM* SP* .;
+
+# LB 14a Break before an IS that begins a number and follows a space.
+LB14a: SP ÷ IS CM* NU;
+
+# LB14b × IS
+LB14b.1: [^SP] CM* IS;
+LB14b.2: SP IS;
+
LB15: QU CM* SP* OP;
LB16: (CL | CP)CM* SP* NS;
LB17: B2 CM* SP* B2;
+
+# LB7 Do not break before spaces or zero width space.
+
LB7.1: [^ZW SP] CM* [SP ZW];
LB7.2: [ZW SP] [SP ZW];
-# LB8, ICU differs from UAX-14,
-# ICU: ZW ÷;
-# UAX 14: ZW SP* ÷;
-LB8: ZW ÷;
-
-# LB8a, from Emoji proposal L2/16-011R3
-# ZWJ x ID
-LB8a: ZJ (ID | EB | EM);
+# LB8a
+# ZWJ x
+# Don't match a CM on the right - let other rules pick up CM sequences, where
+# the ZWJ behaves as just another generic CM.
+LB8a: ZWJ [^CM];
# LB9: X CM -> X
#LB11: × WJ;
# WJ ×
-LB11.1: [^BK CR LF NL SP ZW] CM* WJ;
+LB11.1: [^SP] CM* WJ;
LB11.2: SP WJ;
LB11.3: WJ CM* [^CM];
LB12a: [^SP BA BAX HY] CM* GL;
-# LB 13 ICU Tailoring, matches tailoring exmaple 8 from UAX 14.
-#
-# LB13.1 [^SP] CM* [CL CP EX IS SY] # original UAX 14 rule.
-# LB13.2 SP CM* [CL CP EX IS SY]
-
-LB13.1: [^NU SP] CM* [CL CP IS SY];
-LB13.2: [^SP] CM* EX;
-LB13.2: SP [CL CP EX IS SY];
+# LB 13 Do not break before ‘]’ or ‘!’ or ‘/’, even after spaces.
+LB13.1: [^SP] CM* [CL CP EX SY];
+LB13.2: SP [CL CP EX SY];
# LB 14-17 are moved above LB 7.
LB19.1: QU CM* [^CM];
# LB 20 Break before and after CB.
-# Interaction with LB8a: ZJ x ID is tricky because CM includes ZJ.
-# ZJ acts like a CM to the left, combining with CB.
-# ZJ acts independently to the right, no break from ID by LB8a.
-LB20: . CM* ÷ CB;
-LB20.1a: CB CM* ZJ (ID | EB | EM);
-LB20.1b: CB CM* ÷;
+# Interaction with LB8a: ZWJ x . is tricky because CM includes ZWJ.
+# ZWJ acts like a CM to the left, combining with CB.
+# ZWJ acts independently to the right, no break after by LB8a.
+LB20.1: . CM* ZWJ CB;
+LB20.2: . CM* ÷ CB;
+
+LB20.3: CB CM* ZWJ [^CM];
+LB20.4: CB CM* ÷;
+
+# LB 20.09 Don't break between Hyphens and Letters when there is a break preceding the hyphen.
+LB20.09: ^(HY | HH) CM* AL;
# Note: Rule 21a must come before 21 to prevent 21.1 from matching HL BA, then
# not picking up the continuing match after the BA from 21a.
LB21b: SY CM* HL;
-LB22.1: (AL | HL | CM) CM* IN; # The CM is from LB10, treat an unattached CM as AL.
-LB22.2: EX CM* IN;
-LB22.3: (ID | EB | EM) CM* IN;
-# LB22.4: IN CM* IN; # delete this rule for CSS loose.
-LB22.5: NU CM* IN;
-LB23.1: (ID | EB | EM) CM* PO;
-LB23.2: (AL | HL | CM) CM* NU;
-LB23.3: NU CM* (AL | HL);
+LB22: [^IN] CM* IN; # For CSS Loose, allow breaks between adjacent ellipses characters.
-LB24.1: PR CM* (ID | EB | EM);
-LB24.2: PR CM* (AL | HL);
-LB24.3: (PO | POX) CM* (AL | HL);
-LB24.4: (AL | HL | CM) CM* (PR | PO | POX);
+LB23.1: (AL | HL | CM) CM* NU;
+LB23.2: NU CM* (AL | HL);
+
+LB23a.1: PR CM* (ID | EB | EM);
+LB23a.2: (ID | EB | EM) CM* PO;
+
+LB24.2: (PR | PO | POX) CM* (AL | HL);
+LB24.3: (AL | HL | CM) CM* (PR | PO | POX);
-# Numbers. Equivalent to Tailoring example 8 from UAx 14.
-# Loose_cj tailoring: do not include $PRX at the beginning or $POX at the end.
-LB25: ((PR | PO | POX)CM*)? ((OP | HY)CM*)? NU (CM*(NU | SY | IS))* (CM*(CL | CP))? (CM*(PR | PRX | PO))?;
LB26.1: JL CM* (JL | JV | H2 | H3);
LB26.2: (JV | H2) CM* (JV | JT);
LB29: IS CM* (AL | HL);
# LB30 is adjusted for unattached leading CM being treated as AL.
-LB30.1: (AL | CM | HL | NU) CM* OP;
-LB30.2: CP CM* (AL | HL | NU);
+LB30.1: (AL | CM | HL | NU) CM* OP30;
+LB30.2: CP30 CM* (AL | HL | NU);
-# LB31 keep pairs of RI together.
-LB30a.1: RI CM* RI CM* [BK CR LF NL SP ZW WJ GL CL CP EX IS SY QU BA HY NS];
-LB30a.2: RI CM* RI CM* ZJ (ID | EB | EM);
-LB30a.3: RI CM* RI CM* ÷;
+# LB30a keep pairs of RI together.
+LB30a.1: RI CM* RI ÷ [^BK CR LF NL SP ZW WJ CL CP EX IS SY GL QU BA HY NS IN CM];
+LB30a.2: RI CM* RI CM* CMS ÷ [^BK CR LF NL SP ZW WJ CL CP EX IS SY GL QU BA HY NS IN CM];
+LB30a.3: RI CM* RI CM* [BK CR LF NL SP ZW WJ GL CL CP EX IS SY QU BA HY NS IN ZWJ]?;
# LB30b Do not break between Emoji Base and Emoji Modifier
LB30b: EB CM* EM;
# LB31 Break Everywhere Else.
# Include combining marks
-LB31.1: . CM* ZJ (ID | EB | EM);
+LB31.1: . CM* ZWJ [^CM];
LB31.2: . CM* ÷;