1
/* The following code was generated by JFlex 1.4.1 on 4/28/12 4:57 PM */
6
* LatexTokenMaker.java - Scanner for LaTeX.
8
* This library is distributed under a modified BSD license. See the included
9
* RSyntaxTextArea.License.txt file for details.
11
package org.fife.ui.rsyntaxtextarea.modes;
14
import javax.swing.text.Segment;
16
import org.fife.ui.rsyntaxtextarea.*;
20
* Scanner for the LaTeX.<p>
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
35
* The actual algorithm generated for scanning has, of course, not been
38
* If you wish to regenerate this file yourself, keep in mind the following:
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>
53
* @author Robert Futrell
58
public class LatexTokenMaker extends AbstractJFlexTokenMaker {
60
/** This character denotes the end of file */
61
public static final int YYEOF = -1;
64
public static final int EOL_COMMENT = 1;
65
public static final int YYINITIAL = 0;
68
* Translates characters to character classes
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";
79
* Translates characters to character classes
81
private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
84
* Translates DFA states to action switch labels.
86
private static final int [] ZZ_ACTION = zzUnpackAction();
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";
93
private static int [] zzUnpackAction() {
94
int [] result = new int[42];
96
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
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();
105
int count = packed.charAt(i++);
106
int value = packed.charAt(i++);
107
do result[j++] = value; while (--count > 0);
114
* Translates a state to a row index in the transition table
116
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
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"+
126
private static int [] zzUnpackRowMap() {
127
int [] result = new int[42];
129
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
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();
138
int high = packed.charAt(i++) << 16;
139
result[j++] = high | packed.charAt(i++);
145
* The transition table of the DFA
147
private static final int [] ZZ_TRANS = zzUnpackTrans();
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";
181
private static int [] zzUnpackTrans() {
182
int [] result = new int[918];
184
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
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();
193
int count = packed.charAt(i++);
194
int value = packed.charAt(i++);
196
do result[j++] = value; while (--count > 0);
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;
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"
215
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
217
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
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";
224
private static int [] zzUnpackAttribute() {
225
int [] result = new int[42];
227
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
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();
236
int count = packed.charAt(i++);
237
int value = packed.charAt(i++);
238
do result[j++] = value; while (--count > 0);
243
/** the input device */
244
private java.io.Reader zzReader;
246
/** the current state of the DFA */
249
/** the current lexical state */
250
private int zzLexicalState = YYINITIAL;
252
/** this buffer contains the current text to be matched and is
253
the source of the yytext() string */
254
private char zzBuffer[];
256
/** the textposition at the last accepting state */
257
private int zzMarkedPos;
259
/** the current text position in the buffer */
260
private int zzCurrentPos;
262
/** startRead marks the beginning of the yytext() string in the buffer */
263
private int zzStartRead;
265
/** endRead marks the last character in the buffer, that has been read
267
private int zzEndRead;
269
/** zzAtEOF == true <=> the scanner is at the EOF */
270
private boolean zzAtEOF;
276
* Constructor. This must be here because JFlex does not generate a
277
* no-parameter constructor.
279
public LatexTokenMaker() {
284
* Adds the token specified to the current linked list of tokens.
286
* @param tokenType The token's type.
287
* @see #addToken(int, int, int)
289
private void addHyperlinkToken(int start, int end, int tokenType) {
290
int so = start + offsetShift;
291
addToken(zzBuffer, start,end, tokenType, so, true);
296
* Adds the token specified to the current linked list of tokens.
298
* @param tokenType The token's type.
300
private void addToken(int tokenType) {
301
addToken(zzStartRead, zzMarkedPos-1, tokenType);
306
* Adds the token specified to the current linked list of tokens.
308
* @param tokenType The token's type.
309
* @see #addHyperlinkToken(int, int, int)
311
private void addToken(int start, int end, int tokenType) {
312
int so = start + offsetShift;
313
addToken(zzBuffer, start,end, tokenType, so, false);
318
* Adds the token specified to the current linked list of tokens.
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
326
* @param hyperlink Whether this token is a hyperlink.
329
public void addToken(char[] array, int start, int end, int tokenType,
330
int startOffset, boolean hyperlink) {
331
super.addToken(array, start,end, tokenType, startOffset, hyperlink);
332
zzStartRead = zzMarkedPos;
340
public String[] getLineCommentStartAndEnd() {
341
return new String[] { "%", null };
346
* Returns the first token in the linked list of tokens generated
347
* from <code>text</code>. This method must be implemented by
348
* subclasses so they can correctly implement syntax highlighting.
350
* @param text The text from which to get tokens.
351
* @param initialTokenType The token type we should start with.
352
* @param startOffset The offset into the document at which
353
* <code>text</code> starts.
354
* @return The first <code>Token</code> in a linked list representing
355
* the syntax highlighted text.
357
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
360
this.offsetShift = -text.offset + startOffset;
362
// Start off in the proper state.
363
int state = Token.NULL;
370
} catch (IOException ioe) {
371
ioe.printStackTrace();
372
return new TokenImpl();
379
* Refills the input buffer.
381
* @return <code>true</code> if EOF was reached, otherwise
382
* <code>false</code>.
383
* @exception IOException if any I/O-Error occurs.
385
private boolean zzRefill() {
386
return zzCurrentPos>=s.offset+s.count;
391
* Resets the scanner to read from a new input stream.
392
* Does not close the old reader.
394
* All internal variables are reset, the old input stream
395
* <b>cannot</b> be reused (internal buffer is discarded and lost).
396
* Lexical state is set to <tt>YY_INITIAL</tt>.
398
* @param reader the new input stream
400
public final void yyreset(java.io.Reader reader) {
401
// 's' has been updated.
404
* We replaced the line below with the two below it because zzRefill
405
* no longer "refills" the buffer (since the way we do it, it's always
406
* "full" the first time through, since it points to the segment's
407
* array). So, we assign zzEndRead here.
409
//zzStartRead = zzEndRead = s.offset;
410
zzStartRead = s.offset;
411
zzEndRead = zzStartRead + s.count - 1;
412
zzCurrentPos = zzMarkedPos = s.offset;
413
zzLexicalState = YYINITIAL;
422
* Creates a new scanner
423
* There is also a java.io.InputStream version of this constructor.
425
* @param in the java.io.Reader to read input from.
427
public LatexTokenMaker(java.io.Reader in) {
432
* Creates a new scanner.
433
* There is also java.io.Reader version of this constructor.
435
* @param in the java.io.Inputstream to read input from.
437
public LatexTokenMaker(java.io.InputStream in) {
438
this(new java.io.InputStreamReader(in));
442
* Unpacks the compressed character translation table.
444
* @param packed the packed character translation table
445
* @return the unpacked character translation table
447
private static char [] zzUnpackCMap(String packed) {
448
char [] map = new char[0x10000];
449
int i = 0; /* index in packed string */
450
int j = 0; /* index in unpacked array */
452
int count = packed.charAt(i++);
453
char value = packed.charAt(i++);
454
do map[j++] = value; while (--count > 0);
461
* Closes the input stream.
463
public final void yyclose() throws java.io.IOException {
464
zzAtEOF = true; /* indicate end of file */
465
zzEndRead = zzStartRead; /* invalidate buffer */
467
if (zzReader != null)
473
* Returns the current lexical state.
475
public final int yystate() {
476
return zzLexicalState;
481
* Enters a new lexical state
483
* @param newState the new lexical state
486
public final void yybegin(int newState) {
487
zzLexicalState = newState;
492
* Returns the text matched by the current regular expression.
494
public final String yytext() {
495
return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
500
* Returns the character at position <tt>pos</tt> from the
503
* It is equivalent to yytext().charAt(pos), but faster
505
* @param pos the position of the character to fetch.
506
* A value from 0 to yylength()-1.
508
* @return the character at position pos
510
public final char yycharat(int pos) {
511
return zzBuffer[zzStartRead+pos];
516
* Returns the length of the matched text region.
518
public final int yylength() {
519
return zzMarkedPos-zzStartRead;
524
* Reports an error that occured while scanning.
526
* In a wellformed scanner (no or only correct usage of
527
* yypushback(int) and a match-all fallback rule) this method
528
* will only be called with things that "Can't Possibly Happen".
529
* If this method is called, something is seriously wrong
530
* (e.g. a JFlex bug producing a faulty scanner etc.).
532
* Usual syntax/scanner level error handling should be done
533
* in error fallback rules.
535
* @param errorCode the code of the errormessage to display
537
private void zzScanError(int errorCode) {
540
message = ZZ_ERROR_MSG[errorCode];
542
catch (ArrayIndexOutOfBoundsException e) {
543
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
546
throw new Error(message);
551
* Pushes the specified amount of characters back into the input stream.
553
* They will be read again by then next call of the scanning method
555
* @param number the number of characters to be read again.
556
* This number must not be greater than yylength()!
558
public void yypushback(int number) {
559
if ( number > yylength() )
560
zzScanError(ZZ_PUSHBACK_2BIG);
562
zzMarkedPos -= number;
567
* Resumes scanning until the next regular expression is matched,
568
* the end of input is encountered or an I/O-Error occurs.
570
* @return the next token
571
* @exception java.io.IOException if any I/O-Error occurs
573
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
580
int zzEndReadL = zzEndRead;
581
char [] zzBufferL = zzBuffer;
582
char [] zzCMapL = ZZ_CMAP;
584
int [] zzTransL = ZZ_TRANS;
585
int [] zzRowMapL = ZZ_ROWMAP;
586
int [] zzAttrL = ZZ_ATTRIBUTE;
589
zzMarkedPosL = zzMarkedPos;
593
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
595
zzState = zzLexicalState;
601
if (zzCurrentPosL < zzEndReadL)
602
zzInput = zzBufferL[zzCurrentPosL++];
608
// store back cached positions
609
zzCurrentPos = zzCurrentPosL;
610
zzMarkedPos = zzMarkedPosL;
611
boolean eof = zzRefill();
612
// get translated positions and possibly new buffer
613
zzCurrentPosL = zzCurrentPos;
614
zzMarkedPosL = zzMarkedPos;
615
zzBufferL = zzBuffer;
616
zzEndReadL = zzEndRead;
622
zzInput = zzBufferL[zzCurrentPosL++];
625
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
626
if (zzNext == -1) break zzForAction;
629
int zzAttributes = zzAttrL[zzState];
630
if ( (zzAttributes & 1) == 1 ) {
632
zzMarkedPosL = zzCurrentPosL;
633
if ( (zzAttributes & 8) == 8 ) break zzForAction;
639
// store back cached position
640
zzMarkedPos = zzMarkedPosL;
642
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
644
{ addToken(Token.IDENTIFIER);
648
{ addToken(Token.FUNCTION);
652
{ addToken(Token.WHITESPACE);
656
{ int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_EOL); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_EOL); start = zzMarkedPos;
660
{ start = zzMarkedPos-1; yybegin(EOL_COMMENT);
664
{ addNullToken(); return firstToken;
668
{ addToken(start,zzStartRead-1, Token.COMMENT_EOL); addNullToken(); return firstToken;
672
{ int temp = zzStartRead;
673
addToken(temp, temp+3, Token.RESERVED_WORD);
674
addToken(temp+4, temp+4, Token.SEPARATOR);
675
addToken(temp+5, zzMarkedPos-2, Token.RESERVED_WORD);
676
addToken(zzMarkedPos-1, zzMarkedPos-1, Token.SEPARATOR);
680
{ int temp = zzStartRead;
681
addToken(temp, temp+5, Token.RESERVED_WORD);
682
addToken(temp+6, temp+6, Token.SEPARATOR);
683
addToken(temp+7, zzMarkedPos-2, Token.RESERVED_WORD);
684
addToken(zzMarkedPos-1, zzMarkedPos-1, Token.SEPARATOR);
692
{ addToken(Token.SEPARATOR);
696
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
698
switch (zzLexicalState) {
700
addToken(start,zzStartRead-1, Token.COMMENT_EOL); addNullToken(); return firstToken;
704
addNullToken(); return firstToken;
712
zzScanError(ZZ_NO_MATCH);