]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
2ca993e8 | 3 | * Copyright (c) 2001-2016, International Business Machines Corporation and |
b75a7d8f A |
4 | * others. All Rights Reserved. |
5 | ********************************************************************/ | |
6 | ||
7 | #ifndef RBBINODE_H | |
8 | #define RBBINODE_H | |
9 | ||
10 | #include "unicode/utypes.h" | |
2ca993e8 | 11 | #include "unicode/unistr.h" |
b75a7d8f A |
12 | #include "unicode/uobject.h" |
13 | ||
14 | // | |
15 | // class RBBINode | |
16 | // | |
17 | // Represents a node in the parse tree generated when reading | |
18 | // a rule file. | |
19 | // | |
20 | ||
21 | U_NAMESPACE_BEGIN | |
22 | ||
23 | class UnicodeSet; | |
24 | class UVector; | |
25 | ||
26 | class RBBINode : public UMemory { | |
27 | public: | |
28 | enum NodeType { | |
29 | setRef, | |
30 | uset, | |
31 | varRef, | |
32 | leafChar, | |
33 | lookAhead, | |
34 | tag, | |
35 | endMark, | |
36 | opStart, | |
37 | opCat, | |
38 | opOr, | |
39 | opStar, | |
40 | opPlus, | |
41 | opQuestion, | |
42 | opBreak, | |
43 | opReverse, | |
44 | opLParen | |
45 | }; | |
46 | ||
47 | enum OpPrecedence { | |
48 | precZero, | |
49 | precStart, | |
50 | precLParen, | |
51 | precOpOr, | |
52 | precOpCat | |
53 | }; | |
54 | ||
55 | NodeType fType; | |
56 | RBBINode *fParent; | |
57 | RBBINode *fLeftChild; | |
58 | RBBINode *fRightChild; | |
59 | UnicodeSet *fInputSet; // For uset nodes only. | |
60 | OpPrecedence fPrecedence; // For binary ops only. | |
61 | ||
62 | UnicodeString fText; // Text corresponding to this node. | |
63 | // May be lazily evaluated when (if) needed | |
64 | // for some node types. | |
65 | int fFirstPos; // Position in the rule source string of the | |
66 | // first text associated with the node. | |
67 | // If there's a left child, this will be the same | |
68 | // as that child's left pos. | |
69 | int fLastPos; // Last position in the rule source string | |
70 | // of any text associated with this node. | |
71 | // If there's a right child, this will be the same | |
72 | // as that child's last postion. | |
73 | ||
74 | UBool fNullable; // See Aho. | |
75 | int32_t fVal; // For leafChar nodes, the value. | |
76 | // Values are the character category, | |
77 | // corresponds to columns in the final | |
78 | // state transition table. | |
79 | ||
80 | UBool fLookAheadEnd; // For endMark nodes, set TRUE if | |
81 | // marking the end of a look-ahead rule. | |
82 | ||
2ca993e8 A |
83 | UBool fRuleRoot; // True if this node is the root of a rule. |
84 | UBool fChainIn; // True if chaining into this rule is allowed | |
85 | // (no '^' present). | |
86 | ||
b75a7d8f A |
87 | UVector *fFirstPosSet; |
88 | UVector *fLastPosSet; // TODO: rename fFirstPos & fLastPos to avoid confusion. | |
89 | UVector *fFollowPos; | |
90 | ||
91 | ||
92 | RBBINode(NodeType t); | |
93 | RBBINode(const RBBINode &other); | |
94 | ~RBBINode(); | |
95 | ||
96 | RBBINode *cloneTree(); | |
97 | RBBINode *flattenVariables(); | |
98 | void flattenSets(); | |
99 | void findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &status); | |
100 | ||
374ca955 | 101 | #ifdef RBBI_DEBUG |
2ca993e8 | 102 | static void printNodeHeader(); |
374ca955 A |
103 | void printNode(); |
104 | void printTree(UBool withHeading); | |
374ca955 | 105 | #endif |
b75a7d8f A |
106 | |
107 | private: | |
108 | RBBINode &operator = (const RBBINode &other); // No defs. | |
109 | UBool operator == (const RBBINode &other); // Private, so these functions won't accidently be used. | |
110 | ||
73c04bcf | 111 | #ifdef RBBI_DEBUG |
2ca993e8 | 112 | public: |
b75a7d8f | 113 | int fSerialNum; // Debugging aids. |
73c04bcf | 114 | #endif |
b75a7d8f | 115 | }; |
374ca955 A |
116 | |
117 | #ifdef RBBI_DEBUG | |
118 | U_CFUNC void | |
119 | RBBI_DEBUG_printUnicodeString(const UnicodeString &s, int minWidth=0); | |
120 | #endif | |
121 | ||
b75a7d8f A |
122 | U_NAMESPACE_END |
123 | ||
124 | #endif | |
125 |