1 2 package org.ejen.ext.parsers.java_1_2; 23 24 import org.ejen.util.arl.ArlUtil; 26 27 34 public class Token { 35 36 41 public int kind; 42 43 48 public int beginLine, beginColumn, endLine, endColumn; 49 50 53 public String image; 54 55 63 public Token next; 64 65 77 public Token specialToken; 78 79 82 public final String toString() { 83 return image; 84 } 85 86 98 public static final Token newToken(int ofKind) { 99 switch (ofKind) { 100 default: 101 return new Token(); 102 } 103 } 104 105 137 public final void toNode(org.w3c.dom.Document doc, 138 org.w3c.dom.Node parent, 139 int[] tokensMap, 140 boolean tokensPos) 141 throws org.w3c.dom.DOMException { 142 if (tokensMap[kind] == ArlUtil.F_REMOVE) { 143 return; 144 } 145 if (tokensMap[kind] == ArlUtil.F_ACCEPT) { 146 org.w3c.dom.Element elt = doc.createElement("tok"); 147 148 elt.setAttribute("ki", String.valueOf(kind)); 149 if (tokensPos) { 150 elt.setAttribute("bl", String.valueOf(beginLine)); 151 elt.setAttribute("bc", String.valueOf(beginColumn)); 152 elt.setAttribute("el", String.valueOf(endLine)); 153 elt.setAttribute("ec", String.valueOf(endColumn)); 154 } 155 parent.appendChild(elt); 156 parent = elt; 157 } 158 Token st = specialToken; 159 160 if (st != null) { 161 while (st.specialToken != null) { 162 st = st.specialToken; 163 } 164 while (st != null) { 165 st.toSpecialNode(doc, parent, tokensMap, tokensPos); 166 st = st.next; 167 } 168 } 169 parent.appendChild(doc.createCDATASection(image)); 170 } 171 172 203 protected final void toSpecialNode(org.w3c.dom.Document doc, 204 org.w3c.dom.Node parent, 205 int[] tokensMap, 206 boolean tokensPos) 207 throws org.w3c.dom.DOMException { 208 if (tokensMap[kind] == ArlUtil.F_REMOVE) { 209 return; 210 } 211 if (tokensMap[kind] == ArlUtil.F_ACCEPT) { 212 org.w3c.dom.Element elt = doc.createElement("stok"); 213 214 elt.setAttribute("ki", String.valueOf(kind)); 215 if (tokensPos) { 216 elt.setAttribute("bl", String.valueOf(beginLine)); 217 elt.setAttribute("bc", String.valueOf(beginColumn)); 218 elt.setAttribute("el", String.valueOf(endLine)); 219 elt.setAttribute("ec", String.valueOf(endColumn)); 220 } 221 parent.appendChild(elt); 222 parent = elt; 223 } 224 parent.appendChild(doc.createCDATASection(image)); 225 } 226 } 228
| Popular Tags
|