gitlab.com/thomasboni/go-enry/v2@v2.8.3-0.20220418031202-30b0d7a3de98/_testdata/Java/JFlexLexer.java (about) 1 /* The following code was generated by JFlex 1.4.3 on 28/01/16 11:27 */ 2 3 package test; 4 import com.intellij.lexer.*; 5 import com.intellij.psi.tree.IElementType; 6 import static org.intellij.grammar.psi.BnfTypes.*; 7 8 9 /** 10 * This class is a scanner generated by 11 * <a href="http://www.jflex.de/">JFlex</a> 1.4.3 12 * on 28/01/16 11:27 from the specification file 13 * <tt>/home/abigail/code/intellij-grammar-kit-test/src/test/_GrammarLexer.flex</tt> 14 */ 15 public class _GrammarLexer implements FlexLexer { 16 /** initial size of the lookahead buffer */ 17 private static final int ZZ_BUFFERSIZE = 16384; 18 19 /** lexical states */ 20 public static final int YYINITIAL = 0; 21 22 /** 23 * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l 24 * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l 25 * at the beginning of a line 26 * l is of the form l = 2*k, k a non negative integer 27 */ 28 private static final int ZZ_LEXSTATE[] = { 29 0, 0 30 }; 31 32 /** 33 * Translates characters to character classes 34 */ 35 private static final String ZZ_CMAP_PACKED = 36 "\11\0\1\1\1\1\1\0\1\1\1\1\22\0\1\1\101\0\1\13"+ 37 "\1\0\1\3\1\14\1\0\1\10\1\0\1\2\3\0\1\12\1\7"+ 38 "\3\0\1\6\1\4\1\5\1\11\uff8a\0"; 39 40 /** 41 * Translates characters to character classes 42 */ 43 private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); 44 45 /** 46 * Translates DFA states to action switch labels. 47 */ 48 private static final int [] ZZ_ACTION = zzUnpackAction(); 49 50 private static final String ZZ_ACTION_PACKED_0 = 51 "\1\0\1\1\1\2\3\1\1\3\10\0\1\4\1\5"; 52 53 private static int [] zzUnpackAction() { 54 int [] result = new int[17]; 55 int offset = 0; 56 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); 57 return result; 58 } 59 60 private static int zzUnpackAction(String packed, int offset, int [] result) { 61 int i = 0; /* index in packed string */ 62 int j = offset; /* index in unpacked array */ 63 int l = packed.length(); 64 while (i < l) { 65 int count = packed.charAt(i++); 66 int value = packed.charAt(i++); 67 do result[j++] = value; while (--count > 0); 68 } 69 return j; 70 } 71 72 73 /** 74 * Translates a state to a row index in the transition table 75 */ 76 private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); 77 78 private static final String ZZ_ROWMAP_PACKED_0 = 79 "\0\0\0\15\0\32\0\47\0\64\0\101\0\15\0\116"+ 80 "\0\133\0\150\0\165\0\202\0\217\0\234\0\251\0\15"+ 81 "\0\15"; 82 83 private static int [] zzUnpackRowMap() { 84 int [] result = new int[17]; 85 int offset = 0; 86 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); 87 return result; 88 } 89 90 private static int zzUnpackRowMap(String packed, int offset, int [] result) { 91 int i = 0; /* index in packed string */ 92 int j = offset; /* index in unpacked array */ 93 int l = packed.length(); 94 while (i < l) { 95 int high = packed.charAt(i++) << 16; 96 result[j++] = high | packed.charAt(i++); 97 } 98 return j; 99 } 100 101 /** 102 * The transition table of the DFA 103 */ 104 private static final int [] ZZ_TRANS = zzUnpackTrans(); 105 106 private static final String ZZ_TRANS_PACKED_0 = 107 "\1\2\1\3\1\4\1\2\1\5\2\2\1\6\5\2"+ 108 "\16\0\1\3\16\0\1\7\16\0\1\10\20\0\1\11"+ 109 "\11\0\1\12\20\0\1\13\4\0\1\14\25\0\1\15"+ 110 "\10\0\1\16\21\0\1\17\10\0\1\20\12\0\1\21"+ 111 "\6\0"; 112 113 private static int [] zzUnpackTrans() { 114 int [] result = new int[182]; 115 int offset = 0; 116 offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); 117 return result; 118 } 119 120 private static int zzUnpackTrans(String packed, int offset, int [] result) { 121 int i = 0; /* index in packed string */ 122 int j = offset; /* index in unpacked array */ 123 int l = packed.length(); 124 while (i < l) { 125 int count = packed.charAt(i++); 126 int value = packed.charAt(i++); 127 value--; 128 do result[j++] = value; while (--count > 0); 129 } 130 return j; 131 } 132 133 134 /* error codes */ 135 private static final int ZZ_UNKNOWN_ERROR = 0; 136 private static final int ZZ_NO_MATCH = 1; 137 private static final int ZZ_PUSHBACK_2BIG = 2; 138 private static final char[] EMPTY_BUFFER = new char[0]; 139 private static final int YYEOF = -1; 140 private static java.io.Reader zzReader = null; // Fake 141 142 /* error messages for the codes above */ 143 private static final String ZZ_ERROR_MSG[] = { 144 "Unkown internal scanner error", 145 "Error: could not match input", 146 "Error: pushback value was too large" 147 }; 148 149 /** 150 * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code> 151 */ 152 private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); 153 154 private static final String ZZ_ATTRIBUTE_PACKED_0 = 155 "\1\0\1\11\4\1\1\11\10\0\2\11"; 156 157 private static int [] zzUnpackAttribute() { 158 int [] result = new int[17]; 159 int offset = 0; 160 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); 161 return result; 162 } 163 164 private static int zzUnpackAttribute(String packed, int offset, int [] result) { 165 int i = 0; /* index in packed string */ 166 int j = offset; /* index in unpacked array */ 167 int l = packed.length(); 168 while (i < l) { 169 int count = packed.charAt(i++); 170 int value = packed.charAt(i++); 171 do result[j++] = value; while (--count > 0); 172 } 173 return j; 174 } 175 176 /** the current state of the DFA */ 177 private int zzState; 178 179 /** the current lexical state */ 180 private int zzLexicalState = YYINITIAL; 181 182 /** this buffer contains the current text to be matched and is 183 the source of the yytext() string */ 184 private CharSequence zzBuffer = ""; 185 186 /** this buffer may contains the current text array to be matched when it is cheap to acquire it */ 187 private char[] zzBufferArray; 188 189 /** the textposition at the last accepting state */ 190 private int zzMarkedPos; 191 192 /** the textposition at the last state to be included in yytext */ 193 private int zzPushbackPos; 194 195 /** the current text position in the buffer */ 196 private int zzCurrentPos; 197 198 /** startRead marks the beginning of the yytext() string in the buffer */ 199 private int zzStartRead; 200 201 /** endRead marks the last character in the buffer, that has been read 202 from input */ 203 private int zzEndRead; 204 205 /** 206 * zzAtBOL == true <=> the scanner is currently at the beginning of a line 207 */ 208 private boolean zzAtBOL = true; 209 210 /** zzAtEOF == true <=> the scanner is at the EOF */ 211 private boolean zzAtEOF; 212 213 /* user code: */ 214 public _GrammarLexer() { 215 this((java.io.Reader)null); 216 } 217 218 219 /** 220 * Creates a new scanner 221 * 222 * @param in the java.io.Reader to read input from. 223 */ 224 public _GrammarLexer(java.io.Reader in) { 225 this.zzReader = in; 226 } 227 228 229 /** 230 * Unpacks the compressed character translation table. 231 * 232 * @param packed the packed character translation table 233 * @return the unpacked character translation table 234 */ 235 private static char [] zzUnpackCMap(String packed) { 236 char [] map = new char[0x10000]; 237 int i = 0; /* index in packed string */ 238 int j = 0; /* index in unpacked array */ 239 while (i < 52) { 240 int count = packed.charAt(i++); 241 char value = packed.charAt(i++); 242 do map[j++] = value; while (--count > 0); 243 } 244 return map; 245 } 246 247 public final int getTokenStart(){ 248 return zzStartRead; 249 } 250 251 public final int getTokenEnd(){ 252 return getTokenStart() + yylength(); 253 } 254 255 public void reset(CharSequence buffer, int start, int end,int initialState){ 256 zzBuffer = buffer; 257 zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer); 258 zzCurrentPos = zzMarkedPos = zzStartRead = start; 259 zzPushbackPos = 0; 260 zzAtEOF = false; 261 zzAtBOL = true; 262 zzEndRead = end; 263 yybegin(initialState); 264 } 265 266 /** 267 * Refills the input buffer. 268 * 269 * @return <code>false</code>, iff there was new input. 270 * 271 * @exception java.io.IOException if any I/O-Error occurs 272 */ 273 private boolean zzRefill() throws java.io.IOException { 274 return true; 275 } 276 277 278 /** 279 * Returns the current lexical state. 280 */ 281 public final int yystate() { 282 return zzLexicalState; 283 } 284 285 286 /** 287 * Enters a new lexical state 288 * 289 * @param newState the new lexical state 290 */ 291 public final void yybegin(int newState) { 292 zzLexicalState = newState; 293 } 294 295 296 /** 297 * Returns the text matched by the current regular expression. 298 */ 299 public final CharSequence yytext() { 300 return zzBuffer.subSequence(zzStartRead, zzMarkedPos); 301 } 302 303 304 /** 305 * Returns the character at position <tt>pos</tt> from the 306 * matched text. 307 * 308 * It is equivalent to yytext().charAt(pos), but faster 309 * 310 * @param pos the position of the character to fetch. 311 * A value from 0 to yylength()-1. 312 * 313 * @return the character at position pos 314 */ 315 public final char yycharat(int pos) { 316 return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos); 317 } 318 319 320 /** 321 * Returns the length of the matched text region. 322 */ 323 public final int yylength() { 324 return zzMarkedPos-zzStartRead; 325 } 326 327 328 /** 329 * Reports an error that occured while scanning. 330 * 331 * In a wellformed scanner (no or only correct usage of 332 * yypushback(int) and a match-all fallback rule) this method 333 * will only be called with things that "Can't Possibly Happen". 334 * If this method is called, something is seriously wrong 335 * (e.g. a JFlex bug producing a faulty scanner etc.). 336 * 337 * Usual syntax/scanner level error handling should be done 338 * in error fallback rules. 339 * 340 * @param errorCode the code of the errormessage to display 341 */ 342 private void zzScanError(int errorCode) { 343 String message; 344 try { 345 message = ZZ_ERROR_MSG[errorCode]; 346 } 347 catch (ArrayIndexOutOfBoundsException e) { 348 message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; 349 } 350 351 throw new Error(message); 352 } 353 354 355 /** 356 * Pushes the specified amount of characters back into the input stream. 357 * 358 * They will be read again by then next call of the scanning method 359 * 360 * @param number the number of characters to be read again. 361 * This number must not be greater than yylength()! 362 */ 363 public void yypushback(int number) { 364 if ( number > yylength() ) 365 zzScanError(ZZ_PUSHBACK_2BIG); 366 367 zzMarkedPos -= number; 368 } 369 370 371 /** 372 * Resumes scanning until the next regular expression is matched, 373 * the end of input is encountered or an I/O-Error occurs. 374 * 375 * @return the next token 376 * @exception java.io.IOException if any I/O-Error occurs 377 */ 378 public IElementType advance() throws java.io.IOException { 379 int zzInput; 380 int zzAction; 381 382 // cached fields: 383 int zzCurrentPosL; 384 int zzMarkedPosL; 385 int zzEndReadL = zzEndRead; 386 CharSequence zzBufferL = zzBuffer; 387 char[] zzBufferArrayL = zzBufferArray; 388 char [] zzCMapL = ZZ_CMAP; 389 390 int [] zzTransL = ZZ_TRANS; 391 int [] zzRowMapL = ZZ_ROWMAP; 392 int [] zzAttrL = ZZ_ATTRIBUTE; 393 394 while (true) { 395 zzMarkedPosL = zzMarkedPos; 396 397 zzAction = -1; 398 399 zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; 400 401 zzState = ZZ_LEXSTATE[zzLexicalState]; 402 403 404 zzForAction: { 405 while (true) { 406 407 if (zzCurrentPosL < zzEndReadL) 408 zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); 409 else if (zzAtEOF) { 410 zzInput = YYEOF; 411 break zzForAction; 412 } 413 else { 414 // store back cached positions 415 zzCurrentPos = zzCurrentPosL; 416 zzMarkedPos = zzMarkedPosL; 417 boolean eof = zzRefill(); 418 // get translated positions and possibly new buffer 419 zzCurrentPosL = zzCurrentPos; 420 zzMarkedPosL = zzMarkedPos; 421 zzBufferL = zzBuffer; 422 zzEndReadL = zzEndRead; 423 if (eof) { 424 zzInput = YYEOF; 425 break zzForAction; 426 } 427 else { 428 zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); 429 } 430 } 431 int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; 432 if (zzNext == -1) break zzForAction; 433 zzState = zzNext; 434 435 int zzAttributes = zzAttrL[zzState]; 436 if ( (zzAttributes & 1) == 1 ) { 437 zzAction = zzState; 438 zzMarkedPosL = zzCurrentPosL; 439 if ( (zzAttributes & 8) == 8 ) break zzForAction; 440 } 441 442 } 443 } 444 445 // store back cached position 446 zzMarkedPos = zzMarkedPosL; 447 448 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { 449 case 1: 450 { return com.intellij.psi.TokenType.BAD_CHARACTER; 451 } 452 case 6: break; 453 case 4: 454 { return BNF_STRING; 455 } 456 case 7: break; 457 case 5: 458 { return BNF_NUMBER; 459 } 460 case 8: break; 461 case 3: 462 { return BNF_ID; 463 } 464 case 9: break; 465 case 2: 466 { return com.intellij.psi.TokenType.WHITE_SPACE; 467 } 468 case 10: break; 469 default: 470 if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { 471 zzAtEOF = true; 472 return null; 473 } 474 else { 475 zzScanError(ZZ_NO_MATCH); 476 } 477 } 478 } 479 } 480 481 482 }