]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/documentation/DocumentationLexer.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / parsing / documentation / DocumentationLexer.java
1 /* The following code was generated by JFlex 1.4.3 on 26.5.2013 19:20 */\r
2 \r
3 package org.simantics.scl.compiler.internal.parsing.documentation;\r
4 \r
5 \r
6 /**\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
11  */\r
12 public class DocumentationLexer {\r
13 \r
14   /** This character denotes the end of file */\r
15   public static final int YYEOF = -1;\r
16 \r
17   /** initial size of the lookahead buffer */\r
18   private static final int ZZ_BUFFERSIZE = 16384;\r
19 \r
20   /** lexical states */\r
21   public static final int YYINITIAL = 0;\r
22 \r
23   /**\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
28    */\r
29   private static final int ZZ_LEXSTATE[] = { \r
30      0, 0\r
31   };\r
32 \r
33   /** \r
34    * Translates characters to character classes\r
35    */\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
39 \r
40   /** \r
41    * Translates characters to character classes\r
42    */\r
43   private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);\r
44 \r
45   /** \r
46    * Translates DFA states to action switch labels.\r
47    */\r
48   private static final int [] ZZ_ACTION = zzUnpackAction();\r
49 \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
54 \r
55   private static int [] zzUnpackAction() {\r
56     int [] result = new int[46];\r
57     int offset = 0;\r
58     offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);\r
59     return result;\r
60   }\r
61 \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
66     while (i < l) {\r
67       int count = packed.charAt(i++);\r
68       int value = packed.charAt(i++);\r
69       do result[j++] = value; while (--count > 0);\r
70     }\r
71     return j;\r
72   }\r
73 \r
74 \r
75   /** \r
76    * Translates a state to a row index in the transition table\r
77    */\r
78   private static final int [] ZZ_ROWMAP = zzUnpackRowMap();\r
79 \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
87 \r
88   private static int [] zzUnpackRowMap() {\r
89     int [] result = new int[46];\r
90     int offset = 0;\r
91     offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);\r
92     return result;\r
93   }\r
94 \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
99     while (i < l) {\r
100       int high = packed.charAt(i++) << 16;\r
101       result[j++] = high | packed.charAt(i++);\r
102     }\r
103     return j;\r
104   }\r
105 \r
106   /** \r
107    * The transition table of the DFA\r
108    */\r
109   private static final int [] ZZ_TRANS = zzUnpackTrans();\r
110 \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
133     "\6\0";\r
134 \r
135   private static int [] zzUnpackTrans() {\r
136     int [] result = new int[324];\r
137     int offset = 0;\r
138     offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);\r
139     return result;\r
140   }\r
141 \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
146     while (i < l) {\r
147       int count = packed.charAt(i++);\r
148       int value = packed.charAt(i++);\r
149       value--;\r
150       do result[j++] = value; while (--count > 0);\r
151     }\r
152     return j;\r
153   }\r
154 \r
155 \r
156   /* error codes */\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
160 \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
166   };\r
167 \r
168   /**\r
169    * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>\r
170    */\r
171   private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();\r
172 \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
176     "\4\0\1\11\1\0";\r
177 \r
178   private static int [] zzUnpackAttribute() {\r
179     int [] result = new int[46];\r
180     int offset = 0;\r
181     offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);\r
182     return result;\r
183   }\r
184 \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
189     while (i < l) {\r
190       int count = packed.charAt(i++);\r
191       int value = packed.charAt(i++);\r
192       do result[j++] = value; while (--count > 0);\r
193     }\r
194     return j;\r
195   }\r
196 \r
197   /** the input device */\r
198   private java.io.Reader zzReader;\r
199 \r
200   /** the current state of the DFA */\r
201   private int zzState;\r
202 \r
203   /** the current lexical state */\r
204   private int zzLexicalState = YYINITIAL;\r
205 \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
209 \r
210   /** the textposition at the last accepting state */\r
211   private int zzMarkedPos;\r
212 \r
213   /** the current text position in the buffer */\r
214   private int zzCurrentPos;\r
215 \r
216   /** startRead marks the beginning of the yytext() string in the buffer */\r
217   private int zzStartRead;\r
218 \r
219   /** endRead marks the last character in the buffer, that has been read\r
220       from input */\r
221   private int zzEndRead;\r
222 \r
223   /** number of newlines encountered up to the start of the matched text */\r
224   private int yyline;\r
225 \r
226   /** the number of characters up to the start of the matched text */\r
227   private int yychar;\r
228 \r
229   /**\r
230    * the number of characters from the last newline up to the start of the \r
231    * matched text\r
232    */\r
233   private int yycolumn;\r
234 \r
235   /** \r
236    * zzAtBOL == true <=> the scanner is currently at the beginning of a line\r
237    */\r
238   private boolean zzAtBOL = true;\r
239 \r
240   /** zzAtEOF == true <=> the scanner is at the EOF */\r
241   private boolean zzAtEOF;\r
242 \r
243   /** denotes if the user-EOF-code has already been executed */\r
244   private boolean zzEOFDone;\r
245 \r
246   /* user code: */\r
247     public static String trimW(String text) {\r
248         int a = 0, b = text.length();\r
249         while(a < b) {\r
250             char c = text.charAt(a);\r
251             if(c != ' ' && c != '\t' && c != '\r' && c != '\n')\r
252                 break;\r
253             ++a;\r
254         }\r
255         while(a < b) {\r
256             char c = text.charAt(b-1);\r
257             if(c != ' ' && c != '\t' && c != '\r' && c != '\n')\r
258                 break;\r
259             --b;\r
260         }\r
261         return text.substring(a, b);\r
262     }\r
263 \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
267     }\r
268 \r
269 \r
270   /**\r
271    * Creates a new scanner\r
272    * There is also a java.io.InputStream version of this constructor.\r
273    *\r
274    * @param   in  the java.io.Reader to read input from.\r
275    */\r
276   public DocumentationLexer(java.io.Reader in) {\r
277     this.zzReader = in;\r
278   }\r
279 \r
280   /**\r
281    * Creates a new scanner.\r
282    * There is also java.io.Reader version of this constructor.\r
283    *\r
284    * @param   in  the java.io.Inputstream to read input from.\r
285    */\r
286   public DocumentationLexer(java.io.InputStream in) {\r
287     this(new java.io.InputStreamReader(in));\r
288   }\r
289 \r
290   /** \r
291    * Unpacks the compressed character translation table.\r
292    *\r
293    * @param packed   the packed character translation table\r
294    * @return         the unpacked character translation table\r
295    */\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
300     while (i < 34) {\r
301       int  count = packed.charAt(i++);\r
302       char value = packed.charAt(i++);\r
303       do map[j++] = value; while (--count > 0);\r
304     }\r
305     return map;\r
306   }\r
307 \r
308 \r
309   /**\r
310    * Refills the input buffer.\r
311    *\r
312    * @return      <code>false</code>, iff there was new input.\r
313    * \r
314    * @exception   java.io.IOException  if any I/O-Error occurs\r
315    */\r
316   private boolean zzRefill() throws java.io.IOException {\r
317 \r
318     /* first: make room (if you can) */\r
319     if (zzStartRead > 0) {\r
320       System.arraycopy(zzBuffer, zzStartRead,\r
321                        zzBuffer, 0,\r
322                        zzEndRead-zzStartRead);\r
323 \r
324       /* translate stored positions */\r
325       zzEndRead-= zzStartRead;\r
326       zzCurrentPos-= zzStartRead;\r
327       zzMarkedPos-= zzStartRead;\r
328       zzStartRead = 0;\r
329     }\r
330 \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
337     }\r
338 \r
339     /* finally: fill the buffer with new input */\r
340     int numRead = zzReader.read(zzBuffer, zzEndRead,\r
341                                             zzBuffer.length-zzEndRead);\r
342 \r
343     if (numRead > 0) {\r
344       zzEndRead+= numRead;\r
345       return false;\r
346     }\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
350       if (c == -1) {\r
351         return true;\r
352       } else {\r
353         zzBuffer[zzEndRead++] = (char) c;\r
354         return false;\r
355       }     \r
356     }\r
357 \r
358         // numRead < 0\r
359     return true;\r
360   }\r
361 \r
362     \r
363   /**\r
364    * Closes the input stream.\r
365    */\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
369 \r
370     if (zzReader != null)\r
371       zzReader.close();\r
372   }\r
373 \r
374 \r
375   /**\r
376    * Resets the scanner to read from a new input stream.\r
377    * Does not close the old reader.\r
378    *\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
382    *\r
383    * @param reader   the new input stream \r
384    */\r
385   public final void yyreset(java.io.Reader reader) {\r
386     zzReader = reader;\r
387     zzAtBOL  = true;\r
388     zzAtEOF  = false;\r
389     zzEOFDone = false;\r
390     zzEndRead = zzStartRead = 0;\r
391     zzCurrentPos = zzMarkedPos = 0;\r
392     yyline = yychar = yycolumn = 0;\r
393     zzLexicalState = YYINITIAL;\r
394   }\r
395 \r
396 \r
397   /**\r
398    * Returns the current lexical state.\r
399    */\r
400   public final int yystate() {\r
401     return zzLexicalState;\r
402   }\r
403 \r
404 \r
405   /**\r
406    * Enters a new lexical state\r
407    *\r
408    * @param newState the new lexical state\r
409    */\r
410   public final void yybegin(int newState) {\r
411     zzLexicalState = newState;\r
412   }\r
413 \r
414 \r
415   /**\r
416    * Returns the text matched by the current regular expression.\r
417    */\r
418   public final String yytext() {\r
419     return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );\r
420   }\r
421 \r
422 \r
423   /**\r
424    * Returns the character at position <tt>pos</tt> from the \r
425    * matched text. \r
426    * \r
427    * It is equivalent to yytext().charAt(pos), but faster\r
428    *\r
429    * @param pos the position of the character to fetch. \r
430    *            A value from 0 to yylength()-1.\r
431    *\r
432    * @return the character at position pos\r
433    */\r
434   public final char yycharat(int pos) {\r
435     return zzBuffer[zzStartRead+pos];\r
436   }\r
437 \r
438 \r
439   /**\r
440    * Returns the length of the matched text region.\r
441    */\r
442   public final int yylength() {\r
443     return zzMarkedPos-zzStartRead;\r
444   }\r
445 \r
446 \r
447   /**\r
448    * Reports an error that occured while scanning.\r
449    *\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
455    *\r
456    * Usual syntax/scanner level error handling should be done\r
457    * in error fallback rules.\r
458    *\r
459    * @param   errorCode  the code of the errormessage to display\r
460    */\r
461   private void zzScanError(int errorCode) {\r
462     String message;\r
463     try {\r
464       message = ZZ_ERROR_MSG[errorCode];\r
465     }\r
466     catch (ArrayIndexOutOfBoundsException e) {\r
467       message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];\r
468     }\r
469 \r
470     throw new Error(message);\r
471   } \r
472 \r
473 \r
474   /**\r
475    * Pushes the specified amount of characters back into the input stream.\r
476    *\r
477    * They will be read again by then next call of the scanning method\r
478    *\r
479    * @param number  the number of characters to be read again.\r
480    *                This number must not be greater than yylength()!\r
481    */\r
482   public void yypushback(int number)  {\r
483     if ( number > yylength() )\r
484       zzScanError(ZZ_PUSHBACK_2BIG);\r
485 \r
486     zzMarkedPos -= number;\r
487   }\r
488 \r
489 \r
490   /**\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
493    *\r
494    * @return      the next token\r
495    * @exception   java.io.IOException  if any I/O-Error occurs\r
496    */\r
497   public DocumentationElement nextToken() throws java.io.IOException, DocumentationParsingException {\r
498     int zzInput;\r
499     int zzAction;\r
500 \r
501     // cached fields:\r
502     int zzCurrentPosL;\r
503     int zzMarkedPosL;\r
504     int zzEndReadL = zzEndRead;\r
505     char [] zzBufferL = zzBuffer;\r
506     char [] zzCMapL = ZZ_CMAP;\r
507 \r
508     int [] zzTransL = ZZ_TRANS;\r
509     int [] zzRowMapL = ZZ_ROWMAP;\r
510     int [] zzAttrL = ZZ_ATTRIBUTE;\r
511 \r
512     while (true) {\r
513       zzMarkedPosL = zzMarkedPos;\r
514 \r
515       yychar+= zzMarkedPosL-zzStartRead;\r
516 \r
517       zzAction = -1;\r
518 \r
519       zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;\r
520   \r
521       zzState = ZZ_LEXSTATE[zzLexicalState];\r
522 \r
523 \r
524       zzForAction: {\r
525         while (true) {\r
526     \r
527           if (zzCurrentPosL < zzEndReadL)\r
528             zzInput = zzBufferL[zzCurrentPosL++];\r
529           else if (zzAtEOF) {\r
530             zzInput = YYEOF;\r
531             break zzForAction;\r
532           }\r
533           else {\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
543             if (eof) {\r
544               zzInput = YYEOF;\r
545               break zzForAction;\r
546             }\r
547             else {\r
548               zzInput = zzBufferL[zzCurrentPosL++];\r
549             }\r
550           }\r
551           int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];\r
552           if (zzNext == -1) break zzForAction;\r
553           zzState = zzNext;\r
554 \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
560           }\r
561 \r
562         }\r
563       }\r
564 \r
565       // store back cached position\r
566       zzMarkedPos = zzMarkedPosL;\r
567 \r
568       switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {\r
569         case 4: \r
570           { return new EntityRef(trimW(yytext().substring(1)));\r
571           }\r
572         case 10: break;\r
573         case 8: \r
574           { return new Header(2, trimN(yytext(), 2));\r
575           }\r
576         case 11: break;\r
577         case 7: \r
578           { return new Header(1, trimN(yytext(), 1));\r
579           }\r
580         case 12: break;\r
581         case 3: \r
582           { return new Paragraph(yytext().trim());\r
583           }\r
584         case 13: break;\r
585         case 9: \r
586           { return new Header(3, trimN(yytext(), 3));\r
587           }\r
588         case 14: break;\r
589         case 1: \r
590           { System.err.println("At " + yychar + ": Illegal character '" + yytext() + "'.");\r
591           }\r
592         case 15: break;\r
593         case 5: \r
594           { return new ListItem(trimW(yytext()));\r
595           }\r
596         case 16: break;\r
597         case 6: \r
598           { return new Preformatted(yytext());\r
599           }\r
600         case 17: break;\r
601         case 2: \r
602           { \r
603           }\r
604         case 18: break;\r
605         default: \r
606           if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {\r
607             zzAtEOF = true;\r
608               {     return null;\r
609  }\r
610           } \r
611           else {\r
612             zzScanError(ZZ_NO_MATCH);\r
613           }\r
614       }\r
615     }\r
616   }\r
617 \r
618 \r
619 }\r