Merge remote-tracking branch 'origin/master'
[idea/community.git] / tools / lexer / idea-flex.skeleton
1
2   /** This character denotes the end of file */
3   public static final int YYEOF = -1;
4
5   /** initial size of the lookahead buffer */
6 --- private static final int ZZ_BUFFERSIZE = ...;
7
8   /** lexical states */
9 ---  lexical states, charmap
10
11   /* error codes */
12   private static final int ZZ_UNKNOWN_ERROR = 0;
13   private static final int ZZ_NO_MATCH = 1;
14   private static final int ZZ_PUSHBACK_2BIG = 2;
15
16   /* error messages for the codes above */
17   private static final String[] ZZ_ERROR_MSG = {
18     "Unknown internal scanner error",
19     "Error: could not match input",
20     "Error: pushback value was too large"
21   };
22
23 --- isFinal list
24   /** the input device */
25   private java.io.Reader zzReader;
26
27   /** the current state of the DFA */
28   private int zzState;
29
30   /** the current lexical state */
31   private int zzLexicalState = YYINITIAL;
32
33   /** this buffer contains the current text to be matched and is
34       the source of the yytext() string */
35   private CharSequence zzBuffer = "";
36
37   /** the textposition at the last accepting state */
38   private int zzMarkedPos;
39
40   /** the current text position in the buffer */
41   private int zzCurrentPos;
42
43   /** startRead marks the beginning of the yytext() string in the buffer */
44   private int zzStartRead;
45
46   /** endRead marks the last character in the buffer, that has been read
47       from input */
48   private int zzEndRead;
49
50   /**
51    * zzAtBOL == true <=> the scanner is currently at the beginning of a line
52    */
53   private boolean zzAtBOL = true;
54
55   /** zzAtEOF == true <=> the scanner is at the EOF */
56   private boolean zzAtEOF;
57
58   /** denotes if the user-EOF-code has already been executed */
59   private boolean zzEOFDone;
60
61 --- user class code
62
63 --- constructor declaration
64
65   public final int getTokenStart() {
66     return zzStartRead;
67   }
68
69   public final int getTokenEnd() {
70     return getTokenStart() + yylength();
71   }
72
73   public void reset(CharSequence buffer, int start, int end, int initialState) {
74     zzBuffer = buffer;
75     zzCurrentPos = zzMarkedPos = zzStartRead = start;
76     zzAtEOF  = false;
77     zzAtBOL = true;
78     zzEndRead = end;
79     yybegin(initialState);
80   }
81
82   /**
83    * Refills the input buffer.
84    *
85    * @return      <code>false</code>, iff there was new input.
86    *
87    * @exception   java.io.IOException  if any I/O-Error occurs
88    */
89   private boolean zzRefill() throws java.io.IOException {
90     return true;
91   }
92
93
94   /**
95    * Returns the current lexical state.
96    */
97   public final int yystate() {
98     return zzLexicalState;
99   }
100
101
102   /**
103    * Enters a new lexical state
104    *
105    * @param newState the new lexical state
106    */
107   public final void yybegin(int newState) {
108     zzLexicalState = newState;
109   }
110
111
112   /**
113    * Returns the text matched by the current regular expression.
114    */
115   public final CharSequence yytext() {
116     return zzBuffer.subSequence(zzStartRead, zzMarkedPos);
117   }
118
119
120   /**
121    * Returns the character at position <tt>pos</tt> from the
122    * matched text.
123    *
124    * It is equivalent to yytext().charAt(pos), but faster
125    *
126    * @param pos the position of the character to fetch.
127    *            A value from 0 to yylength()-1.
128    *
129    * @return the character at position pos
130    */
131   public final char yycharat(int pos) {
132     return zzBuffer.charAt(zzStartRead+pos);
133   }
134
135
136   /**
137    * Returns the length of the matched text region.
138    */
139   public final int yylength() {
140     return zzMarkedPos-zzStartRead;
141   }
142
143
144   /**
145    * Reports an error that occured while scanning.
146    *
147    * In a wellformed scanner (no or only correct usage of
148    * yypushback(int) and a match-all fallback rule) this method
149    * will only be called with things that "Can't Possibly Happen".
150    * If this method is called, something is seriously wrong
151    * (e.g. a JFlex bug producing a faulty scanner etc.).
152    *
153    * Usual syntax/scanner level error handling should be done
154    * in error fallback rules.
155    *
156    * @param   errorCode  the code of the errormessage to display
157    */
158 --- zzScanError declaration
159     String message;
160     try {
161       message = ZZ_ERROR_MSG[errorCode];
162     }
163     catch (ArrayIndexOutOfBoundsException e) {
164       message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
165     }
166
167 --- throws clause
168   }
169
170
171   /**
172    * Pushes the specified amount of characters back into the input stream.
173    *
174    * They will be read again by then next call of the scanning method
175    *
176    * @param number  the number of characters to be read again.
177    *                This number must not be greater than yylength()!
178    */
179 --- yypushback decl (contains zzScanError exception)
180     if ( number > yylength() )
181       zzScanError(ZZ_PUSHBACK_2BIG);
182
183     zzMarkedPos -= number;
184   }
185
186
187 --- zzDoEOF
188   /**
189    * Resumes scanning until the next regular expression is matched,
190    * the end of input is encountered or an I/O-Error occurs.
191    *
192    * @return      the next token
193    * @exception   java.io.IOException  if any I/O-Error occurs
194    */
195 --- yylex declaration
196     int zzInput;
197     int zzAction;
198
199     // cached fields:
200     int zzCurrentPosL;
201     int zzMarkedPosL;
202     int zzEndReadL = zzEndRead;
203     CharSequence zzBufferL = zzBuffer;
204
205 --- local declarations
206
207     while (true) {
208       zzMarkedPosL = zzMarkedPos;
209
210 --- start admin (line, char, col count)
211       zzAction = -1;
212
213       zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
214
215 --- start admin (lexstate etc)
216
217       zzForAction: {
218         while (true) {
219
220 --- next input, line, col, char count, next transition, isFinal action
221             zzAction = zzState;
222             zzMarkedPosL = zzCurrentPosL;
223 --- line count update
224           }
225
226         }
227       }
228
229       // store back cached position
230       zzMarkedPos = zzMarkedPosL;
231 --- char count update
232
233       if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
234         zzAtEOF = true;
235 --- eofvalue
236       }
237       else {
238 --- actions
239           default:
240 --- no match
241           }
242       }
243     }
244   }
245
246 --- main
247
248 }