michael@0: // michael@0: // rbbiscan.h michael@0: // michael@0: // Copyright (C) 2002-2008, International Business Machines Corporation and others. michael@0: // All Rights Reserved. michael@0: // michael@0: // This file contains declarations for class RBBIRuleScanner michael@0: // michael@0: michael@0: michael@0: #ifndef RBBISCAN_H michael@0: #define RBBISCAN_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/rbbi.h" michael@0: #include "unicode/uniset.h" michael@0: #include "unicode/parseerr.h" michael@0: #include "uhash.h" michael@0: #include "uvector.h" michael@0: #include "unicode/symtable.h"// For UnicodeSet parsing, is the interface that michael@0: // looks up references to $variables within a set. michael@0: #include "rbbinode.h" michael@0: //#include "rbbitblb.h" michael@0: michael@0: michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class RBBIRuleBuilder; michael@0: class RBBISymbolTable; michael@0: michael@0: michael@0: //-------------------------------------------------------------------------------- michael@0: // michael@0: // class RBBIRuleScanner does the lowest level, character-at-a-time michael@0: // scanning of break iterator rules. michael@0: // michael@0: // The output of the scanner is parse trees for michael@0: // the rule expressions and a list of all Unicode Sets michael@0: // encountered. michael@0: // michael@0: //-------------------------------------------------------------------------------- michael@0: michael@0: class RBBIRuleScanner : public UMemory { michael@0: public: michael@0: michael@0: enum { michael@0: kStackSize = 100 // The size of the state stack for michael@0: }; // rules parsing. Corresponds roughly michael@0: // to the depth of parentheses nesting michael@0: // that is allowed in the rules. michael@0: michael@0: struct RBBIRuleChar { michael@0: UChar32 fChar; michael@0: UBool fEscaped; michael@0: }; michael@0: michael@0: RBBIRuleScanner(RBBIRuleBuilder *rb); michael@0: michael@0: michael@0: virtual ~RBBIRuleScanner(); michael@0: michael@0: void nextChar(RBBIRuleChar &c); // Get the next char from the input stream. michael@0: // Return false if at end. michael@0: michael@0: UBool push(const RBBIRuleChar &c); // Push (unget) one character. michael@0: // Only a single character may be pushed. michael@0: michael@0: void parse(); // Parse the rules, generating two parse michael@0: // trees, one each for the forward and michael@0: // reverse rules, michael@0: // and a list of UnicodeSets encountered. michael@0: michael@0: /** michael@0: * Return a rules string without unnecessary michael@0: * characters. michael@0: */ michael@0: static UnicodeString stripRules(const UnicodeString &rules); michael@0: private: michael@0: michael@0: UBool doParseActions(int32_t a); michael@0: void error(UErrorCode e); // error reporting convenience function. michael@0: void fixOpStack(RBBINode::OpPrecedence p); michael@0: // a character. michael@0: void findSetFor(const UnicodeString &s, RBBINode *node, UnicodeSet *setToAdopt = NULL); michael@0: michael@0: UChar32 nextCharLL(); michael@0: #ifdef RBBI_DEBUG michael@0: void printNodeStack(const char *title); michael@0: #endif michael@0: RBBINode *pushNewNode(RBBINode::NodeType t); michael@0: void scanSet(); michael@0: michael@0: michael@0: RBBIRuleBuilder *fRB; // The rule builder that we are part of. michael@0: michael@0: int32_t fScanIndex; // Index of current character being processed michael@0: // in the rule input string. michael@0: int32_t fNextIndex; // Index of the next character, which michael@0: // is the first character not yet scanned. michael@0: UBool fQuoteMode; // Scan is in a 'quoted region' michael@0: int32_t fLineNum; // Line number in input file. michael@0: int32_t fCharNum; // Char position within the line. michael@0: UChar32 fLastChar; // Previous char, needed to count CR-LF michael@0: // as a single line, not two. michael@0: michael@0: RBBIRuleChar fC; // Current char for parse state machine michael@0: // processing. michael@0: UnicodeString fVarName; // $variableName, valid when we've just michael@0: // scanned one. michael@0: michael@0: RBBIRuleTableEl **fStateTable; // State Transition Table for RBBI Rule michael@0: // parsing. index by p[state][char-class] michael@0: michael@0: uint16_t fStack[kStackSize]; // State stack, holds state pushes michael@0: int32_t fStackPtr; // and pops as specified in the state michael@0: // transition rules. michael@0: michael@0: RBBINode *fNodeStack[kStackSize]; // Node stack, holds nodes created michael@0: // during the parse of a rule michael@0: int32_t fNodeStackPtr; michael@0: michael@0: michael@0: UBool fReverseRule; // True if the rule currently being scanned michael@0: // is a reverse direction rule (if it michael@0: // starts with a '!') michael@0: michael@0: UBool fLookAheadRule; // True if the rule includes a '/' michael@0: // somewhere within it. michael@0: michael@0: RBBISymbolTable *fSymbolTable; // symbol table, holds definitions of michael@0: // $variable symbols. michael@0: michael@0: UHashtable *fSetTable; // UnicocodeSet hash table, holds indexes to michael@0: // the sets created while parsing rules. michael@0: // The key is the string used for creating michael@0: // the set. michael@0: michael@0: UnicodeSet fRuleSets[10]; // Unicode Sets that are needed during michael@0: // the scanning of RBBI rules. The michael@0: // indicies for these are assigned by the michael@0: // perl script that builds the state tables. michael@0: // See rbbirpt.h. michael@0: michael@0: int32_t fRuleNum; // Counts each rule as it is scanned. michael@0: michael@0: int32_t fOptionStart; // Input index of start of a !!option michael@0: // keyword, while being scanned. michael@0: michael@0: UnicodeSet *gRuleSet_rule_char; michael@0: UnicodeSet *gRuleSet_white_space; michael@0: UnicodeSet *gRuleSet_name_char; michael@0: UnicodeSet *gRuleSet_name_start_char; michael@0: michael@0: RBBIRuleScanner(const RBBIRuleScanner &other); // forbid copying of this class michael@0: RBBIRuleScanner &operator=(const RBBIRuleScanner &other); // forbid copying of this class michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif