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