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