1 19 20 package org.netbeans.modules.properties.syntax; 21 22 import org.netbeans.editor.Syntax; 23 import org.netbeans.editor.TokenID; 24 25 32 33 public class PropertiesSyntax extends Syntax { 34 35 private static final int ISI_LINE_COMMENT = 2; private static final int ISI_KEY = 3; private static final int ISI_KEY_A_BSLASH = 4; private static final int ISI_EQUAL = 5; private static final int ISI_EQUAL2 = 6; private static final int ISI_VALUE = 7; private static final int ISI_VALUE_A_BSLASH = 8; private static final int ISI_VALUE_AT_NL = 9; private static final int ISI_EQUAL_AT_NL = 10; 46 47 public PropertiesSyntax() { 48 tokenContextPath = PropertiesTokenContext.contextPath; 49 } 50 51 protected TokenID parseToken() { 52 char actChar; 53 54 while(offset < stopOffset) { 55 actChar = buffer[offset]; 56 57 switch (state) { 58 case INIT: 59 switch (actChar) { 60 case '\n': 61 offset++; 62 return PropertiesTokenContext.EOL; 63 case '\t': 64 case '\f': 65 case ' ': 66 offset++; 67 return PropertiesTokenContext.TEXT; 68 case '#': 69 case '!': 70 state = ISI_LINE_COMMENT; 71 break; 72 case '=': case ':': 74 state = ISI_EQUAL; 75 return PropertiesTokenContext.TEXT; 76 case '\\': state = ISI_KEY_A_BSLASH; 78 break; 79 default: 80 state = ISI_KEY; 81 break; 82 } 83 break; 85 case ISI_LINE_COMMENT: 86 switch (actChar) { 87 case '\n': 88 state = INIT; 89 return PropertiesTokenContext.LINE_COMMENT; 90 } 91 break; 93 case ISI_KEY: 94 switch (actChar) { 95 case '\n': 96 state = INIT; 97 return PropertiesTokenContext.KEY; 98 case '\\': 99 state = ISI_KEY_A_BSLASH; 100 break; 101 case '=': 102 case ':': 103 case ' ': case '\t': 105 state = ISI_EQUAL; 106 return PropertiesTokenContext.KEY; 107 } 108 break; 110 case ISI_KEY_A_BSLASH: 111 switch (actChar) { 112 case '\n': 113 state = INIT; 114 return PropertiesTokenContext.KEY; 115 default: 116 state = ISI_KEY; 117 } 118 break; 120 case ISI_EQUAL: 121 switch (actChar) { 122 case '=': 123 case ':': 124 offset++; 125 state = ISI_VALUE; 126 return PropertiesTokenContext.EQ; 127 case ' ': case '\t': 129 break; 130 case '\\': state = ISI_EQUAL2; 132 break; 133 case '\n': 134 state = INIT; 135 return PropertiesTokenContext.EQ; 136 default: 137 state = ISI_VALUE; 138 } 139 break; 141 case ISI_EQUAL2: 143 switch (actChar) { 144 case '\n': 145 state = ISI_EQUAL_AT_NL; 146 return PropertiesTokenContext.EQ; default: 148 state = ISI_VALUE; 149 } 150 break; 152 case ISI_EQUAL_AT_NL: 154 switch (actChar) { 155 case '\n': 156 offset++; 157 state = ISI_EQUAL; 158 return PropertiesTokenContext.EOL; 159 default: 160 throw new Error ("Something smells 4"); 161 } 162 163 180 case ISI_VALUE: 181 switch (actChar) { 182 case '\n': 183 state = INIT; 184 return PropertiesTokenContext.VALUE; 185 case '\\': 186 state = ISI_VALUE_A_BSLASH; 187 break; 188 } 189 break; 191 case ISI_VALUE_A_BSLASH: 192 switch (actChar) { 193 case '\n': 194 state = ISI_VALUE_AT_NL; 195 return PropertiesTokenContext.VALUE; 196 default: 197 state = ISI_VALUE; 198 } 199 break; 201 case ISI_VALUE_AT_NL: 202 switch (actChar) { 203 case '\n': 204 offset++; 205 state = ISI_VALUE; 206 return PropertiesTokenContext.EOL; 207 default: 208 throw new Error ("Something smells 2"); 209 } 210 212 default: 213 throw new Error ("Unhandled state " + state); 214 215 } 217 offset = ++offset; 218 219 } 221 222 223 if (lastBuffer || !lastBuffer) { 224 switch(state) { 225 case ISI_LINE_COMMENT: 226 return PropertiesTokenContext.LINE_COMMENT; 227 case ISI_KEY: 228 case ISI_KEY_A_BSLASH: 229 return PropertiesTokenContext.KEY; 230 case ISI_EQUAL: 231 case ISI_EQUAL2: 232 return PropertiesTokenContext.EQ; 233 case ISI_VALUE: 234 case ISI_VALUE_A_BSLASH: 235 return PropertiesTokenContext.VALUE; 236 case ISI_VALUE_AT_NL: 237 case ISI_EQUAL_AT_NL: throw new Error ("Something smells 3"); 239 } 240 } 241 242 return null; 243 244 } 246 public String getStateName(int stateNumber) { 247 switch(stateNumber) { 248 case ISI_LINE_COMMENT: 249 return "ISI_LINE_COMMENT"; 250 case ISI_KEY: 251 return "ISI_KEY"; 252 case ISI_KEY_A_BSLASH: 253 return "ISI_KEY_A_BSLASH"; 254 case ISI_EQUAL: 255 return "ISI_EQUAL"; 256 case ISI_EQUAL2: 257 return "ISI_EQUAL2"; 258 case ISI_EQUAL_AT_NL: 259 return "ISI_EQUAL_AT_NL"; 260 case ISI_VALUE: 261 return "ISI_VALUE"; 262 case ISI_VALUE_A_BSLASH: 263 return "ISI_VALUE_A_BSLASH"; 264 case ISI_VALUE_AT_NL: 265 return "ISI_VALUE_AT_NL"; 266 default: 267 return super.getStateName(stateNumber); 268 } 269 } 270 271 272 } 273 274 286 287 | Popular Tags |