sl@0: // sl@0: // rbbirb.h sl@0: // sl@0: // Copyright (C) 2002-2004, International Business Machines Corporation and others. sl@0: // All Rights Reserved. sl@0: // sl@0: // This file contains declarations for several classes from the sl@0: // Rule Based Break Iterator rule builder. sl@0: // sl@0: sl@0: sl@0: #ifndef RBBIRB_H sl@0: #define RBBIRB_H sl@0: sl@0: #include "unicode/utypes.h" sl@0: #include "unicode/uobject.h" sl@0: #include "unicode/rbbi.h" sl@0: #include "unicode/uniset.h" sl@0: #include "unicode/parseerr.h" sl@0: #include "uhash.h" sl@0: #include "uvector.h" sl@0: #include "unicode/symtable.h"// For UnicodeSet parsing, is the interface that sl@0: // looks up references to $variables within a set. sl@0: sl@0: sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: class RBBIRuleScanner; sl@0: struct RBBIRuleTableEl; sl@0: class RBBISetBuilder; sl@0: class RBBINode; sl@0: class RBBITableBuilder; sl@0: sl@0: sl@0: sl@0: //-------------------------------------------------------------------------------- sl@0: // sl@0: // RBBISymbolTable. Implements SymbolTable interface that is used by the sl@0: // UnicodeSet parser to resolve references to $variables. sl@0: // sl@0: //-------------------------------------------------------------------------------- sl@0: class RBBISymbolTableEntry : public UMemory { // The symbol table hash table contains one sl@0: public: // of these structs for each entry. sl@0: RBBISymbolTableEntry(); sl@0: UnicodeString key; sl@0: RBBINode *val; sl@0: ~RBBISymbolTableEntry(); sl@0: sl@0: private: sl@0: RBBISymbolTableEntry(const RBBISymbolTableEntry &other); // forbid copying of this class sl@0: RBBISymbolTableEntry &operator=(const RBBISymbolTableEntry &other); // forbid copying of this class sl@0: }; sl@0: sl@0: sl@0: class RBBISymbolTable : public UMemory, public SymbolTable { sl@0: private: sl@0: const UnicodeString &fRules; sl@0: UHashtable *fHashTable; sl@0: RBBIRuleScanner *fRuleScanner; sl@0: sl@0: // These next two fields are part of the mechanism for passing references to sl@0: // already-constructed UnicodeSets back to the UnicodeSet constructor sl@0: // when the pattern includes $variable references. sl@0: const UnicodeString ffffString; // = "/uffff" sl@0: UnicodeSet *fCachedSetLookup; sl@0: sl@0: public: sl@0: // API inherited from class SymbolTable sl@0: virtual const UnicodeString* lookup(const UnicodeString& s) const; sl@0: virtual const UnicodeFunctor* lookupMatcher(UChar32 ch) const; sl@0: virtual UnicodeString parseReference(const UnicodeString& text, sl@0: ParsePosition& pos, int32_t limit) const; sl@0: sl@0: // Additional Functions sl@0: RBBISymbolTable(RBBIRuleScanner *, const UnicodeString &fRules, UErrorCode &status); sl@0: virtual ~RBBISymbolTable(); sl@0: sl@0: virtual RBBINode *lookupNode(const UnicodeString &key) const; sl@0: virtual void addEntry (const UnicodeString &key, RBBINode *val, UErrorCode &err); sl@0: sl@0: #ifdef RBBI_DEBUG sl@0: virtual void rbbiSymtablePrint() const; sl@0: #else sl@0: // A do-nothing inline function for non-debug builds. Member funcs can't be empty sl@0: // or the call sites won't compile. sl@0: int fFakeField; sl@0: #define rbbiSymtablePrint() fFakeField=0; sl@0: #endif sl@0: sl@0: private: sl@0: RBBISymbolTable(const RBBISymbolTable &other); // forbid copying of this class sl@0: RBBISymbolTable &operator=(const RBBISymbolTable &other); // forbid copying of this class sl@0: }; sl@0: sl@0: sl@0: //-------------------------------------------------------------------------------- sl@0: // sl@0: // class RBBIRuleBuilder The top-level class handling RBBI rule compiling. sl@0: // sl@0: //-------------------------------------------------------------------------------- sl@0: class RBBIRuleBuilder : public UMemory { sl@0: public: sl@0: sl@0: // Create a rule based break iterator from a set of rules. sl@0: // This function is the main entry point into the rule builder. The sl@0: // public ICU API for creating RBBIs uses this function to do the actual work. sl@0: // sl@0: static BreakIterator * createRuleBasedBreakIterator( const UnicodeString &rules, sl@0: UParseError &parseError, sl@0: UErrorCode &status); sl@0: sl@0: public: sl@0: // The "public" functions and data members that appear below are accessed sl@0: // (and shared) by the various parts that make up the rule builder. They sl@0: // are NOT intended to be accessed by anything outside of the sl@0: // rule builder implementation. sl@0: RBBIRuleBuilder(const UnicodeString &rules, sl@0: UParseError &parseErr, sl@0: UErrorCode &status sl@0: ); sl@0: sl@0: virtual ~RBBIRuleBuilder(); sl@0: char *fDebugEnv; // controls debug trace output sl@0: UErrorCode *fStatus; // Error reporting. Keeping status sl@0: UParseError *fParseError; // here avoids passing it everywhere. sl@0: const UnicodeString &fRules; // The rule string that we are compiling sl@0: sl@0: RBBIRuleScanner *fScanner; // The scanner. sl@0: RBBINode *fForwardTree; // The parse trees, generated by the scanner, sl@0: RBBINode *fReverseTree; // then manipulated by subsequent steps. sl@0: RBBINode *fSafeFwdTree; sl@0: RBBINode *fSafeRevTree; sl@0: sl@0: RBBINode **fDefaultTree; // For rules not qualified with a ! sl@0: // the tree to which they belong to. sl@0: sl@0: UBool fChainRules; // True for chained Unicode TR style rules. sl@0: // False for traditional regexp rules. sl@0: sl@0: UBool fLBCMNoChain; // True: suppress chaining of rules on sl@0: // chars with LineBreak property == CM. sl@0: sl@0: UBool fLookAheadHardBreak; // True: Look ahead matches cause an sl@0: // immediate break, no continuing for the sl@0: // longest match. sl@0: sl@0: RBBISetBuilder *fSetBuilder; // Set and Character Category builder. sl@0: UVector *fUSetNodes; // Vector of all uset nodes. sl@0: sl@0: RBBITableBuilder *fForwardTables; // State transition tables sl@0: RBBITableBuilder *fReverseTables; sl@0: RBBITableBuilder *fSafeFwdTables; sl@0: RBBITableBuilder *fSafeRevTables; sl@0: sl@0: UVector *fRuleStatusVals; // The values that can be returned sl@0: // from getRuleStatus(). sl@0: sl@0: RBBIDataHeader *flattenData(); // Create the flattened (runtime format) sl@0: // data tables.. sl@0: private: sl@0: RBBIRuleBuilder(const RBBIRuleBuilder &other); // forbid copying of this class sl@0: RBBIRuleBuilder &operator=(const RBBIRuleBuilder &other); // forbid copying of this class sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: //---------------------------------------------------------------------------- sl@0: // sl@0: // RBBISetTableEl is an entry in the hash table of UnicodeSets that have sl@0: // been encountered. The val Node will be of nodetype uset sl@0: // and contain pointers to the actual UnicodeSets. sl@0: // The Key is the source string for initializing the set. sl@0: // sl@0: // The hash table is used to avoid creating duplicate sl@0: // unnamed (not $var references) UnicodeSets. sl@0: // sl@0: // Memory Management: sl@0: // The Hash Table owns these RBBISetTableEl structs and sl@0: // the key strings. It does NOT own the val nodes. sl@0: // sl@0: //---------------------------------------------------------------------------- sl@0: struct RBBISetTableEl { sl@0: UnicodeString *key; sl@0: RBBINode *val; sl@0: }; sl@0: sl@0: sl@0: //---------------------------------------------------------------------------- sl@0: // sl@0: // RBBIDebugPrintf Printf equivalent, for debugging output. sl@0: // Conditional compilation of the implementation lets us sl@0: // get rid of the stdio dependency in environments where it sl@0: // is unavailable. sl@0: // sl@0: //---------------------------------------------------------------------------- sl@0: #ifdef RBBI_DEBUG sl@0: #include sl@0: #define RBBIDebugPrintf printf sl@0: #define RBBIDebugPuts puts sl@0: #else sl@0: #undef RBBIDebugPrintf sl@0: #define RBBIDebugPuts(arg) sl@0: #endif sl@0: sl@0: U_NAMESPACE_END sl@0: #endif sl@0: sl@0: sl@0: