source: other-projects/rsyntax-textarea/src/java/org/fife/ui/rsyntaxtextarea/modes/XMLTokenMaker.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: 30.1 KB
Line 
1/* The following code was generated by JFlex 1.4.1 on 2/17/12 7:12 PM */
2
3/*
4 * 01/24/2005
5 *
6 * XMLTokenMaker.java - Generates tokens for XML syntax highlighting.
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 * Scanner for XML.
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 RText 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 <code>XMLTokenMaker.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
58public class XMLTokenMaker extends AbstractMarkupTokenMaker {
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 INTAG = 4;
65 public static final int DTD = 3;
66 public static final int INATTR_DOUBLE = 5;
67 public static final int YYINITIAL = 0;
68 public static final int COMMENT = 1;
69 public static final int CDATA = 7;
70 public static final int INATTR_SINGLE = 6;
71 public static final int PI = 2;
72
73 /**
74 * Translates characters to character classes
75 */
76 private static final String ZZ_CMAP_PACKED =
77 "\11\0\1\6\1\4\1\0\1\3\23\0\1\6\1\12\1\11\1\22"+
78 "\1\30\1\22\1\7\1\25\5\22\1\2\1\42\1\24\12\27\1\23"+
79 "\1\10\1\5\1\44\1\21\1\43\1\22\1\16\1\26\1\14\1\15"+
80 "\17\26\1\17\6\26\1\13\1\0\1\20\1\0\1\1\1\0\4\26"+
81 "\1\40\1\35\1\26\1\31\1\36\2\26\1\37\3\26\1\33\2\26"+
82 "\1\34\1\32\2\26\1\41\3\26\3\0\1\22\uff81\0";
83
84 /**
85 * Translates characters to character classes
86 */
87 private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
88
89 /**
90 * Translates DFA states to action switch labels.
91 */
92 private static final int [] ZZ_ACTION = zzUnpackAction();
93
94 private static final String ZZ_ACTION_PACKED_0 =
95 "\5\0\2\1\1\0\2\2\1\3\1\4\1\5\1\6"+
96 "\2\1\1\7\4\1\1\10\2\1\1\11\1\1\1\12"+
97 "\1\13\1\14\2\15\1\16\1\17\1\20\1\21\1\22"+
98 "\1\1\1\23\3\1\1\24\1\25\1\4\1\26\1\6"+
99 "\5\0\1\27\4\0\1\30\1\31\5\0\1\32\1\33"+
100 "\3\0\1\34\1\35\6\0\1\36";
101
102 private static int [] zzUnpackAction() {
103 int [] result = new int[77];
104 int offset = 0;
105 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
106 return result;
107 }
108
109 private static int zzUnpackAction(String packed, int offset, int [] result) {
110 int i = 0; /* index in packed string */
111 int j = offset; /* index in unpacked array */
112 int l = packed.length();
113 while (i < l) {
114 int count = packed.charAt(i++);
115 int value = packed.charAt(i++);
116 do result[j++] = value; while (--count > 0);
117 }
118 return j;
119 }
120
121
122 /**
123 * Translates a state to a row index in the transition table
124 */
125 private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
126
127 private static final String ZZ_ROWMAP_PACKED_0 =
128 "\0\0\0\45\0\112\0\157\0\224\0\271\0\336\0\u0103"+
129 "\0\u0128\0\u014d\0\u0172\0\u0197\0\u01bc\0\u01e1\0\u0206\0\u022b"+
130 "\0\u0172\0\u0250\0\u0275\0\u029a\0\u02bf\0\u0172\0\u02e4\0\u0309"+
131 "\0\u0172\0\u032e\0\u0172\0\u0172\0\u0172\0\u0353\0\u0378\0\u0172"+
132 "\0\u0172\0\u039d\0\u0172\0\u0172\0\u03c2\0\u0172\0\u03e7\0\u040c"+
133 "\0\u0431\0\u0456\0\u047b\0\u04a0\0\u0172\0\u0172\0\u04c5\0\u04ea"+
134 "\0\u050f\0\u0534\0\u0559\0\u0172\0\u057e\0\u05a3\0\u05c8\0\u05ed"+
135 "\0\u0612\0\u0172\0\u0637\0\u065c\0\u0681\0\u06a6\0\u06cb\0\u0172"+
136 "\0\u0172\0\u06f0\0\u0715\0\u073a\0\u075f\0\u0172\0\u0784\0\u07a9"+
137 "\0\u075f\0\u07ce\0\u07f3\0\u0818\0\u0172";
138
139 private static int [] zzUnpackRowMap() {
140 int [] result = new int[77];
141 int offset = 0;
142 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
143 return result;
144 }
145
146 private static int zzUnpackRowMap(String packed, int offset, int [] result) {
147 int i = 0; /* index in packed string */
148 int j = offset; /* index in unpacked array */
149 int l = packed.length();
150 while (i < l) {
151 int high = packed.charAt(i++) << 16;
152 result[j++] = high | packed.charAt(i++);
153 }
154 return j;
155 }
156
157 /**
158 * The transition table of the DFA
159 */
160 private static final int [] ZZ_TRANS = zzUnpackTrans();
161
162 private static final String ZZ_TRANS_PACKED_0 =
163 "\3\11\1\12\1\13\1\14\1\15\1\16\35\11\2\17"+
164 "\1\20\1\17\1\21\24\17\1\22\3\17\1\23\3\17"+
165 "\1\24\3\17\4\25\1\26\36\25\1\27\1\25\4\30"+
166 "\1\31\1\32\5\30\1\33\4\30\1\34\1\35\23\30"+
167 "\3\36\1\37\1\0\1\36\1\15\2\36\1\40\7\36"+
168 "\1\41\2\36\1\42\1\43\16\36\1\44\11\45\1\46"+
169 "\33\45\25\47\1\46\17\47\20\50\1\51\24\50\4\11"+
170 "\4\0\40\11\1\12\2\0\1\15\1\0\35\11\46\0"+
171 "\1\52\10\0\1\53\1\0\4\52\3\0\1\52\1\54"+
172 "\1\0\1\52\2\0\11\52\1\0\1\55\4\0\1\15"+
173 "\2\0\1\15\36\0\6\16\1\0\1\16\1\56\34\16"+
174 "\2\17\1\0\1\17\1\0\24\17\1\0\3\17\1\0"+
175 "\3\17\1\0\3\17\2\0\1\57\74\0\1\60\44\0"+
176 "\1\61\3\0\1\62\47\0\1\63\3\0\4\25\1\0"+
177 "\36\25\1\0\1\25\21\0\1\64\23\0\4\30\2\0"+
178 "\5\30\1\0\4\30\2\0\23\30\12\0\1\65\32\0"+
179 "\4\36\1\0\1\36\1\0\2\36\1\0\7\36\1\0"+
180 "\2\36\2\0\16\36\1\0\3\36\1\37\1\0\1\36"+
181 "\1\15\2\36\1\0\7\36\1\0\2\36\2\0\16\36"+
182 "\22\0\1\41\23\0\11\45\1\0\33\45\25\47\1\0"+
183 "\17\47\20\50\1\0\24\50\20\0\1\66\25\0\2\52"+
184 "\11\0\4\52\3\0\1\52\2\0\2\52\1\0\12\52"+
185 "\4\0\1\67\10\0\1\70\32\0\1\71\12\0\4\71"+
186 "\3\0\1\71\2\0\1\71\2\0\11\71\24\0\1\72"+
187 "\55\0\1\73\45\0\1\74\50\0\1\75\46\0\1\76"+
188 "\5\0\1\77\63\0\1\100\25\0\1\101\56\0\1\102"+
189 "\31\0\2\71\11\0\4\71\3\0\1\71\2\0\2\71"+
190 "\1\0\12\71\35\0\1\103\34\0\1\104\61\0\1\74"+
191 "\46\0\1\105\4\0\1\106\57\0\1\107\52\0\1\104"+
192 "\10\0\1\74\34\0\1\110\21\0\2\111\4\0\2\111"+
193 "\1\0\2\111\4\105\1\111\1\0\2\111\1\105\1\111"+
194 "\14\105\3\111\16\0\1\112\52\0\1\105\37\0\1\113"+
195 "\43\0\1\114\41\0\1\115\31\0";
196
197 private static int [] zzUnpackTrans() {
198 int [] result = new int[2109];
199 int offset = 0;
200 offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
201 return result;
202 }
203
204 private static int zzUnpackTrans(String packed, int offset, int [] result) {
205 int i = 0; /* index in packed string */
206 int j = offset; /* index in unpacked array */
207 int l = packed.length();
208 while (i < l) {
209 int count = packed.charAt(i++);
210 int value = packed.charAt(i++);
211 value--;
212 do result[j++] = value; while (--count > 0);
213 }
214 return j;
215 }
216
217
218 /* error codes */
219 private static final int ZZ_UNKNOWN_ERROR = 0;
220 private static final int ZZ_NO_MATCH = 1;
221 private static final int ZZ_PUSHBACK_2BIG = 2;
222
223 /* error messages for the codes above */
224 private static final String ZZ_ERROR_MSG[] = {
225 "Unkown internal scanner error",
226 "Error: could not match input",
227 "Error: pushback value was too large"
228 };
229
230 /**
231 * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
232 */
233 private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
234
235 private static final String ZZ_ATTRIBUTE_PACKED_0 =
236 "\5\0\2\1\1\0\2\1\1\11\5\1\1\11\4\1"+
237 "\1\11\2\1\1\11\1\1\3\11\2\1\2\11\1\1"+
238 "\2\11\1\1\1\11\6\1\2\11\5\0\1\11\4\0"+
239 "\1\1\1\11\5\0\2\11\3\0\1\1\1\11\6\0"+
240 "\1\11";
241
242 private static int [] zzUnpackAttribute() {
243 int [] result = new int[77];
244 int offset = 0;
245 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
246 return result;
247 }
248
249 private static int zzUnpackAttribute(String packed, int offset, int [] result) {
250 int i = 0; /* index in packed string */
251 int j = offset; /* index in unpacked array */
252 int l = packed.length();
253 while (i < l) {
254 int count = packed.charAt(i++);
255 int value = packed.charAt(i++);
256 do result[j++] = value; while (--count > 0);
257 }
258 return j;
259 }
260
261 /** the input device */
262 private java.io.Reader zzReader;
263
264 /** the current state of the DFA */
265 private int zzState;
266
267 /** the current lexical state */
268 private int zzLexicalState = YYINITIAL;
269
270 /** this buffer contains the current text to be matched and is
271 the source of the yytext() string */
272 private char zzBuffer[];
273
274 /** the textposition at the last accepting state */
275 private int zzMarkedPos;
276
277 /** the current text position in the buffer */
278 private int zzCurrentPos;
279
280 /** startRead marks the beginning of the yytext() string in the buffer */
281 private int zzStartRead;
282
283 /** endRead marks the last character in the buffer, that has been read
284 from input */
285 private int zzEndRead;
286
287 /** zzAtEOF == true <=> the scanner is at the EOF */
288 private boolean zzAtEOF;
289
290 /* user code: */
291
292 /**
293 * Type specific to XMLTokenMaker denoting a line ending with an unclosed
294 * double-quote attribute.
295 */
296 public static final int INTERNAL_ATTR_DOUBLE = -1;
297
298
299 /**
300 * Type specific to XMLTokenMaker denoting a line ending with an unclosed
301 * single-quote attribute.
302 */
303 public static final int INTERNAL_ATTR_SINGLE = -2;
304
305
306 /**
307 * Token type specific to XMLTokenMaker denoting a line ending with an
308 * unclosed XML tag; thus a new line is beginning still inside of the tag.
309 */
310 public static final int INTERNAL_INTAG = -3;
311
312 /**
313 * Token type specific to XMLTokenMaker denoting a line ending with an
314 * unclosed DOCTYPE element.
315 */
316 public static final int INTERNAL_DTD = -4;
317
318 /**
319 * Token type specific to XMLTokenMaker denoting a line ending with an
320 * unclosed, locally-defined DTD in a DOCTYPE element.
321 */
322 public static final int INTERNAL_DTD_INTERNAL = -5;
323
324 /**
325 * Token type specific to XMLTokenMaker denoting a line ending with an
326 * unclosed comment. The state to return to when this comment ends is
327 * embedded in the token type as well.
328 */
329 public static final int INTERNAL_IN_XML_COMMENT = -(1<<11);
330
331 /**
332 * Whether closing markup tags are automatically completed for HTML.
333 */
334 private static boolean completeCloseTags;
335
336 /**
337 * Whether the DTD we're currently in is a locally-defined one. This
338 * field is only valid when in a DOCTYPE element (the <DTD> state).
339 */
340 private boolean inInternalDtd;
341
342 /**
343 * The state we were in prior to the current one. This is used to know
344 * what state to resume after an MLC ends.
345 */
346 private int prevState;
347
348
349 /**
350 * Constructor. This must be here because JFlex does not generate a
351 * no-parameter constructor.
352 */
353 public XMLTokenMaker() {
354 }
355
356
357 static {
358 completeCloseTags = true;
359 }
360
361
362 /**
363 * Adds the token specified to the current linked list of tokens as an
364 * "end token;" that is, at <code>zzMarkedPos</code>.
365 *
366 * @param tokenType The token's type.
367 */
368 private void addEndToken(int tokenType) {
369 addToken(zzMarkedPos,zzMarkedPos, tokenType);
370 }
371
372
373 /**
374 * Adds the token specified to the current linked list of tokens.
375 *
376 * @param tokenType The token's type.
377 * @see #addToken(int, int, int)
378 */
379 private void addHyperlinkToken(int start, int end, int tokenType) {
380 int so = start + offsetShift;
381 addToken(zzBuffer, start,end, tokenType, so, true);
382 }
383
384
385 /**
386 * Adds the token specified to the current linked list of tokens.
387 *
388 * @param tokenType The token's type.
389 */
390 private void addToken(int tokenType) {
391 addToken(zzStartRead, zzMarkedPos-1, tokenType);
392 }
393
394
395 /**
396 * Adds the token specified to the current linked list of tokens.
397 *
398 * @param tokenType The token's type.
399 */
400 private void addToken(int start, int end, int tokenType) {
401 int so = start + offsetShift;
402 addToken(zzBuffer, start,end, tokenType, so);
403 }
404
405
406 /**
407 * Adds the token specified to the current linked list of tokens.
408 *
409 * @param array The character array.
410 * @param start The starting offset in the array.
411 * @param end The ending offset in the array.
412 * @param tokenType The token's type.
413 * @param startOffset The offset in the document at which this token
414 * occurs.
415 */
416 public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
417 super.addToken(array, start,end, tokenType, startOffset);
418 zzStartRead = zzMarkedPos;
419 }
420
421
422 /**
423 * Returns whether markup close tags should be completed. For XML, the
424 * default value is <code>true</code>.
425 *
426 * @return Whether closing markup tags are completed.
427 * @see #setCompleteCloseTags(boolean)
428 */
429 public boolean getCompleteCloseTags() {
430 return completeCloseTags;
431 }
432
433
434 /**
435 * Static version of {@link #getCompleteCloseTags()}. This hack is
436 * unfortunately needed for applications to be able to query this value
437 * without instantiating this class.
438 *
439 * @return Whether closing markup tags are completed.
440 * @see #setCompleteCloseTags(boolean)
441 */
442 public static boolean getCompleteCloseMarkupTags() {
443 return completeCloseTags;
444 }
445
446
447 /**
448 * Always returns <tt>false</tt>, as you never want "mark occurrences"
449 * working in XML files.
450 *
451 * @param type The token type.
452 * @return Whether tokens of this type should have "mark occurrences"
453 * enabled.
454 */
455 public boolean getMarkOccurrencesOfTokenType(int type) {
456 return false;
457 }
458
459
460 /**
461 * Returns the first token in the linked list of tokens generated
462 * from <code>text</code>. This method must be implemented by
463 * subclasses so they can correctly implement syntax highlighting.
464 *
465 * @param text The text from which to get tokens.
466 * @param initialTokenType The token type we should start with.
467 * @param startOffset The offset into the document at which
468 * <code>text</code> starts.
469 * @return The first <code>Token</code> in a linked list representing
470 * the syntax highlighted text.
471 */
472 public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
473
474 resetTokenList();
475 this.offsetShift = -text.offset + startOffset;
476 prevState = YYINITIAL;
477 inInternalDtd = false;
478
479 // Start off in the proper state.
480 int state = Token.NULL;
481 switch (initialTokenType) {
482 case Token.COMMENT_MULTILINE:
483 state = COMMENT;
484 break;
485 case INTERNAL_DTD:
486 state = DTD;
487 break;
488 case INTERNAL_DTD_INTERNAL:
489 state = DTD;
490 inInternalDtd = true;
491 break;
492 case INTERNAL_ATTR_DOUBLE:
493 state = INATTR_DOUBLE;
494 break;
495 case INTERNAL_ATTR_SINGLE:
496 state = INATTR_SINGLE;
497 break;
498 case Token.MARKUP_PROCESSING_INSTRUCTION:
499 state = PI;
500 break;
501 case INTERNAL_INTAG:
502 state = INTAG;
503 break;
504 case Token.MARKUP_CDATA:
505 state = CDATA;
506 break;
507 default:
508 if (initialTokenType<-1024) { // INTERNAL_IN_XML_COMMENT - prevState
509 int main = -(-initialTokenType & 0xffffff00);
510 switch (main) {
511 default: // Should never happen
512 case INTERNAL_IN_XML_COMMENT:
513 state = COMMENT;
514 break;
515 }
516 prevState = -initialTokenType&0xff;
517 }
518 else { // Shouldn't happen
519 state = Token.NULL;
520 }
521 }
522
523 start = text.offset;
524 s = text;
525 try {
526 yyreset(zzReader);
527 yybegin(state);
528 return yylex();
529 } catch (IOException ioe) {
530 ioe.printStackTrace();
531 return new DefaultToken();
532 }
533
534 }
535
536
537 /**
538 * Sets whether markup close tags should be completed.
539 *
540 * @param complete Whether closing markup tags are completed.
541 * @see #getCompleteCloseTags()
542 */
543 public static void setCompleteCloseTags(boolean complete) {
544 completeCloseTags = complete;
545 }
546
547
548 /**
549 * Refills the input buffer.
550 *
551 * @return <code>true</code> if EOF was reached, otherwise
552 * <code>false</code>.
553 */
554 private boolean zzRefill() {
555 return zzCurrentPos>=s.offset+s.count;
556 }
557
558
559 /**
560 * Resets the scanner to read from a new input stream.
561 * Does not close the old reader.
562 *
563 * All internal variables are reset, the old input stream
564 * <b>cannot</b> be reused (internal buffer is discarded and lost).
565 * Lexical state is set to <tt>YY_INITIAL</tt>.
566 *
567 * @param reader the new input stream
568 */
569 public final void yyreset(java.io.Reader reader) {
570 // 's' has been updated.
571 zzBuffer = s.array;
572 /*
573 * We replaced the line below with the two below it because zzRefill
574 * no longer "refills" the buffer (since the way we do it, it's always
575 * "full" the first time through, since it points to the segment's
576 * array). So, we assign zzEndRead here.
577 */
578 //zzStartRead = zzEndRead = s.offset;
579 zzStartRead = s.offset;
580 zzEndRead = zzStartRead + s.count - 1;
581 zzCurrentPos = zzMarkedPos = s.offset;
582 zzLexicalState = YYINITIAL;
583 zzReader = reader;
584 zzAtEOF = false;
585 }
586
587
588
589
590 /**
591 * Creates a new scanner
592 * There is also a java.io.InputStream version of this constructor.
593 *
594 * @param in the java.io.Reader to read input from.
595 */
596 public XMLTokenMaker(java.io.Reader in) {
597 this.zzReader = in;
598 }
599
600 /**
601 * Creates a new scanner.
602 * There is also java.io.Reader version of this constructor.
603 *
604 * @param in the java.io.Inputstream to read input from.
605 */
606 public XMLTokenMaker(java.io.InputStream in) {
607 this(new java.io.InputStreamReader(in));
608 }
609
610 /**
611 * Unpacks the compressed character translation table.
612 *
613 * @param packed the packed character translation table
614 * @return the unpacked character translation table
615 */
616 private static char [] zzUnpackCMap(String packed) {
617 char [] map = new char[0x10000];
618 int i = 0; /* index in packed string */
619 int j = 0; /* index in unpacked array */
620 while (i < 116) {
621 int count = packed.charAt(i++);
622 char value = packed.charAt(i++);
623 do map[j++] = value; while (--count > 0);
624 }
625 return map;
626 }
627
628
629 /**
630 * Closes the input stream.
631 */
632 public final void yyclose() throws java.io.IOException {
633 zzAtEOF = true; /* indicate end of file */
634 zzEndRead = zzStartRead; /* invalidate buffer */
635
636 if (zzReader != null)
637 zzReader.close();
638 }
639
640
641 /**
642 * Returns the current lexical state.
643 */
644 public final int yystate() {
645 return zzLexicalState;
646 }
647
648
649 /**
650 * Enters a new lexical state
651 *
652 * @param newState the new lexical state
653 */
654 public final void yybegin(int newState) {
655 zzLexicalState = newState;
656 }
657
658
659 /**
660 * Returns the text matched by the current regular expression.
661 */
662 public final String yytext() {
663 return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
664 }
665
666
667 /**
668 * Returns the character at position <tt>pos</tt> from the
669 * matched text.
670 *
671 * It is equivalent to yytext().charAt(pos), but faster
672 *
673 * @param pos the position of the character to fetch.
674 * A value from 0 to yylength()-1.
675 *
676 * @return the character at position pos
677 */
678 public final char yycharat(int pos) {
679 return zzBuffer[zzStartRead+pos];
680 }
681
682
683 /**
684 * Returns the length of the matched text region.
685 */
686 public final int yylength() {
687 return zzMarkedPos-zzStartRead;
688 }
689
690
691 /**
692 * Reports an error that occured while scanning.
693 *
694 * In a wellformed scanner (no or only correct usage of
695 * yypushback(int) and a match-all fallback rule) this method
696 * will only be called with things that "Can't Possibly Happen".
697 * If this method is called, something is seriously wrong
698 * (e.g. a JFlex bug producing a faulty scanner etc.).
699 *
700 * Usual syntax/scanner level error handling should be done
701 * in error fallback rules.
702 *
703 * @param errorCode the code of the errormessage to display
704 */
705 private void zzScanError(int errorCode) {
706 String message;
707 try {
708 message = ZZ_ERROR_MSG[errorCode];
709 }
710 catch (ArrayIndexOutOfBoundsException e) {
711 message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
712 }
713
714 throw new Error(message);
715 }
716
717
718 /**
719 * Pushes the specified amount of characters back into the input stream.
720 *
721 * They will be read again by then next call of the scanning method
722 *
723 * @param number the number of characters to be read again.
724 * This number must not be greater than yylength()!
725 */
726 public void yypushback(int number) {
727 if ( number > yylength() )
728 zzScanError(ZZ_PUSHBACK_2BIG);
729
730 zzMarkedPos -= number;
731 }
732
733
734 /**
735 * Resumes scanning until the next regular expression is matched,
736 * the end of input is encountered or an I/O-Error occurs.
737 *
738 * @return the next token
739 * @exception java.io.IOException if any I/O-Error occurs
740 */
741 public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
742 int zzInput;
743 int zzAction;
744
745 // cached fields:
746 int zzCurrentPosL;
747 int zzMarkedPosL;
748 int zzEndReadL = zzEndRead;
749 char [] zzBufferL = zzBuffer;
750 char [] zzCMapL = ZZ_CMAP;
751
752 int [] zzTransL = ZZ_TRANS;
753 int [] zzRowMapL = ZZ_ROWMAP;
754 int [] zzAttrL = ZZ_ATTRIBUTE;
755
756 while (true) {
757 zzMarkedPosL = zzMarkedPos;
758
759 zzAction = -1;
760
761 zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
762
763 zzState = zzLexicalState;
764
765
766 zzForAction: {
767 while (true) {
768
769 if (zzCurrentPosL < zzEndReadL)
770 zzInput = zzBufferL[zzCurrentPosL++];
771 else if (zzAtEOF) {
772 zzInput = YYEOF;
773 break zzForAction;
774 }
775 else {
776 // store back cached positions
777 zzCurrentPos = zzCurrentPosL;
778 zzMarkedPos = zzMarkedPosL;
779 boolean eof = zzRefill();
780 // get translated positions and possibly new buffer
781 zzCurrentPosL = zzCurrentPos;
782 zzMarkedPosL = zzMarkedPos;
783 zzBufferL = zzBuffer;
784 zzEndReadL = zzEndRead;
785 if (eof) {
786 zzInput = YYEOF;
787 break zzForAction;
788 }
789 else {
790 zzInput = zzBufferL[zzCurrentPosL++];
791 }
792 }
793 int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
794 if (zzNext == -1) break zzForAction;
795 zzState = zzNext;
796
797 int zzAttributes = zzAttrL[zzState];
798 if ( (zzAttributes & 1) == 1 ) {
799 zzAction = zzState;
800 zzMarkedPosL = zzCurrentPosL;
801 if ( (zzAttributes & 8) == 8 ) break zzForAction;
802 }
803
804 }
805 }
806
807 // store back cached position
808 zzMarkedPos = zzMarkedPosL;
809
810 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
811 case 19:
812 { yybegin(INTAG); addToken(start,zzStartRead, Token.MARKUP_TAG_ATTRIBUTE_VALUE);
813 }
814 case 31: break;
815 case 3:
816 { addNullToken(); return firstToken;
817 }
818 case 32: break;
819 case 11:
820 { inInternalDtd = false;
821 }
822 case 33: break;
823 case 4:
824 { addToken(Token.MARKUP_TAG_DELIMITER); yybegin(INTAG);
825 }
826 case 34: break;
827 case 24:
828 { int count = yylength();
829 addToken(zzStartRead,zzStartRead+1, Token.MARKUP_TAG_DELIMITER);
830 addToken(zzMarkedPos-(count-2), zzMarkedPos-1, Token.MARKUP_TAG_NAME);
831 yybegin(INTAG);
832 }
833 case 35: break;
834 case 16:
835 { addToken(Token.MARKUP_TAG_DELIMITER); /* Not valid but we'll still accept it */
836 }
837 case 36: break;
838 case 5:
839 { addToken(Token.WHITESPACE);
840 }
841 case 37: break;
842 case 27:
843 { start = zzStartRead; prevState = zzLexicalState; yybegin(COMMENT);
844 }
845 case 38: break;
846 case 29:
847 { int temp = zzStartRead; addToken(start,zzStartRead-1, Token.FUNCTION); start = temp; prevState = zzLexicalState; yybegin(COMMENT);
848 }
849 case 39: break;
850 case 25:
851 { int temp = zzMarkedPos; addToken(start,zzStartRead+2, Token.COMMENT_MULTILINE); start = temp; yybegin(prevState);
852 }
853 case 40: break;
854 case 2:
855 { addToken(Token.IDENTIFIER);
856 }
857 case 41: break;
858 case 9:
859 { addToken(start,zzStartRead-1, Token.FUNCTION); addEndToken(inInternalDtd ? INTERNAL_DTD_INTERNAL : INTERNAL_DTD); return firstToken;
860 }
861 case 42: break;
862 case 10:
863 { inInternalDtd = true;
864 }
865 case 43: break;
866 case 30:
867 { addToken(Token.DATA_TYPE); start = zzMarkedPos; yybegin(CDATA);
868 }
869 case 44: break;
870 case 6:
871 { addToken(Token.DATA_TYPE);
872 }
873 case 45: break;
874 case 23:
875 { yybegin(YYINITIAL); addToken(start,zzStartRead+1, Token.MARKUP_PROCESSING_INSTRUCTION);
876 }
877 case 46: break;
878 case 21:
879 { start = zzMarkedPos-2; inInternalDtd = false; yybegin(DTD);
880 }
881 case 47: break;
882 case 20:
883 { int count = yylength();
884 addToken(zzStartRead,zzStartRead, Token.MARKUP_TAG_DELIMITER);
885 addToken(zzMarkedPos-(count-1), zzMarkedPos-1, Token.MARKUP_TAG_NAME);
886 yybegin(INTAG);
887 }
888 case 48: break;
889 case 22:
890 { start = zzMarkedPos-2; yybegin(PI);
891 }
892 case 49: break;
893 case 8:
894 { addToken(start,zzStartRead-1, Token.MARKUP_PROCESSING_INSTRUCTION); return firstToken;
895 }
896 case 50: break;
897 case 14:
898 { start = zzMarkedPos-1; yybegin(INATTR_DOUBLE);
899 }
900 case 51: break;
901 case 15:
902 { yybegin(YYINITIAL); addToken(Token.MARKUP_TAG_DELIMITER);
903 }
904 case 52: break;
905 case 12:
906 { if (!inInternalDtd) { yybegin(YYINITIAL); addToken(start,zzStartRead, Token.FUNCTION); }
907 }
908 case 53: break;
909 case 17:
910 { start = zzMarkedPos-1; yybegin(INATTR_SINGLE);
911 }
912 case 54: break;
913 case 28:
914 { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_MULTILINE); start = zzMarkedPos;
915 }
916 case 55: break;
917 case 26:
918 { int temp=zzStartRead; yybegin(YYINITIAL); addToken(start,zzStartRead-1, Token.MARKUP_CDATA); addToken(temp,zzMarkedPos-1, Token.DATA_TYPE);
919 }
920 case 56: break;
921 case 18:
922 { addToken(Token.OPERATOR);
923 }
924 case 57: break;
925 case 7:
926 { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addEndToken(INTERNAL_IN_XML_COMMENT - prevState); return firstToken;
927 }
928 case 58: break;
929 case 13:
930 { addToken(Token.MARKUP_TAG_ATTRIBUTE);
931 }
932 case 59: break;
933 case 1:
934 {
935 }
936 case 60: break;
937 default:
938 if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
939 zzAtEOF = true;
940 switch (zzLexicalState) {
941 case INTAG: {
942 addToken(start,zzStartRead-1, INTERNAL_INTAG); return firstToken;
943 }
944 case 78: break;
945 case DTD: {
946 addToken(start,zzStartRead-1, Token.FUNCTION); addEndToken(inInternalDtd ? INTERNAL_DTD_INTERNAL : INTERNAL_DTD); return firstToken;
947 }
948 case 79: break;
949 case INATTR_DOUBLE: {
950 addToken(start,zzStartRead-1, Token.MARKUP_TAG_ATTRIBUTE_VALUE); addEndToken(INTERNAL_ATTR_DOUBLE); return firstToken;
951 }
952 case 80: break;
953 case YYINITIAL: {
954 addNullToken(); return firstToken;
955 }
956 case 81: break;
957 case COMMENT: {
958 addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addEndToken(INTERNAL_IN_XML_COMMENT - prevState); return firstToken;
959 }
960 case 82: break;
961 case CDATA: {
962 addToken(start,zzStartRead-1, Token.MARKUP_CDATA); return firstToken;
963 }
964 case 83: break;
965 case INATTR_SINGLE: {
966 addToken(start,zzStartRead-1, Token.MARKUP_TAG_ATTRIBUTE_VALUE); addEndToken(INTERNAL_ATTR_SINGLE); return firstToken;
967 }
968 case 84: break;
969 case PI: {
970 addToken(start,zzStartRead-1, Token.MARKUP_PROCESSING_INSTRUCTION); return firstToken;
971 }
972 case 85: break;
973 default:
974 return null;
975 }
976 }
977 else {
978 zzScanError(ZZ_NO_MATCH);
979 }
980 }
981 }
982 }
983
984
985}
Note: See TracBrowser for help on using the repository browser.