1 /* The following code was generated by JFlex 1.4.3 on 26.5.2013 19:20 */
3 package org.simantics.scl.compiler.internal.parsing.documentation;
7 * This class is a scanner generated by
8 * <a href="http://www.jflex.de/">JFlex</a> 1.4.3
9 * on 26.5.2013 19:20 from the specification file
10 * <tt>C:/Documents and Settings/Hannu/git/scl/org.simantics.scl.compiler/src/org/simantics/scl/compiler/parsing/documentation/DocumentationLexer.flex</tt>
12 public class DocumentationLexer {
14 /** This character denotes the end of file */
15 public static final int YYEOF = -1;
17 /** initial size of the lookahead buffer */
18 private static final int ZZ_BUFFERSIZE = 16384;
21 public static final int YYINITIAL = 0;
24 * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
25 * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
26 * at the beginning of a line
27 * l is of the form l = 2*k, k a non negative integer
29 private static final int ZZ_LEXSTATE[] = {
34 * Translates characters to character classes
36 private static final String ZZ_CMAP_PACKED =
37 "\11\0\1\1\1\2\2\0\1\3\22\0\1\5\2\0\1\0\6\0"+
38 "\1\7\2\0\1\4\17\0\1\6\1\10\uffc1\0";
41 * Translates characters to character classes
43 private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
46 * Translates DFA states to action switch labels.
48 private static final int [] ZZ_ACTION = zzUnpackAction();
50 private static final String ZZ_ACTION_PACKED_0 =
51 "\1\0\1\1\2\2\2\1\1\2\3\1\1\0\1\3"+
52 "\2\0\1\4\4\0\1\5\2\0\1\6\11\0\1\7"+
53 "\6\0\1\10\4\0\1\11\1\0";
55 private static int [] zzUnpackAction() {
56 int [] result = new int[46];
58 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
62 private static int zzUnpackAction(String packed, int offset, int [] result) {
63 int i = 0; /* index in packed string */
64 int j = offset; /* index in unpacked array */
65 int l = packed.length();
67 int count = packed.charAt(i++);
68 int value = packed.charAt(i++);
69 do result[j++] = value; while (--count > 0);
76 * Translates a state to a row index in the transition table
78 private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
80 private static final String ZZ_ROWMAP_PACKED_0 =
81 "\0\0\0\11\0\22\0\33\0\44\0\55\0\66\0\77"+
82 "\0\110\0\121\0\11\0\132\0\143\0\55\0\33\0\154"+
83 "\0\165\0\176\0\110\0\33\0\207\0\121\0\220\0\231"+
84 "\0\132\0\242\0\253\0\264\0\275\0\306\0\317\0\330"+
85 "\0\33\0\341\0\352\0\363\0\374\0\u0105\0\u010e\0\33"+
86 "\0\u0117\0\u0120\0\u0129\0\u0132\0\33\0\u013b";
88 private static int [] zzUnpackRowMap() {
89 int [] result = new int[46];
91 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
95 private static int zzUnpackRowMap(String packed, int offset, int [] result) {
96 int i = 0; /* index in packed string */
97 int j = offset; /* index in unpacked array */
98 int l = packed.length();
100 int high = packed.charAt(i++) << 16;
101 result[j++] = high | packed.charAt(i++);
107 * The transition table of the DFA
109 private static final int [] ZZ_TRANS = zzUnpackTrans();
111 private static final String ZZ_TRANS_PACKED_0 =
112 "\1\2\1\3\1\4\1\5\1\6\1\7\1\10\1\11"+
113 "\1\12\2\13\1\14\1\15\6\13\1\3\1\14\1\15"+
114 "\1\13\1\3\3\13\13\0\1\4\6\0\2\16\1\17"+
115 "\1\20\5\16\1\13\1\3\3\0\1\7\3\0\2\21"+
116 "\2\0\2\21\1\22\2\21\2\23\1\24\1\25\5\23"+
117 "\2\26\1\27\1\30\5\26\2\13\3\0\1\31\5\0"+
118 "\1\14\10\0\1\17\6\0\2\32\2\0\2\32\1\21"+
119 "\2\32\2\33\2\0\2\33\1\34\2\33\2\0\1\24"+
120 "\16\0\1\26\2\0\1\27\6\0\2\32\2\0\2\32"+
121 "\1\35\2\32\2\36\2\0\2\36\1\33\2\36\2\37"+
122 "\2\0\2\37\1\0\2\37\1\32\1\40\1\41\1\42"+
123 "\1\32\1\40\1\21\2\32\2\36\2\0\2\36\1\43"+
124 "\2\36\2\44\2\0\2\44\1\37\2\44\1\32\1\40"+
125 "\1\41\1\42\1\32\1\40\1\35\2\32\2\0\1\41"+
126 "\6\0\2\36\2\0\2\36\1\45\2\36\2\44\2\0"+
127 "\2\44\1\46\2\44\1\36\1\47\1\50\1\51\1\36"+
128 "\1\47\1\33\2\36\2\44\2\0\2\44\1\52\2\44"+
129 "\1\36\1\47\1\50\1\51\1\36\1\47\1\43\2\36"+
130 "\2\0\1\50\6\0\2\44\2\0\2\44\1\53\3\44"+
131 "\1\54\1\55\1\56\1\44\1\54\1\37\3\44\1\54"+
132 "\1\55\1\56\1\44\1\54\1\46\2\44\2\0\1\55"+
135 private static int [] zzUnpackTrans() {
136 int [] result = new int[324];
138 offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
142 private static int zzUnpackTrans(String packed, int offset, int [] result) {
143 int i = 0; /* index in packed string */
144 int j = offset; /* index in unpacked array */
145 int l = packed.length();
147 int count = packed.charAt(i++);
148 int value = packed.charAt(i++);
150 do result[j++] = value; while (--count > 0);
157 private static final int ZZ_UNKNOWN_ERROR = 0;
158 private static final int ZZ_NO_MATCH = 1;
159 private static final int ZZ_PUSHBACK_2BIG = 2;
161 /* error messages for the codes above */
162 private static final String ZZ_ERROR_MSG[] = {
163 "Unkown internal scanner error",
164 "Error: could not match input",
165 "Error: pushback value was too large"
169 * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
171 private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
173 private static final String ZZ_ATTRIBUTE_PACKED_0 =
174 "\1\0\2\1\1\11\6\1\1\0\1\1\2\0\1\11"+
175 "\4\0\1\11\2\0\1\1\11\0\1\11\6\0\1\11"+
178 private static int [] zzUnpackAttribute() {
179 int [] result = new int[46];
181 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
185 private static int zzUnpackAttribute(String packed, int offset, int [] result) {
186 int i = 0; /* index in packed string */
187 int j = offset; /* index in unpacked array */
188 int l = packed.length();
190 int count = packed.charAt(i++);
191 int value = packed.charAt(i++);
192 do result[j++] = value; while (--count > 0);
197 /** the input device */
198 private java.io.Reader zzReader;
200 /** the current state of the DFA */
203 /** the current lexical state */
204 private int zzLexicalState = YYINITIAL;
206 /** this buffer contains the current text to be matched and is
207 the source of the yytext() string */
208 private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
210 /** the textposition at the last accepting state */
211 private int zzMarkedPos;
213 /** the current text position in the buffer */
214 private int zzCurrentPos;
216 /** startRead marks the beginning of the yytext() string in the buffer */
217 private int zzStartRead;
219 /** endRead marks the last character in the buffer, that has been read
221 private int zzEndRead;
223 /** number of newlines encountered up to the start of the matched text */
226 /** the number of characters up to the start of the matched text */
230 * the number of characters from the last newline up to the start of the
233 private int yycolumn;
236 * zzAtBOL == true <=> the scanner is currently at the beginning of a line
238 private boolean zzAtBOL = true;
240 /** zzAtEOF == true <=> the scanner is at the EOF */
241 private boolean zzAtEOF;
243 /** denotes if the user-EOF-code has already been executed */
244 private boolean zzEOFDone;
247 public static String trimW(String text) {
248 int a = 0, b = text.length();
250 char c = text.charAt(a);
251 if(c != ' ' && c != '\t' && c != '\r' && c != '\n')
256 char c = text.charAt(b-1);
257 if(c != ' ' && c != '\t' && c != '\r' && c != '\n')
261 return text.substring(a, b);
264 public static String trimN(String text, int amount) {
266 return text.substring(amount, text.length()-amount).trim();
271 * Creates a new scanner
272 * There is also a java.io.InputStream version of this constructor.
274 * @param in the java.io.Reader to read input from.
276 public DocumentationLexer(java.io.Reader in) {
281 * Creates a new scanner.
282 * There is also java.io.Reader version of this constructor.
284 * @param in the java.io.Inputstream to read input from.
286 public DocumentationLexer(java.io.InputStream in) {
287 this(new java.io.InputStreamReader(in));
291 * Unpacks the compressed character translation table.
293 * @param packed the packed character translation table
294 * @return the unpacked character translation table
296 private static char [] zzUnpackCMap(String packed) {
297 char [] map = new char[0x10000];
298 int i = 0; /* index in packed string */
299 int j = 0; /* index in unpacked array */
301 int count = packed.charAt(i++);
302 char value = packed.charAt(i++);
303 do map[j++] = value; while (--count > 0);
310 * Refills the input buffer.
312 * @return <code>false</code>, iff there was new input.
314 * @exception java.io.IOException if any I/O-Error occurs
316 private boolean zzRefill() throws java.io.IOException {
318 /* first: make room (if you can) */
319 if (zzStartRead > 0) {
320 System.arraycopy(zzBuffer, zzStartRead,
322 zzEndRead-zzStartRead);
324 /* translate stored positions */
325 zzEndRead-= zzStartRead;
326 zzCurrentPos-= zzStartRead;
327 zzMarkedPos-= zzStartRead;
331 /* is the buffer big enough? */
332 if (zzCurrentPos >= zzBuffer.length) {
333 /* if not: blow it up */
334 char newBuffer[] = new char[zzCurrentPos*2];
335 System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
336 zzBuffer = newBuffer;
339 /* finally: fill the buffer with new input */
340 int numRead = zzReader.read(zzBuffer, zzEndRead,
341 zzBuffer.length-zzEndRead);
347 // unlikely but not impossible: read 0 characters, but not at end of stream
349 int c = zzReader.read();
353 zzBuffer[zzEndRead++] = (char) c;
364 * Closes the input stream.
366 public final void yyclose() throws java.io.IOException {
367 zzAtEOF = true; /* indicate end of file */
368 zzEndRead = zzStartRead; /* invalidate buffer */
370 if (zzReader != null)
376 * Resets the scanner to read from a new input stream.
377 * Does not close the old reader.
379 * All internal variables are reset, the old input stream
380 * <b>cannot</b> be reused (internal buffer is discarded and lost).
381 * Lexical state is set to <tt>ZZ_INITIAL</tt>.
383 * @param reader the new input stream
385 public final void yyreset(java.io.Reader reader) {
390 zzEndRead = zzStartRead = 0;
391 zzCurrentPos = zzMarkedPos = 0;
392 yyline = yychar = yycolumn = 0;
393 zzLexicalState = YYINITIAL;
398 * Returns the current lexical state.
400 public final int yystate() {
401 return zzLexicalState;
406 * Enters a new lexical state
408 * @param newState the new lexical state
410 public final void yybegin(int newState) {
411 zzLexicalState = newState;
416 * Returns the text matched by the current regular expression.
418 public final String yytext() {
419 return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
424 * Returns the character at position <tt>pos</tt> from the
427 * It is equivalent to yytext().charAt(pos), but faster
429 * @param pos the position of the character to fetch.
430 * A value from 0 to yylength()-1.
432 * @return the character at position pos
434 public final char yycharat(int pos) {
435 return zzBuffer[zzStartRead+pos];
440 * Returns the length of the matched text region.
442 public final int yylength() {
443 return zzMarkedPos-zzStartRead;
448 * Reports an error that occured while scanning.
450 * In a wellformed scanner (no or only correct usage of
451 * yypushback(int) and a match-all fallback rule) this method
452 * will only be called with things that "Can't Possibly Happen".
453 * If this method is called, something is seriously wrong
454 * (e.g. a JFlex bug producing a faulty scanner etc.).
456 * Usual syntax/scanner level error handling should be done
457 * in error fallback rules.
459 * @param errorCode the code of the errormessage to display
461 private void zzScanError(int errorCode) {
464 message = ZZ_ERROR_MSG[errorCode];
466 catch (ArrayIndexOutOfBoundsException e) {
467 message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
470 throw new Error(message);
475 * Pushes the specified amount of characters back into the input stream.
477 * They will be read again by then next call of the scanning method
479 * @param number the number of characters to be read again.
480 * This number must not be greater than yylength()!
482 public void yypushback(int number) {
483 if ( number > yylength() )
484 zzScanError(ZZ_PUSHBACK_2BIG);
486 zzMarkedPos -= number;
491 * Resumes scanning until the next regular expression is matched,
492 * the end of input is encountered or an I/O-Error occurs.
494 * @return the next token
495 * @exception java.io.IOException if any I/O-Error occurs
497 public DocumentationElement nextToken() throws java.io.IOException, DocumentationParsingException {
504 int zzEndReadL = zzEndRead;
505 char [] zzBufferL = zzBuffer;
506 char [] zzCMapL = ZZ_CMAP;
508 int [] zzTransL = ZZ_TRANS;
509 int [] zzRowMapL = ZZ_ROWMAP;
510 int [] zzAttrL = ZZ_ATTRIBUTE;
513 zzMarkedPosL = zzMarkedPos;
515 yychar+= zzMarkedPosL-zzStartRead;
519 zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
521 zzState = ZZ_LEXSTATE[zzLexicalState];
527 if (zzCurrentPosL < zzEndReadL)
528 zzInput = zzBufferL[zzCurrentPosL++];
534 // store back cached positions
535 zzCurrentPos = zzCurrentPosL;
536 zzMarkedPos = zzMarkedPosL;
537 boolean eof = zzRefill();
538 // get translated positions and possibly new buffer
539 zzCurrentPosL = zzCurrentPos;
540 zzMarkedPosL = zzMarkedPos;
541 zzBufferL = zzBuffer;
542 zzEndReadL = zzEndRead;
548 zzInput = zzBufferL[zzCurrentPosL++];
551 int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
552 if (zzNext == -1) break zzForAction;
555 int zzAttributes = zzAttrL[zzState];
556 if ( (zzAttributes & 1) == 1 ) {
558 zzMarkedPosL = zzCurrentPosL;
559 if ( (zzAttributes & 8) == 8 ) break zzForAction;
565 // store back cached position
566 zzMarkedPos = zzMarkedPosL;
568 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
570 { return new EntityRef(trimW(yytext().substring(1)));
574 { return new Header(2, trimN(yytext(), 2));
578 { return new Header(1, trimN(yytext(), 1));
582 { return new Paragraph(yytext().trim());
586 { return new Header(3, trimN(yytext(), 3));
590 { System.err.println("At " + yychar + ": Illegal character '" + yytext() + "'.");
594 { return new ListItem(trimW(yytext()));
598 { return new Preformatted(yytext());
606 if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
612 zzScanError(ZZ_NO_MATCH);