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