source: other-projects/rsyntax-textarea/src/java/org/fife/ui/rsyntaxtextarea/modes/CSSTokenMaker.java@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 31.3 KB
Line 
1/* The following code was generated by JFlex 1.4.1 on 2/12/12 12:51 AM */
2
3/*
4 * 09/03/2005
5 *
6 * CSSTokenMaker.java - Token maker for CSS 3 files.
7 *
8 * This library is distributed under a modified BSD license. See the included
9 * RSyntaxTextArea.License.txt file for details.
10 */
11package org.fife.ui.rsyntaxtextarea.modes;
12
13import java.io.*;
14import javax.swing.text.Segment;
15
16import org.fife.ui.rsyntaxtextarea.*;
17
18
19/**
20 * This class splits up text into tokens representing a CSS 3 file. It's
21 * written with a few extra internal states so that it can easily be copy
22 * and pasted into HTML, PHP, and JSP TokenMakres when it is updated.<p>
23 *
24 * This implementation was created using
25 * <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
26 * was modified for performance. Memory allocation needs to be almost
27 * completely removed to be competitive with the handwritten lexers (subclasses
28 * of <code>AbstractTokenMaker</code>, so this class has been modified so that
29 * Strings are never allocated (via yytext()), and the scanner never has to
30 * worry about refilling its buffer (needlessly copying chars around).
31 * We can achieve this because RText always scans exactly 1 line of tokens at a
32 * time, and hands the scanner this line as an array of characters (a Segment
33 * really). Since tokens contain pointers to char arrays instead of Strings
34 * holding their contents, there is no need for allocating new memory for
35 * Strings.<p>
36 *
37 * The actual algorithm generated for scanning has, of course, not been
38 * modified.<p>
39 *
40 * If you wish to regenerate this file yourself, keep in mind the following:
41 * <ul>
42 * <li>The generated CSSTokenMaker.java</code> file will contain 2
43 * definitions of both <code>zzRefill</code> and <code>yyreset</code>.
44 * You should hand-delete the second of each definition (the ones
45 * generated by the lexer), as these generated methods modify the input
46 * buffer, which we'll never have to do.</li>
47 * <li>You should also change the declaration/definition of zzBuffer to NOT
48 * be initialized. This is a needless memory allocation for us since we
49 * will be pointing the array somewhere else anyway.</li>
50 * <li>You should NOT call <code>yylex()</code> on the generated scanner
51 * directly; rather, you should use <code>getTokenList</code> as you would
52 * with any other <code>TokenMaker</code> instance.</li>
53 * </ul>
54 *
55 * @author Robert Futrell
56 * @version 0.4
57 *
58 */
59
60public class CSSTokenMaker extends AbstractJFlexTokenMaker implements TokenMaker {
61
62 /** This character denotes the end of file */
63 public static final int YYEOF = -1;
64
65 /** lexical states */
66 public static final int CSS_C_STYLE_COMMENT = 5;
67 public static final int YYINITIAL = 0;
68 public static final int CSS_STRING = 3;
69 public static final int CSS_VALUE = 2;
70 public static final int CSS_PROPERTY = 1;
71 public static final int CSS_CHAR_LITERAL = 4;
72
73 /**
74 * Translates characters to character classes
75 */
76 private static final String ZZ_CMAP_PACKED =
77 "\11\0\1\40\1\61\25\0\1\40\1\63\1\56\1\36\1\52\1\45"+
78 "\1\47\1\57\1\43\1\64\1\5\1\51\1\55\1\4\1\6\1\41"+
79 "\12\1\1\7\1\37\1\0\1\51\1\60\1\47\1\35\6\46\24\2"+
80 "\1\50\1\42\1\50\1\60\1\3\1\0\1\21\1\34\1\15\1\20"+
81 "\1\26\1\23\1\33\1\14\1\16\1\2\1\30\1\17\1\27\1\13"+
82 "\1\11\1\25\1\2\1\10\1\22\1\12\1\32\1\31\1\53\1\44"+
83 "\1\24\1\2\1\54\1\60\1\62\1\51\uff81\0";
84
85 /**
86 * Translates characters to character classes
87 */
88 private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
89
90 /**
91 * Translates DFA states to action switch labels.
92 */
93 private static final int [] ZZ_ACTION = zzUnpackAction();
94
95 private static final String ZZ_ACTION_PACKED_0 =
96 "\2\0\1\1\3\0\1\2\1\3\1\4\2\2\1\5"+
97 "\1\6\1\2\1\7\1\10\1\1\1\11\1\12\1\13"+
98 "\1\14\1\15\1\14\1\16\1\14\1\17\1\20\1\21"+
99 "\1\22\2\1\1\21\1\23\1\1\1\24\1\25\1\21"+
100 "\1\26\1\27\1\30\1\31\1\32\1\27\1\33\1\34"+
101 "\5\27\1\35\15\0\1\36\1\37\1\40\2\0\1\22"+
102 "\3\0\1\22\1\0\1\30\1\41\41\0\1\15\17\0"+
103 "\1\42\47\0\1\43";
104
105 private static int [] zzUnpackAction() {
106 int [] result = new int[167];
107 int offset = 0;
108 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
109 return result;
110 }
111
112 private static int zzUnpackAction(String packed, int offset, int [] result) {
113 int i = 0; /* index in packed string */
114 int j = offset; /* index in unpacked array */
115 int l = packed.length();
116 while (i < l) {
117 int count = packed.charAt(i++);
118 int value = packed.charAt(i++);
119 do result[j++] = value; while (--count > 0);
120 }
121 return j;
122 }
123
124
125 /**
126 * Translates a state to a row index in the transition table
127 */
128 private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
129
130 private static final String ZZ_ROWMAP_PACKED_0 =
131 "\0\0\0\65\0\152\0\237\0\324\0\u0109\0\u013e\0\u0173"+
132 "\0\u01a8\0\u01dd\0\u0212\0\u013e\0\u0247\0\u027c\0\u013e\0\u013e"+
133 "\0\u013e\0\u013e\0\u013e\0\u013e\0\u013e\0\u02b1\0\u02e6\0\u013e"+
134 "\0\u027c\0\u013e\0\u013e\0\u013e\0\u031b\0\u0350\0\u0385\0\u03ba"+
135 "\0\u013e\0\u03ef\0\u013e\0\u013e\0\u0424\0\u013e\0\u0459\0\u048e"+
136 "\0\u013e\0\u013e\0\u04c3\0\u013e\0\u013e\0\u04f8\0\u052d\0\u0562"+
137 "\0\u0597\0\u05cc\0\u013e\0\u0601\0\u0636\0\u066b\0\u06a0\0\u06d5"+
138 "\0\u070a\0\u073f\0\u0774\0\u07a9\0\u07de\0\u0813\0\u0848\0\u087d"+
139 "\0\u08b2\0\u08e7\0\u013e\0\u091c\0\u0951\0\u013e\0\u0986\0\u09bb"+
140 "\0\u09f0\0\u03ba\0\u0a25\0\u013e\0\u013e\0\u0a5a\0\u0a8f\0\u0ac4"+
141 "\0\u0af9\0\u0b2e\0\u0b63\0\u0b98\0\u0bcd\0\u0c02\0\u0c37\0\u0c6c"+
142 "\0\u0ca1\0\u0cd6\0\u0d0b\0\u0d40\0\u0d75\0\u0daa\0\u0ddf\0\u0e14"+
143 "\0\u0e49\0\u0e7e\0\u0eb3\0\u0ee8\0\u0f1d\0\u0f52\0\u0f87\0\u0fbc"+
144 "\0\u0ff1\0\u1026\0\u105b\0\u1090\0\u10c5\0\u10fa\0\u013e\0\u112f"+
145 "\0\u1164\0\u1199\0\u11ce\0\u1203\0\u1238\0\u126d\0\u12a2\0\u12d7"+
146 "\0\u130c\0\u1341\0\u1376\0\u13ab\0\u13e0\0\u1415\0\u144a\0\u147f"+
147 "\0\u14b4\0\u14e9\0\u151e\0\u1553\0\u1588\0\u15bd\0\u15f2\0\u1627"+
148 "\0\u165c\0\u1691\0\u16c6\0\u16fb\0\u1730\0\u144a\0\u1765\0\u179a"+
149 "\0\u17cf\0\u1804\0\u1839\0\u186e\0\u18a3\0\u18d8\0\u190d\0\u1942"+
150 "\0\u1977\0\u19ac\0\u19e1\0\u1a16\0\u1a4b\0\u1a80\0\u1ab5\0\u1aea"+
151 "\0\u1b1f\0\u1b54\0\u1b89\0\u1bbe\0\u1bf3\0\u1c28\0\u013e";
152
153 private static int [] zzUnpackRowMap() {
154 int [] result = new int[167];
155 int offset = 0;
156 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
157 return result;
158 }
159
160 private static int zzUnpackRowMap(String packed, int offset, int [] result) {
161 int i = 0; /* index in packed string */
162 int j = offset; /* index in unpacked array */
163 int l = packed.length();
164 while (i < l) {
165 int high = packed.charAt(i++) << 16;
166 result[j++] = high | packed.charAt(i++);
167 }
168 return j;
169 }
170
171 /**
172 * The transition table of the DFA
173 */
174 private static final int [] ZZ_TRANS = zzUnpackTrans();
175
176 private static final String ZZ_TRANS_PACKED_0 =
177 "\2\7\5\10\1\11\25\10\1\12\1\13\1\14\1\15"+
178 "\1\16\1\7\1\14\1\10\1\7\1\10\1\7\1\14"+
179 "\2\17\1\10\1\20\1\21\1\22\1\23\1\17\1\24"+
180 "\2\7\1\14\2\25\3\26\1\27\1\25\1\30\25\26"+
181 "\3\25\1\15\1\31\2\25\1\26\1\25\1\26\4\25"+
182 "\1\26\5\25\1\32\1\33\2\25\1\34\1\35\2\36"+
183 "\1\37\1\34\1\21\1\34\25\36\1\34\1\40\1\41"+
184 "\1\15\1\42\1\36\1\43\1\36\1\34\1\36\4\34"+
185 "\1\36\1\34\1\21\1\22\1\23\1\34\1\44\1\33"+
186 "\1\45\1\46\42\47\1\50\13\47\1\51\2\47\1\52"+
187 "\3\47\42\53\1\50\14\53\1\54\1\53\1\55\3\53"+
188 "\5\56\1\57\6\56\1\60\6\56\1\61\27\56\1\62"+
189 "\5\56\1\63\3\56\66\0\4\10\1\0\1\10\1\0"+
190 "\25\10\7\0\1\10\1\0\1\10\4\0\1\10\20\0"+
191 "\1\64\1\65\1\66\1\67\1\70\1\71\1\72\1\0"+
192 "\1\73\1\74\1\75\1\0\1\76\2\0\1\77\2\0"+
193 "\1\100\35\0\5\101\1\0\25\101\7\0\1\101\1\0"+
194 "\1\101\4\0\1\101\13\0\5\102\1\0\25\102\7\0"+
195 "\1\102\1\0\1\102\4\0\1\102\51\0\1\15\31\0"+
196 "\1\103\60\0\4\26\3\0\25\26\7\0\1\26\1\0"+
197 "\1\26\4\0\1\26\13\0\3\26\3\0\25\26\7\0"+
198 "\1\26\1\0\1\26\4\0\1\26\12\0\1\35\4\0"+
199 "\1\35\6\0\1\104\1\105\3\0\1\106\2\0\1\107"+
200 "\1\110\1\111\15\0\1\106\21\0\3\36\3\0\25\36"+
201 "\4\0\2\36\1\43\1\36\1\0\1\36\4\0\1\36"+
202 "\12\0\1\35\3\36\3\0\25\36\4\0\2\36\1\43"+
203 "\1\36\1\0\1\36\4\0\1\36\12\0\1\112\13\0"+
204 "\1\112\2\0\2\112\1\0\1\112\2\0\1\112\5\0"+
205 "\1\112\11\0\1\112\20\0\3\36\1\103\2\0\25\36"+
206 "\4\0\2\36\1\43\1\36\1\0\1\36\4\0\1\36"+
207 "\27\0\1\113\46\0\42\47\1\0\13\47\1\0\2\47"+
208 "\1\0\3\47\61\114\1\0\3\114\42\53\1\0\14\53"+
209 "\1\0\1\53\1\0\3\53\5\56\1\0\6\56\1\0"+
210 "\6\56\1\0\27\56\1\0\5\56\1\0\3\56\41\0"+
211 "\1\115\35\0\1\116\64\0\1\117\3\0\1\120\121\0"+
212 "\1\121\32\0\1\122\1\0\1\123\10\0\1\124\41\0"+
213 "\1\125\66\0\1\126\72\0\1\127\54\0\1\130\1\131"+
214 "\63\0\1\132\67\0\1\133\66\0\1\134\2\0\1\135"+
215 "\61\0\1\136\63\0\1\137\60\0\1\140\4\0\1\141"+
216 "\61\0\1\142\13\0\1\143\53\0\1\144\47\0\4\101"+
217 "\1\0\1\101\1\0\25\101\7\0\1\101\1\0\1\101"+
218 "\4\0\1\101\12\0\4\102\1\0\1\102\1\0\25\102"+
219 "\7\0\1\102\1\0\1\102\4\0\1\102\40\0\1\106"+
220 "\50\0\1\106\63\0\1\106\2\0\1\106\26\0\1\106"+
221 "\47\0\1\106\14\0\1\106\42\0\1\106\4\0\1\106"+
222 "\64\0\1\145\47\0\1\146\77\0\1\147\56\0\1\150"+
223 "\120\0\1\151\34\0\1\152\57\0\1\153\74\0\1\154"+
224 "\47\0\1\130\72\0\1\155\55\0\1\156\66\0\1\157"+
225 "\66\0\1\160\101\0\1\161\61\0\1\162\51\0\1\163"+
226 "\64\0\1\164\6\0\1\165\64\0\1\142\54\0\1\166"+
227 "\67\0\1\167\57\0\1\170\75\0\1\171\70\0\1\172"+
228 "\61\0\1\173\67\0\1\174\64\0\1\175\46\0\1\176"+
229 "\103\0\1\147\44\0\1\177\70\0\1\161\62\0\1\200"+
230 "\77\0\1\201\65\0\1\202\73\0\1\203\35\0\1\204"+
231 "\106\0\1\205\53\0\1\206\77\0\1\157\67\0\1\157"+
232 "\43\0\1\202\70\0\1\207\100\0\1\210\54\0\1\165"+
233 "\76\0\1\211\42\0\1\212\70\0\1\213\57\0\1\214"+
234 "\62\0\1\176\12\0\1\147\103\0\1\215\24\0\2\177"+
235 "\5\216\25\177\3\216\1\0\1\177\1\0\1\216\1\177"+
236 "\1\216\1\177\3\216\2\177\1\0\1\216\1\0\1\216"+
237 "\3\0\2\216\22\0\1\217\53\0\1\220\57\0\1\221"+
238 "\106\0\1\130\47\0\1\222\3\0\1\223\1\0\1\224"+
239 "\55\0\1\157\104\0\1\225\65\0\1\226\55\0\1\157"+
240 "\61\0\1\225\71\0\1\157\52\0\1\225\62\0\1\227"+
241 "\115\0\1\177\35\0\1\230\62\0\1\226\65\0\1\222"+
242 "\3\0\1\223\72\0\1\231\55\0\1\232\71\0\1\170"+
243 "\71\0\1\233\64\0\1\157\50\0\1\234\56\0\1\235"+
244 "\64\0\1\236\76\0\1\237\66\0\1\157\65\0\1\240"+
245 "\62\0\1\241\57\0\1\242\71\0\1\233\60\0\1\243"+
246 "\67\0\1\244\7\0\1\245\62\0\1\246\52\0\1\247"+
247 "\65\0\1\226\63\0\1\152\77\0\1\226\37\0";
248
249 private static int [] zzUnpackTrans() {
250 int [] result = new int[7261];
251 int offset = 0;
252 offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
253 return result;
254 }
255
256 private static int zzUnpackTrans(String packed, int offset, int [] result) {
257 int i = 0; /* index in packed string */
258 int j = offset; /* index in unpacked array */
259 int l = packed.length();
260 while (i < l) {
261 int count = packed.charAt(i++);
262 int value = packed.charAt(i++);
263 value--;
264 do result[j++] = value; while (--count > 0);
265 }
266 return j;
267 }
268
269
270 /* error codes */
271 private static final int ZZ_UNKNOWN_ERROR = 0;
272 private static final int ZZ_NO_MATCH = 1;
273 private static final int ZZ_PUSHBACK_2BIG = 2;
274
275 /* error messages for the codes above */
276 private static final String ZZ_ERROR_MSG[] = {
277 "Unkown internal scanner error",
278 "Error: could not match input",
279 "Error: pushback value was too large"
280 };
281
282 /**
283 * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
284 */
285 private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
286
287 private static final String ZZ_ATTRIBUTE_PACKED_0 =
288 "\2\0\1\1\3\0\1\11\4\1\1\11\2\1\7\11"+
289 "\2\1\1\11\1\1\3\11\4\1\1\11\1\1\2\11"+
290 "\1\1\1\11\2\1\2\11\1\1\2\11\5\1\1\11"+
291 "\15\0\2\1\1\11\2\0\1\11\3\0\1\1\1\0"+
292 "\2\11\41\0\1\11\17\0\1\1\47\0\1\11";
293
294 private static int [] zzUnpackAttribute() {
295 int [] result = new int[167];
296 int offset = 0;
297 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
298 return result;
299 }
300
301 private static int zzUnpackAttribute(String packed, int offset, int [] result) {
302 int i = 0; /* index in packed string */
303 int j = offset; /* index in unpacked array */
304 int l = packed.length();
305 while (i < l) {
306 int count = packed.charAt(i++);
307 int value = packed.charAt(i++);
308 do result[j++] = value; while (--count > 0);
309 }
310 return j;
311 }
312
313 /** the input device */
314 private java.io.Reader zzReader;
315
316 /** the current state of the DFA */
317 private int zzState;
318
319 /** the current lexical state */
320 private int zzLexicalState = YYINITIAL;
321
322 /** this buffer contains the current text to be matched and is
323 the source of the yytext() string */
324 private char zzBuffer[];
325
326 /** the textposition at the last accepting state */
327 private int zzMarkedPos;
328
329 /** the current text position in the buffer */
330 private int zzCurrentPos;
331
332 /** startRead marks the beginning of the yytext() string in the buffer */
333 private int zzStartRead;
334
335 /** endRead marks the last character in the buffer, that has been read
336 from input */
337 private int zzEndRead;
338
339 /** zzAtEOF == true <=> the scanner is at the EOF */
340 private boolean zzAtEOF;
341
342 /* user code: */
343
344 /**
345 * Internal type denoting a line ending in a CSS property.
346 */
347 public static final int INTERNAL_CSS_PROPERTY = -1;
348
349 /**
350 * Internal type denoting a line ending in a CSS property value.
351 */
352 public static final int INTERNAL_CSS_VALUE = -2;
353
354 /**
355 * Internal type denoting line ending in a CSS double-quote string.
356 * The state to return to is embedded in the actual end token type.
357 */
358 public static final int INTERNAL_CSS_STRING = -(1<<11);
359
360 /**
361 * Internal type denoting line ending in a CSS single-quote string.
362 * The state to return to is embedded in the actual end token type.
363 */
364 public static final int INTERNAL_CSS_CHAR = -(2<<11);
365
366 /**
367 * Internal type denoting line ending in a CSS multi-line comment.
368 * The state to return to is embedded in the actual end token type.
369 */
370 public static final int INTERNAL_CSS_MLC = -(3<<11);
371
372 /**
373 * The state previous CSS-related state we were in before going into a CSS
374 * string, multi-line comment, etc.
375 */
376 private int cssPrevState;
377
378
379 /**
380 * Constructor. This must be here because JFlex does not generate a
381 * no-parameter constructor.
382 */
383 public CSSTokenMaker() {
384 super();
385 }
386
387
388 /**
389 * Adds the token specified to the current linked list of tokens as an
390 * "end token;" that is, at <code>zzMarkedPos</code>.
391 *
392 * @param tokenType The token's type.
393 */
394 private void addEndToken(int tokenType) {
395 addToken(zzMarkedPos,zzMarkedPos, tokenType);
396 }
397
398
399 /**
400 * Adds the token specified to the current linked list of tokens.
401 *
402 * @param tokenType The token's type.
403 * @see #addToken(int, int, int)
404 */
405 private void addHyperlinkToken(int start, int end, int tokenType) {
406 int so = start + offsetShift;
407 addToken(zzBuffer, start,end, tokenType, so, true);
408 }
409
410
411 /**
412 * Adds the token specified to the current linked list of tokens.
413 *
414 * @param tokenType The token's type.
415 */
416 private void addToken(int tokenType) {
417 addToken(zzStartRead, zzMarkedPos-1, tokenType);
418 }
419
420
421 /**
422 * Adds the token specified to the current linked list of tokens.
423 *
424 * @param tokenType The token's type.
425 */
426 private void addToken(int start, int end, int tokenType) {
427 int so = start + offsetShift;
428 addToken(zzBuffer, start,end, tokenType, so);
429 }
430
431
432 /**
433 * Adds the token specified to the current linked list of tokens.
434 *
435 * @param array The character array.
436 * @param start The starting offset in the array.
437 * @param end The ending offset in the array.
438 * @param tokenType The token's type.
439 * @param startOffset The offset in the document at which this token
440 * occurs.
441 */
442 public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
443 super.addToken(array, start,end, tokenType, startOffset);
444 zzStartRead = zzMarkedPos;
445 }
446
447
448 /**
449 * Returns <code>true</code> since CSS uses curly braces.
450 *
451 * @return <code>true</code> always.
452 */
453 public boolean getCurlyBracesDenoteCodeBlocks() {
454 return true;
455 }
456
457
458 /**
459 * Returns the first token in the linked list of tokens generated
460 * from <code>text</code>. This method must be implemented by
461 * subclasses so they can correctly implement syntax highlighting.
462 *
463 * @param text The text from which to get tokens.
464 * @param initialTokenType The token type we should start with.
465 * @param startOffset The offset into the document at which
466 * <code>text</code> starts.
467 * @return The first <code>Token</code> in a linked list representing
468 * the syntax highlighted text.
469 */
470 public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
471
472 resetTokenList();
473 this.offsetShift = -text.offset + startOffset;
474 cssPrevState = YYINITIAL; // Shouldn't be necessary
475
476 // Start off in the proper state.
477 int state = Token.NULL;
478 switch (initialTokenType) {
479 case Token.LITERAL_STRING_DOUBLE_QUOTE:
480 state = CSS_STRING;
481 break;
482 case Token.LITERAL_CHAR:
483 state = CSS_CHAR_LITERAL;
484 break;
485 case Token.COMMENT_MULTILINE:
486 state = CSS_C_STYLE_COMMENT;
487 break;
488 case INTERNAL_CSS_PROPERTY:
489 state = CSS_PROPERTY;
490 break;
491 case INTERNAL_CSS_VALUE:
492 state = CSS_VALUE;
493 break;
494 default:
495 if (initialTokenType<-1024) {
496 int main = -(-initialTokenType & 0xffffff00);
497 switch (main) {
498 default: // Should never happen
499 case INTERNAL_CSS_STRING:
500 state = CSS_STRING;
501 break;
502 case INTERNAL_CSS_CHAR:
503 state = CSS_CHAR_LITERAL;
504 break;
505 case INTERNAL_CSS_MLC:
506 state = CSS_C_STYLE_COMMENT;
507 break;
508 }
509 cssPrevState = -initialTokenType&0xff;
510 }
511 else {
512 state = Token.NULL;
513 }
514 }
515
516 start = text.offset;
517 s = text;
518 try {
519 yyreset(zzReader);
520 yybegin(state);
521 return yylex();
522 } catch (IOException ioe) {
523 ioe.printStackTrace();
524 return new DefaultToken();
525 }
526
527 }
528
529
530 /**
531 * Refills the input buffer.
532 *
533 * @return <code>true</code> if EOF was reached, otherwise
534 * <code>false</code>.
535 */
536 private boolean zzRefill() {
537 return zzCurrentPos>=s.offset+s.count;
538 }
539
540
541 /**
542 * Resets the scanner to read from a new input stream.
543 * Does not close the old reader.
544 *
545 * All internal variables are reset, the old input stream
546 * <b>cannot</b> be reused (internal buffer is discarded and lost).
547 * Lexical state is set to <tt>YY_INITIAL</tt>.
548 *
549 * @param reader the new input stream
550 */
551 public final void yyreset(java.io.Reader reader) {
552 // 's' has been updated.
553 zzBuffer = s.array;
554 /*
555 * We replaced the line below with the two below it because zzRefill
556 * no longer "refills" the buffer (since the way we do it, it's always
557 * "full" the first time through, since it points to the segment's
558 * array). So, we assign zzEndRead here.
559 */
560 //zzStartRead = zzEndRead = s.offset;
561 zzStartRead = s.offset;
562 zzEndRead = zzStartRead + s.count - 1;
563 zzCurrentPos = zzMarkedPos = s.offset;
564 zzLexicalState = YYINITIAL;
565 zzReader = reader;
566 zzAtEOF = false;
567 }
568
569
570
571
572 /**
573 * Creates a new scanner
574 * There is also a java.io.InputStream version of this constructor.
575 *
576 * @param in the java.io.Reader to read input from.
577 */
578 public CSSTokenMaker(java.io.Reader in) {
579 this.zzReader = in;
580 }
581
582 /**
583 * Creates a new scanner.
584 * There is also java.io.Reader version of this constructor.
585 *
586 * @param in the java.io.Inputstream to read input from.
587 */
588 public CSSTokenMaker(java.io.InputStream in) {
589 this(new java.io.InputStreamReader(in));
590 }
591
592 /**
593 * Unpacks the compressed character translation table.
594 *
595 * @param packed the packed character translation table
596 * @return the unpacked character translation table
597 */
598 private static char [] zzUnpackCMap(String packed) {
599 char [] map = new char[0x10000];
600 int i = 0; /* index in packed string */
601 int j = 0; /* index in unpacked array */
602 while (i < 134) {
603 int count = packed.charAt(i++);
604 char value = packed.charAt(i++);
605 do map[j++] = value; while (--count > 0);
606 }
607 return map;
608 }
609
610
611 /**
612 * Closes the input stream.
613 */
614 public final void yyclose() throws java.io.IOException {
615 zzAtEOF = true; /* indicate end of file */
616 zzEndRead = zzStartRead; /* invalidate buffer */
617
618 if (zzReader != null)
619 zzReader.close();
620 }
621
622
623 /**
624 * Returns the current lexical state.
625 */
626 public final int yystate() {
627 return zzLexicalState;
628 }
629
630
631 /**
632 * Enters a new lexical state
633 *
634 * @param newState the new lexical state
635 */
636 public final void yybegin(int newState) {
637 zzLexicalState = newState;
638 }
639
640
641 /**
642 * Returns the text matched by the current regular expression.
643 */
644 public final String yytext() {
645 return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
646 }
647
648
649 /**
650 * Returns the character at position <tt>pos</tt> from the
651 * matched text.
652 *
653 * It is equivalent to yytext().charAt(pos), but faster
654 *
655 * @param pos the position of the character to fetch.
656 * A value from 0 to yylength()-1.
657 *
658 * @return the character at position pos
659 */
660 public final char yycharat(int pos) {
661 return zzBuffer[zzStartRead+pos];
662 }
663
664
665 /**
666 * Returns the length of the matched text region.
667 */
668 public final int yylength() {
669 return zzMarkedPos-zzStartRead;
670 }
671
672
673 /**
674 * Reports an error that occured while scanning.
675 *
676 * In a wellformed scanner (no or only correct usage of
677 * yypushback(int) and a match-all fallback rule) this method
678 * will only be called with things that "Can't Possibly Happen".
679 * If this method is called, something is seriously wrong
680 * (e.g. a JFlex bug producing a faulty scanner etc.).
681 *
682 * Usual syntax/scanner level error handling should be done
683 * in error fallback rules.
684 *
685 * @param errorCode the code of the errormessage to display
686 */
687 private void zzScanError(int errorCode) {
688 String message;
689 try {
690 message = ZZ_ERROR_MSG[errorCode];
691 }
692 catch (ArrayIndexOutOfBoundsException e) {
693 message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
694 }
695
696 throw new Error(message);
697 }
698
699
700 /**
701 * Pushes the specified amount of characters back into the input stream.
702 *
703 * They will be read again by then next call of the scanning method
704 *
705 * @param number the number of characters to be read again.
706 * This number must not be greater than yylength()!
707 */
708 public void yypushback(int number) {
709 if ( number > yylength() )
710 zzScanError(ZZ_PUSHBACK_2BIG);
711
712 zzMarkedPos -= number;
713 }
714
715
716 /**
717 * Resumes scanning until the next regular expression is matched,
718 * the end of input is encountered or an I/O-Error occurs.
719 *
720 * @return the next token
721 * @exception java.io.IOException if any I/O-Error occurs
722 */
723 public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
724 int zzInput;
725 int zzAction;
726
727 // cached fields:
728 int zzCurrentPosL;
729 int zzMarkedPosL;
730 int zzEndReadL = zzEndRead;
731 char [] zzBufferL = zzBuffer;
732 char [] zzCMapL = ZZ_CMAP;
733
734 int [] zzTransL = ZZ_TRANS;
735 int [] zzRowMapL = ZZ_ROWMAP;
736 int [] zzAttrL = ZZ_ATTRIBUTE;
737
738 while (true) {
739 zzMarkedPosL = zzMarkedPos;
740
741 zzAction = -1;
742
743 zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
744
745 zzState = zzLexicalState;
746
747
748 zzForAction: {
749 while (true) {
750
751 if (zzCurrentPosL < zzEndReadL)
752 zzInput = zzBufferL[zzCurrentPosL++];
753 else if (zzAtEOF) {
754 zzInput = YYEOF;
755 break zzForAction;
756 }
757 else {
758 // store back cached positions
759 zzCurrentPos = zzCurrentPosL;
760 zzMarkedPos = zzMarkedPosL;
761 boolean eof = zzRefill();
762 // get translated positions and possibly new buffer
763 zzCurrentPosL = zzCurrentPos;
764 zzMarkedPosL = zzMarkedPos;
765 zzBufferL = zzBuffer;
766 zzEndReadL = zzEndRead;
767 if (eof) {
768 zzInput = YYEOF;
769 break zzForAction;
770 }
771 else {
772 zzInput = zzBufferL[zzCurrentPosL++];
773 }
774 }
775 int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
776 if (zzNext == -1) break zzForAction;
777 zzState = zzNext;
778
779 int zzAttributes = zzAttrL[zzState];
780 if ( (zzAttributes & 1) == 1 ) {
781 zzAction = zzState;
782 zzMarkedPosL = zzCurrentPosL;
783 if ( (zzAttributes & 8) == 8 ) break zzForAction;
784 }
785
786 }
787 }
788
789 // store back cached position
790 zzMarkedPos = zzMarkedPosL;
791
792 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
793 case 4:
794 { /* Unknown pseudo class */ addToken(Token.DATA_TYPE);
795 }
796 case 36: break;
797 case 11:
798 { addNullToken(); return firstToken;
799 }
800 case 37: break;
801 case 27:
802 { addToken(start,zzStartRead, Token.LITERAL_CHAR); yybegin(cssPrevState);
803 }
804 case 38: break;
805 case 15:
806 { addEndToken(INTERNAL_CSS_PROPERTY); return firstToken;
807 }
808 case 39: break;
809 case 22:
810 { /* End of a function */ addToken(Token.SEPARATOR);
811 }
812 case 40: break;
813 case 6:
814 { addToken(Token.WHITESPACE);
815 }
816 case 41: break;
817 case 2:
818 { /*System.out.println("yyinitial: " + yytext());*/ addToken(Token.IDENTIFIER);
819 }
820 case 42: break;
821 case 32:
822 { start = zzMarkedPos-2; cssPrevState = zzLexicalState; yybegin(CSS_C_STYLE_COMMENT);
823 }
824 case 43: break;
825 case 14:
826 { addToken(Token.OPERATOR); yybegin(CSS_VALUE);
827 }
828 case 44: break;
829 case 13:
830 { addToken(Token.RESERVED_WORD);
831 }
832 case 45: break;
833 case 31:
834 { addToken(Token.VARIABLE);
835 }
836 case 46: break;
837 case 5:
838 { addToken(Token.SEPARATOR);
839 }
840 case 47: break;
841 case 16:
842 { addToken(Token.SEPARATOR); yybegin(YYINITIAL);
843 }
844 case 48: break;
845 case 26:
846 { addToken(start,zzStartRead-1, Token.LITERAL_STRING_DOUBLE_QUOTE); addEndToken(INTERNAL_CSS_STRING - cssPrevState); return firstToken;
847 }
848 case 49: break;
849 case 1:
850 { addToken(Token.IDENTIFIER);
851 }
852 case 50: break;
853 case 19:
854 { addToken(Token.OPERATOR); yybegin(CSS_PROPERTY);
855 }
856 case 51: break;
857 case 9:
858 { start = zzMarkedPos-1; cssPrevState = zzLexicalState; yybegin(CSS_STRING);
859 }
860 case 52: break;
861 case 30:
862 { addToken(Token.REGEX);
863 }
864 case 53: break;
865 case 12:
866 { /*System.out.println("css_property: " + yytext());*/ addToken(Token.IDENTIFIER);
867 }
868 case 54: break;
869 case 17:
870 { /*System.out.println("css_value: " + yytext());*/ addToken(Token.IDENTIFIER);
871 }
872 case 55: break;
873 case 33:
874 { addToken(start,zzStartRead+1, Token.COMMENT_MULTILINE); yybegin(cssPrevState);
875 }
876 case 56: break;
877 case 24:
878 { /* Skip escaped chars. */
879 }
880 case 57: break;
881 case 3:
882 { addToken(Token.DATA_TYPE);
883 }
884 case 58: break;
885 case 10:
886 { start = zzMarkedPos-1; cssPrevState = zzLexicalState; yybegin(CSS_CHAR_LITERAL);
887 }
888 case 59: break;
889 case 35:
890 { addToken(Token.ANNOTATION);
891 }
892 case 60: break;
893 case 25:
894 { addToken(start,zzStartRead, Token.LITERAL_STRING_DOUBLE_QUOTE); yybegin(cssPrevState);
895 }
896 case 61: break;
897 case 20:
898 { int temp = zzMarkedPos - 2;
899 addToken(zzStartRead, temp, Token.FUNCTION);
900 addToken(zzMarkedPos-1, zzMarkedPos-1, Token.SEPARATOR);
901 zzStartRead = zzCurrentPos = zzMarkedPos;
902 }
903 case 62: break;
904 case 8:
905 { addToken(Token.SEPARATOR); yybegin(CSS_PROPERTY);
906 }
907 case 63: break;
908 case 28:
909 { addToken(start,zzStartRead-1, Token.LITERAL_CHAR); addEndToken(INTERNAL_CSS_CHAR - cssPrevState); return firstToken;
910 }
911 case 64: break;
912 case 34:
913 { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_MULTILINE); start = zzMarkedPos;
914 }
915 case 65: break;
916 case 21:
917 { addEndToken(INTERNAL_CSS_VALUE); return firstToken;
918 }
919 case 66: break;
920 case 29:
921 { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addEndToken(INTERNAL_CSS_MLC - cssPrevState); return firstToken;
922 }
923 case 67: break;
924 case 18:
925 { addToken(Token.LITERAL_NUMBER_DECIMAL_INT);
926 }
927 case 68: break;
928 case 7:
929 { addToken(Token.OPERATOR);
930 }
931 case 69: break;
932 case 23:
933 {
934 }
935 case 70: break;
936 default:
937 if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
938 zzAtEOF = true;
939 switch (zzLexicalState) {
940 case CSS_C_STYLE_COMMENT: {
941 addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addEndToken(INTERNAL_CSS_MLC - cssPrevState); return firstToken;
942 }
943 case 168: break;
944 case YYINITIAL: {
945 addNullToken(); return firstToken;
946 }
947 case 169: break;
948 case CSS_STRING: {
949 addToken(start,zzStartRead-1, Token.LITERAL_STRING_DOUBLE_QUOTE); addEndToken(INTERNAL_CSS_STRING - cssPrevState); return firstToken;
950 }
951 case 170: break;
952 case CSS_VALUE: {
953 addEndToken(INTERNAL_CSS_VALUE); return firstToken;
954 }
955 case 171: break;
956 case CSS_PROPERTY: {
957 addEndToken(INTERNAL_CSS_PROPERTY); return firstToken;
958 }
959 case 172: break;
960 case CSS_CHAR_LITERAL: {
961 addToken(start,zzStartRead-1, Token.LITERAL_CHAR); addEndToken(INTERNAL_CSS_CHAR - cssPrevState); return firstToken;
962 }
963 case 173: break;
964 default:
965 return null;
966 }
967 }
968 else {
969 zzScanError(ZZ_NO_MATCH);
970 }
971 }
972 }
973 }
974
975
976}
Note: See TracBrowser for help on using the repository browser.