2002-10-22 00:09:32 +00:00
|
|
|
//
|
|
|
|
// regexcmp.h
|
|
|
|
//
|
2003-03-20 01:15:10 +00:00
|
|
|
// Copyright (C) 2002-2003, International Business Machines Corporation and others.
|
2002-10-22 00:09:32 +00:00
|
|
|
// All Rights Reserved.
|
|
|
|
//
|
2002-11-07 02:34:46 +00:00
|
|
|
// This file contains declarations for the class RegexCompile
|
|
|
|
//
|
|
|
|
// This class is internal to the regular expression implementation.
|
|
|
|
// For the public Regular Expression API, see the file "unicode/regex.h"
|
2002-10-22 00:09:32 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef RBBISCAN_H
|
|
|
|
#define RBBISCAN_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2002-11-07 02:34:46 +00:00
|
|
|
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
#include "unicode/uobject.h"
|
|
|
|
#include "unicode/uniset.h"
|
|
|
|
#include "unicode/parseerr.h"
|
|
|
|
#include "uhash.h"
|
|
|
|
#include "uvector.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//
|
2002-11-07 02:34:46 +00:00
|
|
|
// class RegexCompile Contains the regular expression compiler.
|
2002-10-22 00:09:32 +00:00
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
static const int kStackSize = 100; // The size of the state stack for
|
|
|
|
// pattern parsing. Corresponds roughly
|
|
|
|
// to the depth of parentheses nesting
|
|
|
|
// that is allowed in the rules.
|
|
|
|
|
|
|
|
enum EParseAction {dummy01, dummy02}; // Placeholder enum for the specifier for
|
|
|
|
// actions that are specified in the
|
|
|
|
// rule parsing state table.
|
|
|
|
struct RegexTableEl;
|
|
|
|
class RegexPattern;
|
|
|
|
|
|
|
|
|
2002-11-21 01:06:00 +00:00
|
|
|
class RegexCompile : public UMemory {
|
2002-10-22 00:09:32 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
struct RegexPatternChar {
|
|
|
|
UChar32 fChar;
|
|
|
|
UBool fQuoted;
|
|
|
|
};
|
|
|
|
|
2003-02-11 01:17:51 +00:00
|
|
|
RegexCompile(RegexPattern *rp, UErrorCode &e);
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2003-02-11 01:17:51 +00:00
|
|
|
void compile(const UnicodeString &pat, UParseError &pp, UErrorCode &e);
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
virtual ~RegexCompile();
|
|
|
|
|
|
|
|
void nextChar(RegexPatternChar &c); // Get the next char from the input stream.
|
|
|
|
|
2002-11-07 20:06:39 +00:00
|
|
|
static void cleanup(); // Memory cleanup
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2003-01-31 02:00:52 +00:00
|
|
|
|
|
|
|
// Categories of parentheses in pattern.
|
|
|
|
// The category is saved in the compile-time parentheses stack frame, and
|
|
|
|
// determines the code to be generated when the matching close ) is encountered.
|
|
|
|
enum EParenClass {
|
|
|
|
plain = -1, // No special handling
|
|
|
|
capturing = -2,
|
|
|
|
atomic = -3,
|
|
|
|
lookAhead = -4,
|
2003-02-12 01:28:01 +00:00
|
|
|
negLookAhead = -5,
|
2003-03-02 19:11:09 +00:00
|
|
|
flags = -6,
|
|
|
|
lookBehind = -7,
|
|
|
|
lookBehindN = -8
|
2003-01-31 02:00:52 +00:00
|
|
|
};
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
private:
|
|
|
|
|
2003-01-31 02:00:52 +00:00
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
UBool doParseActions(EParseAction a);
|
|
|
|
void error(UErrorCode e); // error reporting convenience function.
|
|
|
|
|
|
|
|
UChar32 nextCharLL();
|
2002-10-24 22:16:07 +00:00
|
|
|
UChar32 peekCharLL();
|
2002-10-22 00:09:32 +00:00
|
|
|
UnicodeSet *scanSet();
|
2002-10-29 01:20:15 +00:00
|
|
|
UnicodeSet *scanProp();
|
2002-10-22 00:09:32 +00:00
|
|
|
void handleCloseParen();
|
2002-10-28 17:18:44 +00:00
|
|
|
int32_t blockTopLoc(UBool reserve); // Locate a position in the compiled pattern
|
2002-10-22 00:09:32 +00:00
|
|
|
// at the top of the just completed block
|
2002-10-28 17:18:44 +00:00
|
|
|
// or operation, and optionally ensure that
|
|
|
|
// there is space to add an opcode there.
|
2002-10-29 01:20:15 +00:00
|
|
|
void compileSet(UnicodeSet *theSet); // Generate the compiled pattern for
|
|
|
|
// a reference to a UnicodeSet.
|
2003-03-04 01:10:46 +00:00
|
|
|
void compileInterval(int32_t InitOp, // Generate the code for a {min,max} quantifier.
|
2003-01-16 01:12:04 +00:00
|
|
|
int32_t LoopOp);
|
2003-03-04 01:10:46 +00:00
|
|
|
void literalChar(UChar32 c); // Compile a literal char
|
2002-11-11 18:49:49 +00:00
|
|
|
void fixLiterals(UBool split=FALSE); // Fix literal strings.
|
2003-01-16 01:12:04 +00:00
|
|
|
void insertOp(int32_t where); // Open up a slot for a new op in the
|
|
|
|
// generated code at the specified location.
|
2003-02-07 02:04:14 +00:00
|
|
|
void emitONE_CHAR(UChar32 c); // EMit a ONE_CHAR op into the compiled code,
|
|
|
|
// taking case mode into account.
|
2003-02-24 05:12:29 +00:00
|
|
|
int32_t minMatchLength(int32_t start,
|
|
|
|
int32_t end);
|
2003-02-27 01:59:23 +00:00
|
|
|
int32_t maxMatchLength(int32_t start,
|
|
|
|
int32_t end);
|
2003-03-13 01:56:01 +00:00
|
|
|
void matchStartType();
|
2003-03-18 01:51:36 +00:00
|
|
|
void stripNOPs();
|
2003-03-26 01:17:16 +00:00
|
|
|
void OptEndingLoop();
|
|
|
|
void OptDotStar();
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
UErrorCode *fStatus;
|
|
|
|
RegexPattern *fRXPat;
|
|
|
|
UParseError *fParseErr;
|
|
|
|
|
2002-10-24 22:16:07 +00:00
|
|
|
//
|
|
|
|
// Data associated with low level character scanning
|
|
|
|
//
|
2002-10-22 00:09:32 +00:00
|
|
|
int32_t fScanIndex; // Index of current character being processed
|
|
|
|
// in the rule input string.
|
|
|
|
int32_t fNextIndex; // Index of the next character, which
|
|
|
|
// is the first character not yet scanned.
|
2003-02-13 01:10:22 +00:00
|
|
|
UBool fQuoteMode; // Scan is in a \Q...\E quoted region
|
|
|
|
UBool fInBackslashQuote; // Scan is between a '\' and the following char.
|
|
|
|
UBool fEOLComments; // When scan is just after '(?', inhibit #... to
|
|
|
|
// end of line comments, in favor of (?#...) comments.
|
2002-10-22 00:09:32 +00:00
|
|
|
int fLineNum; // Line number in input file.
|
|
|
|
int fCharNum; // Char position within the line.
|
|
|
|
UChar32 fLastChar; // Previous char, needed to count CR-LF
|
|
|
|
// as a single line, not two.
|
2002-10-24 22:16:07 +00:00
|
|
|
UChar32 fPeekChar; // Saved char, if we've scanned ahead.
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
RegexPatternChar fC; // Current char for parse state machine
|
|
|
|
// processing.
|
|
|
|
|
2003-02-07 02:04:14 +00:00
|
|
|
//
|
|
|
|
// Data for the state machine that parses the regular expression.
|
|
|
|
//
|
2002-10-22 00:09:32 +00:00
|
|
|
RegexTableEl **fStateTable; // State Transition Table for regex Rule
|
|
|
|
// parsing. index by p[state][char-class]
|
|
|
|
|
|
|
|
uint16_t fStack[kStackSize]; // State stack, holds state pushes
|
|
|
|
int fStackPtr; // and pops as specified in the state
|
|
|
|
// transition rules.
|
|
|
|
|
2003-02-07 02:04:14 +00:00
|
|
|
//
|
|
|
|
// Data associated with the generation of the pcode for the match engine
|
|
|
|
//
|
2003-02-12 01:28:01 +00:00
|
|
|
int32_t fModeFlags; // Match Flags. (Case Insensitive, etc.)
|
|
|
|
int32_t fNewModeFlags; // New flags, while compiling (?i, holds state
|
|
|
|
// until last flag is scanned.
|
|
|
|
UBool fSetModeFlag; // true for (?ismx, false for (?-ismx
|
|
|
|
|
2003-02-07 02:04:14 +00:00
|
|
|
|
|
|
|
int32_t fStringOpStart; // While a literal string is being scanned
|
|
|
|
// holds the start index within RegexPattern.
|
|
|
|
// fLiteralText where the string is being stored.
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
int32_t fPatternLength; // Length of the input pattern string.
|
|
|
|
|
2003-01-16 01:12:04 +00:00
|
|
|
UVector32 fParenStack; // parentheses stack. Each frame consists of
|
2002-10-22 00:09:32 +00:00
|
|
|
// the positions of compiled pattern operations
|
2003-01-16 01:12:04 +00:00
|
|
|
// needing fixup, followed by negative value. The
|
2002-10-22 00:09:32 +00:00
|
|
|
// first entry in each frame is the position of the
|
|
|
|
// spot reserved for use when a quantifier
|
|
|
|
// needs to add a SAVE at the start of a (block)
|
|
|
|
// The negative value (-1, -2,...) indicates
|
|
|
|
// the kind of paren that opened the frame. Some
|
|
|
|
// need special handling on close.
|
|
|
|
|
|
|
|
|
|
|
|
int32_t fMatchOpenParen; // The position in the compiled pattern
|
|
|
|
// of the slot reserved for a state save
|
|
|
|
// at the start of the most recently processed
|
|
|
|
// parenthesized block.
|
|
|
|
int32_t fMatchCloseParen; // The position in the pattern of the first
|
|
|
|
// location after the most recently processed
|
|
|
|
// parenthesized block.
|
|
|
|
|
2003-01-16 01:12:04 +00:00
|
|
|
int32_t fIntervalLow; // {lower, upper} interval quantifier values.
|
|
|
|
int32_t fIntervalUpper; // Placed here temporarily, when pattern is
|
|
|
|
// initially scanned. Each new interval
|
|
|
|
// encountered overwrites these values.
|
|
|
|
// -1 for the upper interval value means none
|
|
|
|
// was specified (unlimited occurences.)
|
|
|
|
|
2003-03-04 01:10:46 +00:00
|
|
|
int32_t fNameStartPos; // Starting position of a \N{NAME} name in a
|
|
|
|
// pattern, valid while remainder of name is
|
|
|
|
// scanned.
|
2002-10-22 00:09:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
2002-11-07 02:34:46 +00:00
|
|
|
#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
|
|
|
|
#endif // RBBISCAN_H
|