1 7 package com.ibm.icu.text; 8 9 import java.util.HashMap ; 10 import java.util.Collection ; 11 12 import java.text.ParsePosition ; 13 import com.ibm.icu.lang.UCharacter; 14 15 class RBBISymbolTable implements SymbolTable{ 16 17 String fRules; 18 HashMap fHashTable; 19 RBBIRuleScanner fRuleScanner; 20 21 String ffffString; 25 UnicodeSet fCachedSetLookup; 26 27 28 29 static class RBBISymbolTableEntry { 30 String key; 31 RBBINode val; 32 }; 33 34 35 36 RBBISymbolTable(RBBIRuleScanner rs, String rules) { 37 fRules = rules; 38 fRuleScanner = rs; 39 fHashTable = new HashMap (); 40 ffffString = "\uffff"; 41 } 42 43 44 45 46 public char[] lookup(String s) 54 { 55 RBBISymbolTableEntry el; 56 RBBINode varRefNode; 57 RBBINode exprNode; 58 59 RBBINode usetNode; 60 String retString; 61 62 el = (RBBISymbolTableEntry)fHashTable.get(s); 63 if (el == null) { 64 return null; 65 } 66 67 varRefNode = el.val; 69 while (varRefNode.fLeftChild.fType == RBBINode.varRef) { 70 varRefNode = varRefNode.fLeftChild; 71 } 72 73 exprNode = varRefNode.fLeftChild; if (exprNode.fType == RBBINode.setRef) { 75 usetNode = exprNode.fLeftChild; 79 fCachedSetLookup = usetNode.fInputSet; 80 retString = ffffString; 81 } 82 else 83 { 84 fRuleScanner.error(RBBIRuleBuilder.U_BRK_MALFORMED_SET); 89 retString = exprNode.fText; 90 fCachedSetLookup = null; 91 } 92 return retString.toCharArray(); 93 } 94 95 96 97 public UnicodeMatcher lookupMatcher(int ch) 109 { 110 UnicodeSet retVal = null; 111 if (ch == 0xffff) { 112 retVal = fCachedSetLookup; 113 fCachedSetLookup = null; 114 } 115 return retVal; 116 } 117 118 public String parseReference( String text, ParsePosition pos, int limit) 125 { 126 int start = pos.getIndex(); 127 int i = start; 128 String result = ""; 129 while (i < limit) { 130 int c = UTF16.charAt(text, i); 131 if ((i==start && !UCharacter.isUnicodeIdentifierStart(c)) || !UCharacter.isUnicodeIdentifierPart(c)) { 132 break; 133 } 134 i += UTF16.getCharCount(c); 135 } 136 if (i == start) { return result; } 139 pos.setIndex(i); 140 result = text.substring(start, i); 141 return result; 142 } 143 144 145 146 RBBINode lookupNode(String key) { 152 153 RBBINode retNode = null; 154 RBBISymbolTableEntry el; 155 156 el = (RBBISymbolTableEntry)fHashTable.get(key); 157 if (el != null) { 158 retNode = el.val; 159 } 160 return retNode; 161 } 162 163 164 void addEntry (String key, RBBINode val) { 171 RBBISymbolTableEntry e; 172 e = (RBBISymbolTableEntry )fHashTable.get(key); 173 if (e != null) { 174 fRuleScanner.error(RBBIRuleBuilder.U_BRK_VARIABLE_REDFINITION); 175 return; 176 } 177 178 e = new RBBISymbolTableEntry(); 179 e.key = key; 180 e.val = val; 181 fHashTable.put(e.key, e); 182 } 183 184 185 186 187 188 void rbbiSymtablePrint() { 192 System.out.print("Variable Definitions\n" + 193 "Name Node Val String Val\n" + 194 "----------------------------------------------------------------------\n"); 195 196 int pos = -1; 197 RBBISymbolTableEntry [] syms = new RBBISymbolTableEntry[0]; 198 Collection t = fHashTable.values(); 199 syms = (RBBISymbolTableEntry[]) t.toArray(syms); 200 201 for (int i=0; i<syms.length; i++) { 202 RBBISymbolTableEntry s = syms[i]; 203 204 System.out.print(" " + s.key + " "); System.out.print(" " + s.val + " "); 206 System.out.print(s.val.fLeftChild.fText); 207 System.out.print("\n"); 208 } 209 210 System.out.println("\nParsed Variable Definitions\n"); 211 pos = -1; 212 for (int i=0; i<syms.length; i++) { 213 RBBISymbolTableEntry s = syms[i]; 214 System.out.print(s.key); 215 s.val.fLeftChild.printTree(true); 216 System.out.print("\n"); 217 } 218 } 219 220 221 } 222 | Popular Tags |