1 | /* The following code was generated by JFlex 1.4.1 on 4/28/12 4:57 PM */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * 04/24/2012
|
---|
5 | *
|
---|
6 | * LatexTokenMaker.java - Scanner for LaTeX.
|
---|
7 | *
|
---|
8 | * This library is distributed under a modified BSD license. See the included
|
---|
9 | * RSyntaxTextArea.License.txt file for details.
|
---|
10 | */
|
---|
11 | package org.fife.ui.rsyntaxtextarea.modes;
|
---|
12 |
|
---|
13 | import java.io.*;
|
---|
14 | import javax.swing.text.Segment;
|
---|
15 |
|
---|
16 | import org.fife.ui.rsyntaxtextarea.*;
|
---|
17 |
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Scanner for the LaTeX.<p>
|
---|
21 | *
|
---|
22 | * This implementation was created using
|
---|
23 | * <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
|
---|
24 | * was modified for performance. Memory allocation needs to be almost
|
---|
25 | * completely removed to be competitive with the handwritten lexers (subclasses
|
---|
26 | * of <code>AbstractTokenMaker</code>, so this class has been modified so that
|
---|
27 | * Strings are never allocated (via yytext()), and the scanner never has to
|
---|
28 | * worry about refilling its buffer (needlessly copying chars around).
|
---|
29 | * We can achieve this because RSTA always scans exactly 1 line of tokens at a
|
---|
30 | * time, and hands the scanner this line as an array of characters (a Segment
|
---|
31 | * really). Since tokens contain pointers to char arrays instead of Strings
|
---|
32 | * holding their contents, there is no need for allocating new memory for
|
---|
33 | * Strings.<p>
|
---|
34 | *
|
---|
35 | * The actual algorithm generated for scanning has, of course, not been
|
---|
36 | * modified.<p>
|
---|
37 | *
|
---|
38 | * If you wish to regenerate this file yourself, keep in mind the following:
|
---|
39 | * <ul>
|
---|
40 | * <li>The generated LatexTokenMaker.java</code> file will contain two
|
---|
41 | * definitions of both <code>zzRefill</code> and <code>yyreset</code>.
|
---|
42 | * You should hand-delete the second of each definition (the ones
|
---|
43 | * generated by the lexer), as these generated methods modify the input
|
---|
44 | * buffer, which we'll never have to do.</li>
|
---|
45 | * <li>You should also change the declaration/definition of zzBuffer to NOT
|
---|
46 | * be initialized. This is a needless memory allocation for us since we
|
---|
47 | * will be pointing the array somewhere else anyway.</li>
|
---|
48 | * <li>You should NOT call <code>yylex()</code> on the generated scanner
|
---|
49 | * directly; rather, you should use <code>getTokenList</code> as you would
|
---|
50 | * with any other <code>TokenMaker</code> instance.</li>
|
---|
51 | * </ul>
|
---|
52 | *
|
---|
53 | * @author Robert Futrell
|
---|
54 | * @version 0.5
|
---|
55 | *
|
---|
56 | */
|
---|
57 |
|
---|
58 | public class LatexTokenMaker extends AbstractJFlexTokenMaker {
|
---|
59 |
|
---|
60 | /** This character denotes the end of file */
|
---|
61 | public static final int YYEOF = -1;
|
---|
62 |
|
---|
63 | /** lexical states */
|
---|
64 | public static final int EOL_COMMENT = 1;
|
---|
65 | public static final int YYINITIAL = 0;
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Translates characters to character classes
|
---|
69 | */
|
---|
70 | private static final String ZZ_CMAP_PACKED =
|
---|
71 | "\11\0\1\3\1\32\1\0\1\3\23\0\1\3\1\5\1\0\1\5"+
|
---|
72 | "\1\7\1\4\7\5\1\2\1\22\1\6\12\1\1\20\1\5\1\0"+
|
---|
73 | "\1\5\1\0\2\5\32\1\1\5\1\23\1\5\1\0\1\2\1\0"+
|
---|
74 | "\1\1\1\25\1\1\1\31\1\17\1\14\1\26\1\10\1\15\2\1"+
|
---|
75 | "\1\16\1\1\1\27\1\1\1\12\2\1\1\13\1\11\2\1\1\21"+
|
---|
76 | "\3\1\1\30\1\0\1\24\1\5\uff81\0";
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Translates characters to character classes
|
---|
80 | */
|
---|
81 | private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Translates DFA states to action switch labels.
|
---|
85 | */
|
---|
86 | private static final int [] ZZ_ACTION = zzUnpackAction();
|
---|
87 |
|
---|
88 | private static final String ZZ_ACTION_PACKED_0 =
|
---|
89 | "\2\0\2\1\1\2\1\3\1\1\1\4\1\5\4\6"+
|
---|
90 | "\1\7\3\10\4\0\2\10\4\0\2\10\2\0\1\11"+
|
---|
91 | "\1\0\1\10\3\0\1\10\1\12\2\0\1\13";
|
---|
92 |
|
---|
93 | private static int [] zzUnpackAction() {
|
---|
94 | int [] result = new int[42];
|
---|
95 | int offset = 0;
|
---|
96 | offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
|
---|
97 | return result;
|
---|
98 | }
|
---|
99 |
|
---|
100 | private static int zzUnpackAction(String packed, int offset, int [] result) {
|
---|
101 | int i = 0; /* index in packed string */
|
---|
102 | int j = offset; /* index in unpacked array */
|
---|
103 | int l = packed.length();
|
---|
104 | while (i < l) {
|
---|
105 | int count = packed.charAt(i++);
|
---|
106 | int value = packed.charAt(i++);
|
---|
107 | do result[j++] = value; while (--count > 0);
|
---|
108 | }
|
---|
109 | return j;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Translates a state to a row index in the transition table
|
---|
115 | */
|
---|
116 | private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
|
---|
117 |
|
---|
118 | private static final String ZZ_ROWMAP_PACKED_0 =
|
---|
119 | "\0\0\0\33\0\66\0\121\0\66\0\66\0\154\0\66"+
|
---|
120 | "\0\66\0\207\0\242\0\275\0\330\0\66\0\363\0\u010e"+
|
---|
121 | "\0\u0129\0\u0144\0\u015f\0\u017a\0\u0195\0\u01b0\0\u01cb\0\u01e6"+
|
---|
122 | "\0\u0201\0\u021c\0\u0237\0\u0252\0\u026d\0\u0288\0\u02a3\0\u02be"+
|
---|
123 | "\0\u02d9\0\u02f4\0\u030f\0\u02be\0\u032a\0\u0345\0\66\0\u0360"+
|
---|
124 | "\0\u037b\0\66";
|
---|
125 |
|
---|
126 | private static int [] zzUnpackRowMap() {
|
---|
127 | int [] result = new int[42];
|
---|
128 | int offset = 0;
|
---|
129 | offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
|
---|
130 | return result;
|
---|
131 | }
|
---|
132 |
|
---|
133 | private static int zzUnpackRowMap(String packed, int offset, int [] result) {
|
---|
134 | int i = 0; /* index in packed string */
|
---|
135 | int j = offset; /* index in unpacked array */
|
---|
136 | int l = packed.length();
|
---|
137 | while (i < l) {
|
---|
138 | int high = packed.charAt(i++) << 16;
|
---|
139 | result[j++] = high | packed.charAt(i++);
|
---|
140 | }
|
---|
141 | return j;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * The transition table of the DFA
|
---|
146 | */
|
---|
147 | private static final int [] ZZ_TRANS = zzUnpackTrans();
|
---|
148 |
|
---|
149 | private static final String ZZ_TRANS_PACKED_0 =
|
---|
150 | "\1\3\2\4\1\5\1\6\3\3\10\4\1\3\1\4"+
|
---|
151 | "\1\3\1\7\1\10\3\4\1\10\1\4\1\11\10\12"+
|
---|
152 | "\1\13\3\12\1\14\4\12\1\15\10\12\1\16\34\0"+
|
---|
153 | "\2\4\5\0\10\4\1\0\1\4\3\0\3\4\1\0"+
|
---|
154 | "\1\4\2\0\2\17\5\0\7\17\1\20\1\0\1\17"+
|
---|
155 | "\3\0\1\21\2\17\1\0\1\17\1\0\10\12\1\0"+
|
---|
156 | "\3\12\1\0\4\12\1\0\10\12\12\0\1\22\32\0"+
|
---|
157 | "\1\23\3\0\1\24\36\0\1\25\12\0\2\17\5\0"+
|
---|
158 | "\10\17\1\0\1\17\3\0\3\17\1\0\1\17\2\0"+
|
---|
159 | "\2\17\5\0\10\17\1\0\1\17\3\0\2\17\1\26"+
|
---|
160 | "\1\0\1\17\2\0\2\17\5\0\7\17\1\27\1\0"+
|
---|
161 | "\1\17\3\0\3\17\1\0\1\17\12\0\1\30\33\0"+
|
---|
162 | "\1\31\36\0\1\32\35\0\1\33\12\0\2\17\5\0"+
|
---|
163 | "\10\17\1\0\1\17\3\0\3\17\1\0\1\34\2\0"+
|
---|
164 | "\2\17\5\0\10\17\1\0\1\17\3\0\1\17\1\35"+
|
---|
165 | "\1\17\1\0\1\17\13\0\1\36\40\0\1\37\31\0"+
|
---|
166 | "\1\31\35\0\1\40\11\0\2\17\5\0\10\17\1\0"+
|
---|
167 | "\1\17\3\0\3\17\1\41\1\17\2\0\2\17\5\0"+
|
---|
168 | "\5\17\1\42\2\17\1\0\1\17\3\0\3\17\1\0"+
|
---|
169 | "\1\17\14\0\1\31\4\0\1\37\20\0\1\43\25\0"+
|
---|
170 | "\1\40\1\44\1\0\2\44\12\40\1\44\1\40\1\44"+
|
---|
171 | "\2\0\3\40\1\0\1\40\2\0\2\45\5\0\10\45"+
|
---|
172 | "\1\0\1\45\3\0\3\45\1\0\1\45\2\0\2\17"+
|
---|
173 | "\5\0\10\17\1\0\1\17\3\0\2\17\1\46\1\0"+
|
---|
174 | "\1\17\7\0\1\40\25\0\2\45\5\0\10\45\1\0"+
|
---|
175 | "\1\45\2\0\1\47\3\45\1\0\1\45\2\0\2\17"+
|
---|
176 | "\5\0\10\17\1\0\1\17\3\0\3\17\1\50\1\17"+
|
---|
177 | "\2\0\2\51\5\0\10\51\1\0\1\51\3\0\3\51"+
|
---|
178 | "\1\0\1\51\2\0\2\51\5\0\10\51\1\0\1\51"+
|
---|
179 | "\2\0\1\52\3\51\1\0\1\51\1\0";
|
---|
180 |
|
---|
181 | private static int [] zzUnpackTrans() {
|
---|
182 | int [] result = new int[918];
|
---|
183 | int offset = 0;
|
---|
184 | offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
|
---|
185 | return result;
|
---|
186 | }
|
---|
187 |
|
---|
188 | private static int zzUnpackTrans(String packed, int offset, int [] result) {
|
---|
189 | int i = 0; /* index in packed string */
|
---|
190 | int j = offset; /* index in unpacked array */
|
---|
191 | int l = packed.length();
|
---|
192 | while (i < l) {
|
---|
193 | int count = packed.charAt(i++);
|
---|
194 | int value = packed.charAt(i++);
|
---|
195 | value--;
|
---|
196 | do result[j++] = value; while (--count > 0);
|
---|
197 | }
|
---|
198 | return j;
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | /* error codes */
|
---|
203 | private static final int ZZ_UNKNOWN_ERROR = 0;
|
---|
204 | private static final int ZZ_NO_MATCH = 1;
|
---|
205 | private static final int ZZ_PUSHBACK_2BIG = 2;
|
---|
206 |
|
---|
207 | /* error messages for the codes above */
|
---|
208 | private static final String ZZ_ERROR_MSG[] = {
|
---|
209 | "Unkown internal scanner error",
|
---|
210 | "Error: could not match input",
|
---|
211 | "Error: pushback value was too large"
|
---|
212 | };
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
|
---|
216 | */
|
---|
217 | private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
|
---|
218 |
|
---|
219 | private static final String ZZ_ATTRIBUTE_PACKED_0 =
|
---|
220 | "\2\0\1\11\1\1\2\11\1\1\2\11\4\1\1\11"+
|
---|
221 | "\3\1\4\0\2\1\4\0\2\1\2\0\1\1\1\0"+
|
---|
222 | "\1\1\3\0\1\1\1\11\2\0\1\11";
|
---|
223 |
|
---|
224 | private static int [] zzUnpackAttribute() {
|
---|
225 | int [] result = new int[42];
|
---|
226 | int offset = 0;
|
---|
227 | offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
|
---|
228 | return result;
|
---|
229 | }
|
---|
230 |
|
---|
231 | private static int zzUnpackAttribute(String packed, int offset, int [] result) {
|
---|
232 | int i = 0; /* index in packed string */
|
---|
233 | int j = offset; /* index in unpacked array */
|
---|
234 | int l = packed.length();
|
---|
235 | while (i < l) {
|
---|
236 | int count = packed.charAt(i++);
|
---|
237 | int value = packed.charAt(i++);
|
---|
238 | do result[j++] = value; while (--count > 0);
|
---|
239 | }
|
---|
240 | return j;
|
---|
241 | }
|
---|
242 |
|
---|
243 | /** the input device */
|
---|
244 | private java.io.Reader zzReader;
|
---|
245 |
|
---|
246 | /** the current state of the DFA */
|
---|
247 | private int zzState;
|
---|
248 |
|
---|
249 | /** the current lexical state */
|
---|
250 | private int zzLexicalState = YYINITIAL;
|
---|
251 |
|
---|
252 | /** this buffer contains the current text to be matched and is
|
---|
253 | the source of the yytext() string */
|
---|
254 | private char zzBuffer[];
|
---|
255 |
|
---|
256 | /** the textposition at the last accepting state */
|
---|
257 | private int zzMarkedPos;
|
---|
258 |
|
---|
259 | /** the current text position in the buffer */
|
---|
260 | private int zzCurrentPos;
|
---|
261 |
|
---|
262 | /** startRead marks the beginning of the yytext() string in the buffer */
|
---|
263 | private int zzStartRead;
|
---|
264 |
|
---|
265 | /** endRead marks the last character in the buffer, that has been read
|
---|
266 | from input */
|
---|
267 | private int zzEndRead;
|
---|
268 |
|
---|
269 | /** zzAtEOF == true <=> the scanner is at the EOF */
|
---|
270 | private boolean zzAtEOF;
|
---|
271 |
|
---|
272 | /* user code: */
|
---|
273 |
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * Constructor. This must be here because JFlex does not generate a
|
---|
277 | * no-parameter constructor.
|
---|
278 | */
|
---|
279 | public LatexTokenMaker() {
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Adds the token specified to the current linked list of tokens.
|
---|
285 | *
|
---|
286 | * @param tokenType The token's type.
|
---|
287 | * @see #addToken(int, int, int)
|
---|
288 | */
|
---|
289 | private void addHyperlinkToken(int start, int end, int tokenType) {
|
---|
290 | int so = start + offsetShift;
|
---|
291 | addToken(zzBuffer, start,end, tokenType, so, true);
|
---|
292 | }
|
---|
293 |
|
---|
294 |
|
---|
295 | /**
|
---|
296 | * Adds the token specified to the current linked list of tokens.
|
---|
297 | *
|
---|
298 | * @param tokenType The token's type.
|
---|
299 | */
|
---|
300 | private void addToken(int tokenType) {
|
---|
301 | addToken(zzStartRead, zzMarkedPos-1, tokenType);
|
---|
302 | }
|
---|
303 |
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Adds the token specified to the current linked list of tokens.
|
---|
307 | *
|
---|
308 | * @param tokenType The token's type.
|
---|
309 | * @see #addHyperlinkToken(int, int, int)
|
---|
310 | */
|
---|
311 | private void addToken(int start, int end, int tokenType) {
|
---|
312 | int so = start + offsetShift;
|
---|
313 | addToken(zzBuffer, start,end, tokenType, so, false);
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Adds the token specified to the current linked list of tokens.
|
---|
319 | *
|
---|
320 | * @param array The character array.
|
---|
321 | * @param start The starting offset in the array.
|
---|
322 | * @param end The ending offset in the array.
|
---|
323 | * @param tokenType The token's type.
|
---|
324 | * @param startOffset The offset in the document at which this token
|
---|
325 | * occurs.
|
---|
326 | * @param hyperlink Whether this token is a hyperlink.
|
---|
327 | */
|
---|
328 | public void addToken(char[] array, int start, int end, int tokenType,
|
---|
329 | int startOffset, boolean hyperlink) {
|
---|
330 | super.addToken(array, start,end, tokenType, startOffset, hyperlink);
|
---|
331 | zzStartRead = zzMarkedPos;
|
---|
332 | }
|
---|
333 |
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * ${inheritDoc}
|
---|
337 | */
|
---|
338 | public String[] getLineCommentStartAndEnd() {
|
---|
339 | return new String[] { "%", null };
|
---|
340 | }
|
---|
341 |
|
---|
342 |
|
---|
343 | /**
|
---|
344 | * Returns the first token in the linked list of tokens generated
|
---|
345 | * from <code>text</code>. This method must be implemented by
|
---|
346 | * subclasses so they can correctly implement syntax highlighting.
|
---|
347 | *
|
---|
348 | * @param text The text from which to get tokens.
|
---|
349 | * @param initialTokenType The token type we should start with.
|
---|
350 | * @param startOffset The offset into the document at which
|
---|
351 | * <code>text</code> starts.
|
---|
352 | * @return The first <code>Token</code> in a linked list representing
|
---|
353 | * the syntax highlighted text.
|
---|
354 | */
|
---|
355 | public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
|
---|
356 |
|
---|
357 | resetTokenList();
|
---|
358 | this.offsetShift = -text.offset + startOffset;
|
---|
359 |
|
---|
360 | // Start off in the proper state.
|
---|
361 | int state = Token.NULL;
|
---|
362 |
|
---|
363 | s = text;
|
---|
364 | try {
|
---|
365 | yyreset(zzReader);
|
---|
366 | yybegin(state);
|
---|
367 | return yylex();
|
---|
368 | } catch (IOException ioe) {
|
---|
369 | ioe.printStackTrace();
|
---|
370 | return new DefaultToken();
|
---|
371 | }
|
---|
372 |
|
---|
373 | }
|
---|
374 |
|
---|
375 |
|
---|
376 | /**
|
---|
377 | * Refills the input buffer.
|
---|
378 | *
|
---|
379 | * @return <code>true</code> if EOF was reached, otherwise
|
---|
380 | * <code>false</code>.
|
---|
381 | * @exception IOException if any I/O-Error occurs.
|
---|
382 | */
|
---|
383 | private boolean zzRefill() {
|
---|
384 | return zzCurrentPos>=s.offset+s.count;
|
---|
385 | }
|
---|
386 |
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Resets the scanner to read from a new input stream.
|
---|
390 | * Does not close the old reader.
|
---|
391 | *
|
---|
392 | * All internal variables are reset, the old input stream
|
---|
393 | * <b>cannot</b> be reused (internal buffer is discarded and lost).
|
---|
394 | * Lexical state is set to <tt>YY_INITIAL</tt>.
|
---|
395 | *
|
---|
396 | * @param reader the new input stream
|
---|
397 | */
|
---|
398 | public final void yyreset(java.io.Reader reader) {
|
---|
399 | // 's' has been updated.
|
---|
400 | zzBuffer = s.array;
|
---|
401 | /*
|
---|
402 | * We replaced the line below with the two below it because zzRefill
|
---|
403 | * no longer "refills" the buffer (since the way we do it, it's always
|
---|
404 | * "full" the first time through, since it points to the segment's
|
---|
405 | * array). So, we assign zzEndRead here.
|
---|
406 | */
|
---|
407 | //zzStartRead = zzEndRead = s.offset;
|
---|
408 | zzStartRead = s.offset;
|
---|
409 | zzEndRead = zzStartRead + s.count - 1;
|
---|
410 | zzCurrentPos = zzMarkedPos = s.offset;
|
---|
411 | zzLexicalState = YYINITIAL;
|
---|
412 | zzReader = reader;
|
---|
413 | zzAtEOF = false;
|
---|
414 | }
|
---|
415 |
|
---|
416 |
|
---|
417 |
|
---|
418 |
|
---|
419 | /**
|
---|
420 | * Creates a new scanner
|
---|
421 | * There is also a java.io.InputStream version of this constructor.
|
---|
422 | *
|
---|
423 | * @param in the java.io.Reader to read input from.
|
---|
424 | */
|
---|
425 | public LatexTokenMaker(java.io.Reader in) {
|
---|
426 | this.zzReader = in;
|
---|
427 | }
|
---|
428 |
|
---|
429 | /**
|
---|
430 | * Creates a new scanner.
|
---|
431 | * There is also java.io.Reader version of this constructor.
|
---|
432 | *
|
---|
433 | * @param in the java.io.Inputstream to read input from.
|
---|
434 | */
|
---|
435 | public LatexTokenMaker(java.io.InputStream in) {
|
---|
436 | this(new java.io.InputStreamReader(in));
|
---|
437 | }
|
---|
438 |
|
---|
439 | /**
|
---|
440 | * Unpacks the compressed character translation table.
|
---|
441 | *
|
---|
442 | * @param packed the packed character translation table
|
---|
443 | * @return the unpacked character translation table
|
---|
444 | */
|
---|
445 | private static char [] zzUnpackCMap(String packed) {
|
---|
446 | char [] map = new char[0x10000];
|
---|
447 | int i = 0; /* index in packed string */
|
---|
448 | int j = 0; /* index in unpacked array */
|
---|
449 | while (i < 112) {
|
---|
450 | int count = packed.charAt(i++);
|
---|
451 | char value = packed.charAt(i++);
|
---|
452 | do map[j++] = value; while (--count > 0);
|
---|
453 | }
|
---|
454 | return map;
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 | /**
|
---|
459 | * Closes the input stream.
|
---|
460 | */
|
---|
461 | public final void yyclose() throws java.io.IOException {
|
---|
462 | zzAtEOF = true; /* indicate end of file */
|
---|
463 | zzEndRead = zzStartRead; /* invalidate buffer */
|
---|
464 |
|
---|
465 | if (zzReader != null)
|
---|
466 | zzReader.close();
|
---|
467 | }
|
---|
468 |
|
---|
469 |
|
---|
470 | /**
|
---|
471 | * Returns the current lexical state.
|
---|
472 | */
|
---|
473 | public final int yystate() {
|
---|
474 | return zzLexicalState;
|
---|
475 | }
|
---|
476 |
|
---|
477 |
|
---|
478 | /**
|
---|
479 | * Enters a new lexical state
|
---|
480 | *
|
---|
481 | * @param newState the new lexical state
|
---|
482 | */
|
---|
483 | public final void yybegin(int newState) {
|
---|
484 | zzLexicalState = newState;
|
---|
485 | }
|
---|
486 |
|
---|
487 |
|
---|
488 | /**
|
---|
489 | * Returns the text matched by the current regular expression.
|
---|
490 | */
|
---|
491 | public final String yytext() {
|
---|
492 | return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
|
---|
493 | }
|
---|
494 |
|
---|
495 |
|
---|
496 | /**
|
---|
497 | * Returns the character at position <tt>pos</tt> from the
|
---|
498 | * matched text.
|
---|
499 | *
|
---|
500 | * It is equivalent to yytext().charAt(pos), but faster
|
---|
501 | *
|
---|
502 | * @param pos the position of the character to fetch.
|
---|
503 | * A value from 0 to yylength()-1.
|
---|
504 | *
|
---|
505 | * @return the character at position pos
|
---|
506 | */
|
---|
507 | public final char yycharat(int pos) {
|
---|
508 | return zzBuffer[zzStartRead+pos];
|
---|
509 | }
|
---|
510 |
|
---|
511 |
|
---|
512 | /**
|
---|
513 | * Returns the length of the matched text region.
|
---|
514 | */
|
---|
515 | public final int yylength() {
|
---|
516 | return zzMarkedPos-zzStartRead;
|
---|
517 | }
|
---|
518 |
|
---|
519 |
|
---|
520 | /**
|
---|
521 | * Reports an error that occured while scanning.
|
---|
522 | *
|
---|
523 | * In a wellformed scanner (no or only correct usage of
|
---|
524 | * yypushback(int) and a match-all fallback rule) this method
|
---|
525 | * will only be called with things that "Can't Possibly Happen".
|
---|
526 | * If this method is called, something is seriously wrong
|
---|
527 | * (e.g. a JFlex bug producing a faulty scanner etc.).
|
---|
528 | *
|
---|
529 | * Usual syntax/scanner level error handling should be done
|
---|
530 | * in error fallback rules.
|
---|
531 | *
|
---|
532 | * @param errorCode the code of the errormessage to display
|
---|
533 | */
|
---|
534 | private void zzScanError(int errorCode) {
|
---|
535 | String message;
|
---|
536 | try {
|
---|
537 | message = ZZ_ERROR_MSG[errorCode];
|
---|
538 | }
|
---|
539 | catch (ArrayIndexOutOfBoundsException e) {
|
---|
540 | message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
---|
541 | }
|
---|
542 |
|
---|
543 | throw new Error(message);
|
---|
544 | }
|
---|
545 |
|
---|
546 |
|
---|
547 | /**
|
---|
548 | * Pushes the specified amount of characters back into the input stream.
|
---|
549 | *
|
---|
550 | * They will be read again by then next call of the scanning method
|
---|
551 | *
|
---|
552 | * @param number the number of characters to be read again.
|
---|
553 | * This number must not be greater than yylength()!
|
---|
554 | */
|
---|
555 | public void yypushback(int number) {
|
---|
556 | if ( number > yylength() )
|
---|
557 | zzScanError(ZZ_PUSHBACK_2BIG);
|
---|
558 |
|
---|
559 | zzMarkedPos -= number;
|
---|
560 | }
|
---|
561 |
|
---|
562 |
|
---|
563 | /**
|
---|
564 | * Resumes scanning until the next regular expression is matched,
|
---|
565 | * the end of input is encountered or an I/O-Error occurs.
|
---|
566 | *
|
---|
567 | * @return the next token
|
---|
568 | * @exception java.io.IOException if any I/O-Error occurs
|
---|
569 | */
|
---|
570 | public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
|
---|
571 | int zzInput;
|
---|
572 | int zzAction;
|
---|
573 |
|
---|
574 | // cached fields:
|
---|
575 | int zzCurrentPosL;
|
---|
576 | int zzMarkedPosL;
|
---|
577 | int zzEndReadL = zzEndRead;
|
---|
578 | char [] zzBufferL = zzBuffer;
|
---|
579 | char [] zzCMapL = ZZ_CMAP;
|
---|
580 |
|
---|
581 | int [] zzTransL = ZZ_TRANS;
|
---|
582 | int [] zzRowMapL = ZZ_ROWMAP;
|
---|
583 | int [] zzAttrL = ZZ_ATTRIBUTE;
|
---|
584 |
|
---|
585 | while (true) {
|
---|
586 | zzMarkedPosL = zzMarkedPos;
|
---|
587 |
|
---|
588 | zzAction = -1;
|
---|
589 |
|
---|
590 | zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
|
---|
591 |
|
---|
592 | zzState = zzLexicalState;
|
---|
593 |
|
---|
594 |
|
---|
595 | zzForAction: {
|
---|
596 | while (true) {
|
---|
597 |
|
---|
598 | if (zzCurrentPosL < zzEndReadL)
|
---|
599 | zzInput = zzBufferL[zzCurrentPosL++];
|
---|
600 | else if (zzAtEOF) {
|
---|
601 | zzInput = YYEOF;
|
---|
602 | break zzForAction;
|
---|
603 | }
|
---|
604 | else {
|
---|
605 | // store back cached positions
|
---|
606 | zzCurrentPos = zzCurrentPosL;
|
---|
607 | zzMarkedPos = zzMarkedPosL;
|
---|
608 | boolean eof = zzRefill();
|
---|
609 | // get translated positions and possibly new buffer
|
---|
610 | zzCurrentPosL = zzCurrentPos;
|
---|
611 | zzMarkedPosL = zzMarkedPos;
|
---|
612 | zzBufferL = zzBuffer;
|
---|
613 | zzEndReadL = zzEndRead;
|
---|
614 | if (eof) {
|
---|
615 | zzInput = YYEOF;
|
---|
616 | break zzForAction;
|
---|
617 | }
|
---|
618 | else {
|
---|
619 | zzInput = zzBufferL[zzCurrentPosL++];
|
---|
620 | }
|
---|
621 | }
|
---|
622 | int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
|
---|
623 | if (zzNext == -1) break zzForAction;
|
---|
624 | zzState = zzNext;
|
---|
625 |
|
---|
626 | int zzAttributes = zzAttrL[zzState];
|
---|
627 | if ( (zzAttributes & 1) == 1 ) {
|
---|
628 | zzAction = zzState;
|
---|
629 | zzMarkedPosL = zzCurrentPosL;
|
---|
630 | if ( (zzAttributes & 8) == 8 ) break zzForAction;
|
---|
631 | }
|
---|
632 |
|
---|
633 | }
|
---|
634 | }
|
---|
635 |
|
---|
636 | // store back cached position
|
---|
637 | zzMarkedPos = zzMarkedPosL;
|
---|
638 |
|
---|
639 | switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
|
---|
640 | case 1:
|
---|
641 | { addToken(Token.IDENTIFIER);
|
---|
642 | }
|
---|
643 | case 12: break;
|
---|
644 | case 8:
|
---|
645 | { addToken(Token.FUNCTION);
|
---|
646 | }
|
---|
647 | case 13: break;
|
---|
648 | case 2:
|
---|
649 | { addToken(Token.WHITESPACE);
|
---|
650 | }
|
---|
651 | case 14: break;
|
---|
652 | case 9:
|
---|
653 | { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_EOL); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_EOL); start = zzMarkedPos;
|
---|
654 | }
|
---|
655 | case 15: break;
|
---|
656 | case 3:
|
---|
657 | { start = zzMarkedPos-1; yybegin(EOL_COMMENT);
|
---|
658 | }
|
---|
659 | case 16: break;
|
---|
660 | case 5:
|
---|
661 | { addNullToken(); return firstToken;
|
---|
662 | }
|
---|
663 | case 17: break;
|
---|
664 | case 7:
|
---|
665 | { addToken(start,zzStartRead-1, Token.COMMENT_EOL); addNullToken(); return firstToken;
|
---|
666 | }
|
---|
667 | case 18: break;
|
---|
668 | case 10:
|
---|
669 | { int temp = zzStartRead;
|
---|
670 | addToken(temp, temp+3, Token.RESERVED_WORD);
|
---|
671 | addToken(temp+4, temp+4, Token.SEPARATOR);
|
---|
672 | addToken(temp+5, zzMarkedPos-2, Token.RESERVED_WORD);
|
---|
673 | addToken(zzMarkedPos-1, zzMarkedPos-1, Token.SEPARATOR);
|
---|
674 | }
|
---|
675 | case 19: break;
|
---|
676 | case 11:
|
---|
677 | { int temp = zzStartRead;
|
---|
678 | addToken(temp, temp+5, Token.RESERVED_WORD);
|
---|
679 | addToken(temp+6, temp+6, Token.SEPARATOR);
|
---|
680 | addToken(temp+7, zzMarkedPos-2, Token.RESERVED_WORD);
|
---|
681 | addToken(zzMarkedPos-1, zzMarkedPos-1, Token.SEPARATOR);
|
---|
682 | }
|
---|
683 | case 20: break;
|
---|
684 | case 6:
|
---|
685 | {
|
---|
686 | }
|
---|
687 | case 21: break;
|
---|
688 | case 4:
|
---|
689 | { addToken(Token.SEPARATOR);
|
---|
690 | }
|
---|
691 | case 22: break;
|
---|
692 | default:
|
---|
693 | if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
|
---|
694 | zzAtEOF = true;
|
---|
695 | switch (zzLexicalState) {
|
---|
696 | case EOL_COMMENT: {
|
---|
697 | addToken(start,zzStartRead-1, Token.COMMENT_EOL); addNullToken(); return firstToken;
|
---|
698 | }
|
---|
699 | case 43: break;
|
---|
700 | case YYINITIAL: {
|
---|
701 | addNullToken(); return firstToken;
|
---|
702 | }
|
---|
703 | case 44: break;
|
---|
704 | default:
|
---|
705 | return null;
|
---|
706 | }
|
---|
707 | }
|
---|
708 | else {
|
---|
709 | zzScanError(ZZ_NO_MATCH);
|
---|
710 | }
|
---|
711 | }
|
---|
712 | }
|
---|
713 | }
|
---|
714 |
|
---|
715 |
|
---|
716 | }
|
---|