4
* LispTokenMaker.java - Scanner for the Lisp programming language.
6
* This library is distributed under a modified BSD license. See the included
7
* RSyntaxTextArea.License.txt file for details.
9
package org.fife.ui.rsyntaxtextarea.modes;
12
import javax.swing.text.Segment;
14
import org.fife.ui.rsyntaxtextarea.*;
18
* Scanner for the Lisp programming language.<p>
20
* This implementation was created using
21
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
22
* was modified for performance. Memory allocation needs to be almost
23
* completely removed to be competitive with the handwritten lexers (subclasses
24
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
25
* Strings are never allocated (via yytext()), and the scanner never has to
26
* worry about refilling its buffer (needlessly copying chars around).
27
* We can achieve this because RText always scans exactly 1 line of tokens at a
28
* time, and hands the scanner this line as an array of characters (a Segment
29
* really). Since tokens contain pointers to char arrays instead of Strings
30
* holding their contents, there is no need for allocating new memory for
33
* The actual algorithm generated for scanning has, of course, not been
36
* If you wish to regenerate this file yourself, keep in mind the following:
38
* <li>The generated LispTokenMaker.java</code> file will contain two
39
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
40
* You should hand-delete the second of each definition (the ones
41
* generated by the lexer), as these generated methods modify the input
42
* buffer, which we'll never have to do.</li>
43
* <li>You should also change the declaration/definition of zzBuffer to NOT
44
* be initialized. This is a needless memory allocation for us since we
45
* will be pointing the array somewhere else anyway.</li>
46
* <li>You should NOT call <code>yylex()</code> on the generated scanner
47
* directly; rather, you should use <code>getTokenList</code> as you would
48
* with any other <code>TokenMaker</code> instance.</li>
51
* @author Robert Futrell
59
%extends AbstractJFlexTokenMaker
61
%type org.fife.ui.rsyntaxtextarea.Token
68
* Constructor. This must be here because JFlex does not generate a
69
* no-parameter constructor.
71
public LispTokenMaker() {
76
* Adds the token specified to the current linked list of tokens.
78
* @param tokenType The token's type.
79
* @see #addToken(int, int, int)
81
private void addHyperlinkToken(int start, int end, int tokenType) {
82
int so = start + offsetShift;
83
addToken(zzBuffer, start,end, tokenType, so, true);
88
* Adds the token specified to the current linked list of tokens.
90
* @param tokenType The token's type.
92
private void addToken(int tokenType) {
93
addToken(zzStartRead, zzMarkedPos-1, tokenType);
98
* Adds the token specified to the current linked list of tokens.
100
* @param tokenType The token's type.
101
* @see #addHyperlinkToken(int, int, int)
103
private void addToken(int start, int end, int tokenType) {
104
int so = start + offsetShift;
105
addToken(zzBuffer, start,end, tokenType, so, false);
110
* Adds the token specified to the current linked list of tokens.
112
* @param array The character array.
113
* @param start The starting offset in the array.
114
* @param end The ending offset in the array.
115
* @param tokenType The token's type.
116
* @param startOffset The offset in the document at which this token
118
* @param hyperlink Whether this token is a hyperlink.
121
public void addToken(char[] array, int start, int end, int tokenType,
122
int startOffset, boolean hyperlink) {
123
super.addToken(array, start,end, tokenType, startOffset, hyperlink);
124
zzStartRead = zzMarkedPos;
129
* Returns the text to place at the beginning and end of a
130
* line to "comment" it in a this programming language.
132
* @return The start and end strings to add to a line to "comment"
136
public String[] getLineCommentStartAndEnd() {
137
return new String[] { ";", null };
142
* Returns the first token in the linked list of tokens generated
143
* from <code>text</code>. This method must be implemented by
144
* subclasses so they can correctly implement syntax highlighting.
146
* @param text The text from which to get tokens.
147
* @param initialTokenType The token type we should start with.
148
* @param startOffset The offset into the document at which
149
* <code>text</code> starts.
150
* @return The first <code>Token</code> in a linked list representing
151
* the syntax highlighted text.
153
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
156
this.offsetShift = -text.offset + startOffset;
158
// Start off in the proper state.
159
int state = Token.NULL;
160
switch (initialTokenType) {
161
case Token.COMMENT_MULTILINE:
165
case Token.LITERAL_STRING_DOUBLE_QUOTE:
178
} catch (IOException ioe) {
179
ioe.printStackTrace();
180
return new TokenImpl();
187
* Refills the input buffer.
189
* @return <code>true</code> if EOF was reached, otherwise
190
* <code>false</code>.
191
* @exception IOException if any I/O-Error occurs.
193
private boolean zzRefill() throws java.io.IOException {
194
return zzCurrentPos>=s.offset+s.count;
199
* Resets the scanner to read from a new input stream.
200
* Does not close the old reader.
202
* All internal variables are reset, the old input stream
203
* <b>cannot</b> be reused (internal buffer is discarded and lost).
204
* Lexical state is set to <tt>YY_INITIAL</tt>.
206
* @param reader the new input stream
208
public final void yyreset(java.io.Reader reader) throws java.io.IOException {
209
// 's' has been updated.
212
* We replaced the line below with the two below it because zzRefill
213
* no longer "refills" the buffer (since the way we do it, it's always
214
* "full" the first time through, since it points to the segment's
215
* array). So, we assign zzEndRead here.
217
//zzStartRead = zzEndRead = s.offset;
218
zzStartRead = s.offset;
219
zzEndRead = zzStartRead + s.count - 1;
220
zzCurrentPos = zzMarkedPos = zzPushbackPos = s.offset;
221
zzLexicalState = YYINITIAL;
231
LetterOrUnderscore = ({Letter}|"_")
233
Digit = ("0"|{NonzeroDigit})
234
HexDigit = ({Digit}|[A-Fa-f])
236
EscapedSourceCharacter = ("u"{HexDigit}{HexDigit}{HexDigit}{HexDigit})
237
NonSeparator = ([^\t\f\r\n\ \(\)\{\}\[\]\;\,\.\=\>\<\!\~\?\:\+\-\*\/\&\|\^\%\"\']|"#"|"\\")
238
IdentifierStart = ({LetterOrUnderscore}|"$")
239
IdentifierPart = ({IdentifierStart}|{Digit}|("\\"{EscapedSourceCharacter}))
241
LineTerminator = (\n)
242
WhiteSpace = ([ \t\f])
246
LineCommentBegin = ";"
248
IntegerHelper1 = (({NonzeroDigit}{Digit}*)|"0")
249
IntegerHelper2 = ("0"(([xX]{HexDigit}+)|({OctalDigit}*)))
250
IntegerLiteral = ({IntegerHelper1}[lL]?)
251
HexLiteral = ({IntegerHelper2}[lL]?)
252
FloatHelper1 = ([fFdD]?)
253
FloatHelper2 = ([eE][+-]?{Digit}+{FloatHelper1})
254
FloatLiteral1 = ({Digit}+"."({FloatHelper1}|{FloatHelper2}|{Digit}+({FloatHelper1}|{FloatHelper2})))
255
FloatLiteral2 = ("."{Digit}+({FloatHelper1}|{FloatHelper2}))
256
FloatLiteral3 = ({Digit}+{FloatHelper2})
257
FloatLiteral = ({FloatLiteral1}|{FloatLiteral2}|{FloatLiteral3}|({Digit}+[fFdD]))
258
ErrorNumberFormat = (({IntegerLiteral}|{HexLiteral}|{FloatLiteral}){NonSeparator}+)
262
NonAssignmentOperator = ("+"|"-"|"<="|"^"|"++"|"<"|"*"|">="|"%"|"--"|">"|"/"|"!="|"?"|">>"|"!"|"&"|"=="|":"|">>"|"~"|"|"|"&&"|">>>")
263
AssignmentOperator = ("="|"-="|"*="|"/="|"|="|"&="|"^="|"+="|"%="|"<<="|">>="|">>>=")
264
Operator = ({NonAssignmentOperator}|{AssignmentOperator})
266
Identifier = ({IdentifierStart}{IdentifierPart}*)
267
ErrorIdentifier = ({NonSeparator}+)
269
URLGenDelim = ([:\/\?#\[\]@])
270
URLSubDelim = ([\!\$&'\(\)\*\+,;=])
271
URLUnreserved = ({LetterOrUnderscore}|{Digit}|[\-\.\~])
272
URLCharacter = ({URLGenDelim}|{URLSubDelim}|{URLUnreserved}|[%])
273
URLCharacters = ({URLCharacter}*)
274
URLEndCharacter = ([\/\$]|{Letter}|{Digit})
275
URL = (((https?|f(tp|ile))"://"|"www.")({URLCharacters}{URLEndCharacter})?)
289
"define-compiler-macro" |
291
"define-method-combination" |
292
"define-modify-macro" |
293
"define-setf-expander" |
294
"define-symbol-macro" |
303
"defvar" { addToken(Token.RESERVED_WORD); }
320
"do-external-symbols" |
341
"multiple-value-bind" |
366
"with-compilation-unit" |
367
"with-condition-restarts" |
368
"with-hash-table-iterator" |
369
"with-input-from-string" |
372
"with-output-to-string" |
373
"with-package-iterator" |
374
"with-simple-restart" |
376
"with-standard-io-syntax" { addToken(Token.RESERVED_WORD); }
378
{LineTerminator} { addNullToken(); return firstToken; }
379
{Identifier} { addToken(Token.IDENTIFIER); }
380
{WhiteSpace}+ { addToken(Token.WHITESPACE); }
381
[\"] { start = zzMarkedPos-1; yybegin(STRING); }
382
{MLCBegin} { start = zzMarkedPos-2; yybegin(MLC); }
383
{LineCommentBegin} { start = zzMarkedPos-1; yybegin(EOL_COMMENT); }
384
{Separator} { addToken(Token.SEPARATOR); }
385
{Operator} { addToken(Token.OPERATOR); }
388
{IntegerLiteral} { addToken(Token.LITERAL_NUMBER_DECIMAL_INT); }
389
{HexLiteral} { addToken(Token.LITERAL_NUMBER_HEXADECIMAL); }
390
{FloatLiteral} { addToken(Token.LITERAL_NUMBER_FLOAT); }
391
{ErrorNumberFormat} { addToken(Token.ERROR_NUMBER_FORMAT); }
393
{ErrorIdentifier} { addToken(Token.ERROR_IDENTIFIER); }
395
/* Ended with a line not in a string or comment. */
396
<<EOF>> { addNullToken(); return firstToken; }
398
/* Catch any other (unhandled) characters and flag them as bad. */
399
. { addToken(Token.ERROR_IDENTIFIER); }
406
\n { addToken(start,zzStartRead-1, Token.LITERAL_STRING_DOUBLE_QUOTE); return firstToken; }
407
\\.? { /* Skip escaped chars. */ }
408
\" { yybegin(YYINITIAL); addToken(start,zzStartRead, Token.LITERAL_STRING_DOUBLE_QUOTE); }
409
<<EOF>> { addToken(start,zzStartRead-1, Token.LITERAL_STRING_DOUBLE_QUOTE); return firstToken; }
416
{URL} { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_MULTILINE); start = zzMarkedPos; }
419
\n { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); return firstToken; }
420
{MLCEnd} { yybegin(YYINITIAL); addToken(start,zzStartRead+1, Token.COMMENT_MULTILINE); }
422
<<EOF>> { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); return firstToken; }
429
{URL} { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_EOL); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_EOL); start = zzMarkedPos; }
431
\n { addToken(start,zzStartRead-1, Token.COMMENT_EOL); addNullToken(); return firstToken; }
432
<<EOF>> { addToken(start,zzStartRead-1, Token.COMMENT_EOL); addNullToken(); return firstToken; }