]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/rbbiscan.h
4 // Copyright (C) 2002-2005, International Business Machines Corporation and others.
5 // All Rights Reserved.
7 // This file contains declarations for class RBBIRuleScanner
14 #include "unicode/utypes.h"
15 #include "unicode/uobject.h"
16 #include "unicode/rbbi.h"
17 #include "unicode/uniset.h"
18 #include "unicode/parseerr.h"
21 #include "unicode/symtable.h"// For UnicodeSet parsing, is the interface that
22 // looks up references to $variables within a set.
24 //#include "rbbitblb.h"
30 class RBBIRuleBuilder
;
31 class RBBISymbolTable
;
34 //--------------------------------------------------------------------------------
36 // class RBBIRuleScanner does the lowest level, character-at-a-time
37 // scanning of break iterator rules.
39 // The output of the scanner is parse trees for
40 // the rule expressions and a list of all Unicode Sets
43 //--------------------------------------------------------------------------------
44 static const int kStackSize
= 100; // The size of the state stack for
45 // rules parsing. Corresponds roughly
46 // to the depth of parentheses nesting
47 // that is allowed in the rules.
49 enum EParseAction
{dummy01
, dummy02
}; // Placeholder enum for the specifier for
50 // actions that are specified in the
51 // rule parsing state table.
53 class RBBIRuleScanner
: public UMemory
{
61 RBBIRuleScanner(RBBIRuleBuilder
*rb
);
64 virtual ~RBBIRuleScanner();
66 void nextChar(RBBIRuleChar
&c
); // Get the next char from the input stream.
67 // Return false if at end.
69 UBool
push(const RBBIRuleChar
&c
); // Push (unget) one character.
70 // Only a single character may be pushed.
72 void parse(); // Parse the rules, generating two parse
73 // trees, one each for the forward and
75 // and a list of UnicodeSets encountered.
78 * Return a rules string without unnecessary
81 static UnicodeString
stripRules(const UnicodeString
&rules
);
84 UBool
doParseActions(EParseAction a
);
85 void error(UErrorCode e
); // error reporting convenience function.
86 void fixOpStack(RBBINode::OpPrecedence p
);
88 void findSetFor(const UnicodeString
&s
, RBBINode
*node
, UnicodeSet
*setToAdopt
= NULL
);
92 void printNodeStack(const char *title
);
94 RBBINode
*pushNewNode(RBBINode::NodeType t
);
98 RBBIRuleBuilder
*fRB
; // The rule builder that we are part of.
100 int32_t fScanIndex
; // Index of current character being processed
101 // in the rule input string.
102 int32_t fNextIndex
; // Index of the next character, which
103 // is the first character not yet scanned.
104 UBool fQuoteMode
; // Scan is in a 'quoted region'
105 int32_t fLineNum
; // Line number in input file.
106 int32_t fCharNum
; // Char position within the line.
107 UChar32 fLastChar
; // Previous char, needed to count CR-LF
108 // as a single line, not two.
110 RBBIRuleChar fC
; // Current char for parse state machine
112 UnicodeString fVarName
; // $variableName, valid when we've just
115 RBBIRuleTableEl
**fStateTable
; // State Transition Table for RBBI Rule
116 // parsing. index by p[state][char-class]
118 uint16_t fStack
[kStackSize
]; // State stack, holds state pushes
119 int32_t fStackPtr
; // and pops as specified in the state
122 RBBINode
*fNodeStack
[kStackSize
]; // Node stack, holds nodes created
123 // during the parse of a rule
124 int32_t fNodeStackPtr
;
127 UBool fReverseRule
; // True if the rule currently being scanned
128 // is a reverse direction rule (if it
129 // starts with a '!')
131 UBool fLookAheadRule
; // True if the rule includes a '/'
132 // somewhere within it.
134 RBBISymbolTable
*fSymbolTable
; // symbol table, holds definitions of
135 // $variable symbols.
137 UHashtable
*fSetTable
; // UnicocodeSet hash table, holds indexes to
138 // the sets created while parsing rules.
139 // The key is the string used for creating
142 UnicodeSet
*fRuleSets
[10]; // Unicode Sets that are needed during
143 // the scanning of RBBI rules. The
144 // indicies for these are assigned by the
145 // perl script that builds the state tables.
148 int32_t fRuleNum
; // Counts each rule as it is scanned.
150 int32_t fOptionStart
; // Input index of start of a !!option
151 // keyword, while being scanned.
153 UnicodeSet
*gRuleSet_rule_char
;
154 UnicodeSet
*gRuleSet_white_space
;
155 UnicodeSet
*gRuleSet_name_char
;
156 UnicodeSet
*gRuleSet_name_start_char
;
158 RBBIRuleScanner(const RBBIRuleScanner
&other
); // forbid copying of this class
159 RBBIRuleScanner
&operator=(const RBBIRuleScanner
&other
); // forbid copying of this class