1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
#*****************************************************************************
#
# Copyright (C) 2016 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html
#
#*****************************************************************************
#*****************************************************************************
#
# Copyright (C) 2002-2016, International Business Machines Corporation and others.
# All Rights Reserved.
#
#*****************************************************************************
#
# file: rbbirpt.txt
# ICU Break Iterator Rule Parser State Table
#
# This state table is used when reading and parsing a set of RBBI rules
# The rule parser uses a state machine; the data in this file define the
# state transitions that occur for each input character.
#
# *** This file defines the RBBI rule grammar. This is it.
# *** The determination of what is accepted is here.
#
# This file is processed by a perl script "rbbicst.pl" to produce initialized C arrays
# that are then built with the rule parser.
#
# perl rbbicst.pl < rbbirpt.txt > rbbirpt.h
#
# Here is the syntax of the state definitions in this file:
#
#
#StateName:
# input-char n next-state ^push-state action
# input-char n next-state ^push-state action
# | | | | |
# | | | | |--- action to be performed by state machine
# | | | | See function RBBIRuleScanner::doParseActions()
# | | | |
# | | | |--- Push this named state onto the state stack.
# | | | Later, when next state is specified as "pop",
# | | | the pushed state will become the current state.
# | | |
# | | |--- Transition to this state if the current input character matches the input
# | | character or char class in the left hand column. "pop" causes the next
# | | state to be popped from the state stack.
# | |
# | |--- When making the state transition specified on this line, advance to the next
# | character from the input only if 'n' appears here.
# |
# |--- Character or named character classes to test for. If the current character being scanned
# matches, perform the actions and go to the state specified on this line.
# The input character is tested sequentally, in the order written. The characters and
# character classes tested for do not need to be mutually exclusive. The first match wins.
#
#
# start state, scan position is at the beginning of the rules file, or in between two rules.
#
start:
escaped term ^break-rule-end doExprStart
white_space n start
'^' n start-after-caret ^break-rule-end doNoChain
'$' scan-var-name ^assign-or-rule doExprStart
'!' n rev-option
';' n start # ignore empty rules.
eof exit
default term ^break-rule-end doExprStart
#
# break-rule-end: Returned from doing a break-rule expression.
#
break-rule-end:
';' n start doEndOfRule
white_space n break-rule-end
default errorDeath doRuleError
#
# start of a rule, after having seen a '^' (inhibits rule chain in).
# Similar to the main 'start' state in most respects, except
# - empty rule is an error.
# - A second '^' is an error.
#
start-after-caret:
escaped term doExprStart
white_space n start-after-caret
'^' errorDeath doRuleError # two '^'s
'$' scan-var-name ^term-var-ref doExprStart
';' errorDeath doRuleError # ^ ;
eof errorDeath doRuleError
default term doExprStart
#
# ! We've just scanned a '!', indicating either a !!key word flag or a
# !Reverse rule.
#
rev-option:
'!' n option-scan1
default reverse-rule ^break-rule-end doReverseDir
option-scan1:
name_start_char n option-scan2 doOptionStart
default errorDeath doRuleError
option-scan2:
name_char n option-scan2
default option-scan3 doOptionEnd
option-scan3:
';' n start
white_space n option-scan3
default errorDeath doRuleError
reverse-rule:
default term ^break-rule-end doExprStart
#
# term. Eat through a single rule character, or a composite thing, which
# could be a parenthesized expression, a variable name, or a Unicode Set.
#
term:
escaped n expr-mod doRuleChar
white_space n term
rule_char n expr-mod doRuleChar
'[' scan-unicode-set ^expr-mod
'(' n term ^expr-mod doLParen
'$' scan-var-name ^term-var-ref
'.' n expr-mod doDotAny
default errorDeath doRuleError
#
# term-var-ref We've just finished scanning a reference to a $variable.
# Check that the variable was defined.
# The variable name scanning is in common with assignment statements,
# so the check can't be done there.
term-var-ref:
default expr-mod doCheckVarDef
#
# expr-mod We've just finished scanning a term, now look for the optional
# trailing '*', '?', '+'
#
expr-mod:
white_space n expr-mod
'*' n expr-cont doUnaryOpStar
'+' n expr-cont doUnaryOpPlus
'?' n expr-cont doUnaryOpQuestion
default expr-cont
#
# expr-cont Expression, continuation. At a point where additional terms are
# allowed, but not required.
#
expr-cont:
escaped term doExprCatOperator
white_space n expr-cont
rule_char term doExprCatOperator
'[' term doExprCatOperator
'(' term doExprCatOperator
'$' term doExprCatOperator
'.' term doExprCatOperator
'/' look-ahead doExprCatOperator
'{' n tag-open doExprCatOperator
'|' n term doExprOrOperator
')' n pop doExprRParen
default pop doExprFinished
#
# look-ahead Scanning a '/', which identifies a break point, assuming that the
# remainder of the expression matches.
#
# Generate a parse tree as if this was a special kind of input symbol
# appearing in an otherwise normal concatenation expression.
#
look-ahead:
'/' n expr-cont-no-slash doSlash
default errorDeath
#
# expr-cont-no-slash Expression, continuation. At a point where additional terms are
# allowed, but not required. Just like
# expr-cont, above, except that no '/'
# look-ahead symbol is permitted.
#
expr-cont-no-slash:
escaped term doExprCatOperator
white_space n expr-cont
rule_char term doExprCatOperator
'[' term doExprCatOperator
'(' term doExprCatOperator
'$' term doExprCatOperator
'.' term doExprCatOperator
'|' n term doExprOrOperator
')' n pop doExprRParen
default pop doExprFinished
#
# tags scanning a '{', the opening delimiter for a tag that identifies
# the kind of match. Scan the whole {dddd} tag, where d=digit
#
tag-open:
white_space n tag-open
digit_char tag-value doStartTagValue
default errorDeath doTagExpectedError
tag-value:
white_space n tag-close
'}' tag-close
digit_char n tag-value doTagDigit
default errorDeath doTagExpectedError
tag-close:
white_space n tag-close
'}' n expr-cont-no-tag doTagValue
default errorDeath doTagExpectedError
#
# expr-cont-no-tag Expression, continuation. At a point where additional terms are
# allowed, but not required. Just like
# expr-cont, above, except that no "{ddd}"
# tagging is permitted.
#
expr-cont-no-tag:
escaped term doExprCatOperator
white_space n expr-cont-no-tag
rule_char term doExprCatOperator
'[' term doExprCatOperator
'(' term doExprCatOperator
'$' term doExprCatOperator
'.' term doExprCatOperator
'/' look-ahead doExprCatOperator
'|' n term doExprOrOperator
')' n pop doExprRParen
default pop doExprFinished
#
# Variable Name Scanning.
#
# The state that branched to here must have pushed a return state
# to go to after completion of the variable name scanning.
#
# The current input character must be the $ that introduces the name.
# The $ is consumed here rather than in the state that first detected it
# so that the doStartVariableName action only needs to happen in one
# place (here), and the other states don't need to worry about it.
#
scan-var-name:
'$' n scan-var-start doStartVariableName
default errorDeath
scan-var-start:
name_start_char n scan-var-body
default errorDeath doVariableNameExpectedErr
scan-var-body:
name_char n scan-var-body
default pop doEndVariableName
#
# scan-unicode-set Unicode Sets are parsed by the the UnicodeSet class.
# Within the RBBI parser, after finding the first character
# of a Unicode Set, we just hand the rule input at that
# point of to the Unicode Set constructor, then pick
# up parsing after the close of the set.
#
# The action for this state invokes the UnicodeSet parser.
#
scan-unicode-set:
'[' n pop doScanUnicodeSet
'p' n pop doScanUnicodeSet
'P' n pop doScanUnicodeSet
default errorDeath
#
# assign-or-rule. A $variable was encountered at the start of something, could be
# either an assignment statement or a rule, depending on whether an '='
# follows the variable name. We get to this state when the variable name
# scanning does a return.
#
assign-or-rule:
white_space n assign-or-rule
'=' n term ^assign-end doStartAssign # variable was target of assignment
default term-var-ref ^break-rule-end # variable was a term in a rule
#
# assign-end This state is entered when the end of the expression on the
# right hand side of an assignment is found. We get here via
# a pop; this state is pushed when the '=' in an assignment is found.
#
# The only thing allowed at this point is a ';'. The RHS of an
# assignment must look like a rule expression, and we come here
# when what is being scanned no longer looks like an expression.
#
assign-end:
';' n start doEndAssign
default errorDeath doRuleErrorAssignExpr
#
# errorDeath. This state is specified as the next state whenever a syntax error
# in the source rules is detected. Barring bugs, the state machine will never
# actually get here, but will stop because of the action associated with the error.
# But, just in case, this state asks the state machine to exit.
errorDeath:
default n errorDeath doExit
|