michael@0: /******************************************************************** michael@0: * COPYRIGHT: michael@0: * Copyright (c) 2001-2006, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ********************************************************************/ michael@0: michael@0: #ifndef RBBINODE_H michael@0: #define RBBINODE_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uobject.h" michael@0: michael@0: // michael@0: // class RBBINode michael@0: // michael@0: // Represents a node in the parse tree generated when reading michael@0: // a rule file. michael@0: // michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class UnicodeSet; michael@0: class UVector; michael@0: michael@0: class RBBINode : public UMemory { michael@0: public: michael@0: enum NodeType { michael@0: setRef, michael@0: uset, michael@0: varRef, michael@0: leafChar, michael@0: lookAhead, michael@0: tag, michael@0: endMark, michael@0: opStart, michael@0: opCat, michael@0: opOr, michael@0: opStar, michael@0: opPlus, michael@0: opQuestion, michael@0: opBreak, michael@0: opReverse, michael@0: opLParen michael@0: }; michael@0: michael@0: enum OpPrecedence { michael@0: precZero, michael@0: precStart, michael@0: precLParen, michael@0: precOpOr, michael@0: precOpCat michael@0: }; michael@0: michael@0: NodeType fType; michael@0: RBBINode *fParent; michael@0: RBBINode *fLeftChild; michael@0: RBBINode *fRightChild; michael@0: UnicodeSet *fInputSet; // For uset nodes only. michael@0: OpPrecedence fPrecedence; // For binary ops only. michael@0: michael@0: UnicodeString fText; // Text corresponding to this node. michael@0: // May be lazily evaluated when (if) needed michael@0: // for some node types. michael@0: int fFirstPos; // Position in the rule source string of the michael@0: // first text associated with the node. michael@0: // If there's a left child, this will be the same michael@0: // as that child's left pos. michael@0: int fLastPos; // Last position in the rule source string michael@0: // of any text associated with this node. michael@0: // If there's a right child, this will be the same michael@0: // as that child's last postion. michael@0: michael@0: UBool fNullable; // See Aho. michael@0: int32_t fVal; // For leafChar nodes, the value. michael@0: // Values are the character category, michael@0: // corresponds to columns in the final michael@0: // state transition table. michael@0: michael@0: UBool fLookAheadEnd; // For endMark nodes, set TRUE if michael@0: // marking the end of a look-ahead rule. michael@0: michael@0: UVector *fFirstPosSet; michael@0: UVector *fLastPosSet; // TODO: rename fFirstPos & fLastPos to avoid confusion. michael@0: UVector *fFollowPos; michael@0: michael@0: michael@0: RBBINode(NodeType t); michael@0: RBBINode(const RBBINode &other); michael@0: ~RBBINode(); michael@0: michael@0: RBBINode *cloneTree(); michael@0: RBBINode *flattenVariables(); michael@0: void flattenSets(); michael@0: void findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &status); michael@0: michael@0: #ifdef RBBI_DEBUG michael@0: void printNode(); michael@0: void printTree(UBool withHeading); michael@0: #endif michael@0: michael@0: private: michael@0: RBBINode &operator = (const RBBINode &other); // No defs. michael@0: UBool operator == (const RBBINode &other); // Private, so these functions won't accidently be used. michael@0: michael@0: #ifdef RBBI_DEBUG michael@0: int fSerialNum; // Debugging aids. michael@0: #endif michael@0: }; michael@0: michael@0: #ifdef RBBI_DEBUG michael@0: U_CFUNC void michael@0: RBBI_DEBUG_printUnicodeString(const UnicodeString &s, int minWidth=0); michael@0: #endif michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: