]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/regexcmp.h
4 // Copyright (C) 2002-2003, International Business Machines Corporation and others.
5 // All Rights Reserved.
7 // This file contains declarations for the class RegexCompile
9 // This class is internal to the regular expression implementation.
10 // For the public Regular Expression API, see the file "unicode/regex.h"
17 #include "unicode/utypes.h"
18 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
20 #include "unicode/uobject.h"
21 #include "unicode/uniset.h"
22 #include "unicode/parseerr.h"
31 //--------------------------------------------------------------------------------
33 // class RegexCompile Contains the regular expression compiler.
35 //--------------------------------------------------------------------------------
36 static const int kStackSize
= 100; // The size of the state stack for
37 // pattern parsing. Corresponds roughly
38 // to the depth of parentheses nesting
39 // that is allowed in the rules.
41 enum EParseAction
{dummy01
, dummy02
}; // Placeholder enum for the specifier for
42 // actions that are specified in the
43 // rule parsing state table.
48 class RegexCompile
: public UMemory
{
51 struct RegexPatternChar
{
56 RegexCompile(RegexPattern
*rp
, UErrorCode
&e
);
58 void compile(const UnicodeString
&pat
, UParseError
&pp
, UErrorCode
&e
);
61 virtual ~RegexCompile();
63 void nextChar(RegexPatternChar
&c
); // Get the next char from the input stream.
65 static void cleanup(); // Memory cleanup
69 // Categories of parentheses in pattern.
70 // The category is saved in the compile-time parentheses stack frame, and
71 // determines the code to be generated when the matching close ) is encountered.
73 plain
= -1, // No special handling
86 UBool
doParseActions(EParseAction a
);
87 void error(UErrorCode e
); // error reporting convenience function.
91 UnicodeSet
*scanSet();
92 UnicodeSet
*scanProp();
93 void handleCloseParen();
94 int32_t blockTopLoc(UBool reserve
); // Locate a position in the compiled pattern
95 // at the top of the just completed block
96 // or operation, and optionally ensure that
97 // there is space to add an opcode there.
98 void compileSet(UnicodeSet
*theSet
); // Generate the compiled pattern for
99 // a reference to a UnicodeSet.
100 void compileInterval(int32_t InitOp
, // Generate the code for a {min,max} quantifier.
102 UBool
compileInlineInterval(); // Generate inline code for a {min,max} quantifier
103 void literalChar(UChar32 c
); // Compile a literal char
104 void fixLiterals(UBool split
=FALSE
); // Fix literal strings.
105 void insertOp(int32_t where
); // Open up a slot for a new op in the
106 // generated code at the specified location.
107 void emitONE_CHAR(UChar32 c
); // EMit a ONE_CHAR op into the compiled code,
108 // taking case mode into account.
109 int32_t minMatchLength(int32_t start
,
111 int32_t maxMatchLength(int32_t start
,
113 void matchStartType();
119 RegexPattern
*fRXPat
;
120 UParseError
*fParseErr
;
123 // Data associated with low level character scanning
125 int32_t fScanIndex
; // Index of current character being processed
126 // in the rule input string.
127 int32_t fNextIndex
; // Index of the next character, which
128 // is the first character not yet scanned.
129 UBool fQuoteMode
; // Scan is in a \Q...\E quoted region
130 UBool fInBackslashQuote
; // Scan is between a '\' and the following char.
131 UBool fEOLComments
; // When scan is just after '(?', inhibit #... to
132 // end of line comments, in favor of (?#...) comments.
133 int fLineNum
; // Line number in input file.
134 int fCharNum
; // Char position within the line.
135 UChar32 fLastChar
; // Previous char, needed to count CR-LF
136 // as a single line, not two.
137 UChar32 fPeekChar
; // Saved char, if we've scanned ahead.
140 RegexPatternChar fC
; // Current char for parse state machine
144 // Data for the state machine that parses the regular expression.
146 RegexTableEl
**fStateTable
; // State Transition Table for regex Rule
147 // parsing. index by p[state][char-class]
149 uint16_t fStack
[kStackSize
]; // State stack, holds state pushes
150 int fStackPtr
; // and pops as specified in the state
154 // Data associated with the generation of the pcode for the match engine
156 int32_t fModeFlags
; // Match Flags. (Case Insensitive, etc.)
157 int32_t fNewModeFlags
; // New flags, while compiling (?i, holds state
158 // until last flag is scanned.
159 UBool fSetModeFlag
; // true for (?ismx, false for (?-ismx
162 int32_t fStringOpStart
; // While a literal string is being scanned
163 // holds the start index within RegexPattern.
164 // fLiteralText where the string is being stored.
166 int32_t fPatternLength
; // Length of the input pattern string.
168 UVector32 fParenStack
; // parentheses stack. Each frame consists of
169 // the positions of compiled pattern operations
170 // needing fixup, followed by negative value. The
171 // first entry in each frame is the position of the
172 // spot reserved for use when a quantifier
173 // needs to add a SAVE at the start of a (block)
174 // The negative value (-1, -2,...) indicates
175 // the kind of paren that opened the frame. Some
176 // need special handling on close.
179 int32_t fMatchOpenParen
; // The position in the compiled pattern
180 // of the slot reserved for a state save
181 // at the start of the most recently processed
182 // parenthesized block.
183 int32_t fMatchCloseParen
; // The position in the pattern of the first
184 // location after the most recently processed
185 // parenthesized block.
187 int32_t fIntervalLow
; // {lower, upper} interval quantifier values.
188 int32_t fIntervalUpper
; // Placed here temporarily, when pattern is
189 // initially scanned. Each new interval
190 // encountered overwrites these values.
191 // -1 for the upper interval value means none
192 // was specified (unlimited occurences.)
194 int32_t fNameStartPos
; // Starting position of a \N{NAME} name in a
195 // pattern, valid while remainder of name is
200 #endif // !UCONFIG_NO_REGULAR_EXPRESSIONS