~ubuntu-branches/ubuntu/trusty/drmips/trusty-backports

« back to all changes in this revision

Viewing changes to src/pc/DrMIPS/src/org/fife/ui/rsyntaxtextarea/modes/LispTokenMaker.flex

  • Committer: Package Import Robot
  • Author(s): Bruno Nova
  • Date: 2014-09-27 12:24:17 UTC
  • Revision ID: package-import@ubuntu.com-20140927122417-2gadkwt9k0u7j4zu
Tags: upstream-1.2.3
Import upstream version 1.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * 11/13/2004
 
3
 *
 
4
 * LispTokenMaker.java - Scanner for the Lisp programming language.
 
5
 * 
 
6
 * This library is distributed under a modified BSD license.  See the included
 
7
 * RSyntaxTextArea.License.txt file for details.
 
8
 */
 
9
package org.fife.ui.rsyntaxtextarea.modes;
 
10
 
 
11
import java.io.*;
 
12
import javax.swing.text.Segment;
 
13
 
 
14
import org.fife.ui.rsyntaxtextarea.*;
 
15
 
 
16
 
 
17
/**
 
18
 * Scanner for the Lisp programming language.<p>
 
19
 *
 
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
 
31
 * Strings.<p>
 
32
 *
 
33
 * The actual algorithm generated for scanning has, of course, not been
 
34
 * modified.<p>
 
35
 *
 
36
 * If you wish to regenerate this file yourself, keep in mind the following:
 
37
 * <ul>
 
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>
 
49
 * </ul>
 
50
 *
 
51
 * @author Robert Futrell
 
52
 * @version 0.5
 
53
 *
 
54
 */
 
55
%%
 
56
 
 
57
%public
 
58
%class LispTokenMaker
 
59
%extends AbstractJFlexTokenMaker
 
60
%unicode
 
61
%type org.fife.ui.rsyntaxtextarea.Token
 
62
 
 
63
 
 
64
%{
 
65
 
 
66
 
 
67
        /**
 
68
         * Constructor.  This must be here because JFlex does not generate a
 
69
         * no-parameter constructor.
 
70
         */
 
71
        public LispTokenMaker() {
 
72
        }
 
73
 
 
74
 
 
75
        /**
 
76
         * Adds the token specified to the current linked list of tokens.
 
77
         *
 
78
         * @param tokenType The token's type.
 
79
         * @see #addToken(int, int, int)
 
80
         */
 
81
        private void addHyperlinkToken(int start, int end, int tokenType) {
 
82
                int so = start + offsetShift;
 
83
                addToken(zzBuffer, start,end, tokenType, so, true);
 
84
        }
 
85
 
 
86
 
 
87
        /**
 
88
         * Adds the token specified to the current linked list of tokens.
 
89
         *
 
90
         * @param tokenType The token's type.
 
91
         */
 
92
        private void addToken(int tokenType) {
 
93
                addToken(zzStartRead, zzMarkedPos-1, tokenType);
 
94
        }
 
95
 
 
96
 
 
97
        /**
 
98
         * Adds the token specified to the current linked list of tokens.
 
99
         *
 
100
         * @param tokenType The token's type.
 
101
         * @see #addHyperlinkToken(int, int, int)
 
102
         */
 
103
        private void addToken(int start, int end, int tokenType) {
 
104
                int so = start + offsetShift;
 
105
                addToken(zzBuffer, start,end, tokenType, so, false);
 
106
        }
 
107
 
 
108
 
 
109
        /**
 
110
         * Adds the token specified to the current linked list of tokens.
 
111
         *
 
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
 
117
         *                    occurs.
 
118
         * @param hyperlink Whether this token is a hyperlink.
 
119
         */
 
120
        @Override
 
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;
 
125
        }
 
126
 
 
127
 
 
128
        /**
 
129
         * Returns the text to place at the beginning and end of a
 
130
         * line to "comment" it in a this programming language.
 
131
         *
 
132
         * @return The start and end strings to add to a line to "comment"
 
133
         *         it out.
 
134
         */
 
135
        @Override
 
136
        public String[] getLineCommentStartAndEnd() {
 
137
                return new String[] { ";", null };
 
138
        }
 
139
 
 
140
 
 
141
        /**
 
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.
 
145
         *
 
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.
 
152
         */
 
153
        public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
 
154
 
 
155
                resetTokenList();
 
156
                this.offsetShift = -text.offset + startOffset;
 
157
 
 
158
                // Start off in the proper state.
 
159
                int state = Token.NULL;
 
160
                switch (initialTokenType) {
 
161
                        case Token.COMMENT_MULTILINE:
 
162
                                state = MLC;
 
163
                                start = text.offset;
 
164
                                break;
 
165
                        case Token.LITERAL_STRING_DOUBLE_QUOTE:
 
166
                                state = STRING;
 
167
                                start = text.offset;
 
168
                                break;
 
169
                        default:
 
170
                                state = Token.NULL;
 
171
                }
 
172
 
 
173
                s = text;
 
174
                try {
 
175
                        yyreset(zzReader);
 
176
                        yybegin(state);
 
177
                        return yylex();
 
178
                } catch (IOException ioe) {
 
179
                        ioe.printStackTrace();
 
180
                        return new TokenImpl();
 
181
                }
 
182
 
 
183
        }
 
184
 
 
185
 
 
186
        /**
 
187
         * Refills the input buffer.
 
188
         *
 
189
         * @return      <code>true</code> if EOF was reached, otherwise
 
190
         *              <code>false</code>.
 
191
         * @exception   IOException  if any I/O-Error occurs.
 
192
         */
 
193
        private boolean zzRefill() throws java.io.IOException {
 
194
                return zzCurrentPos>=s.offset+s.count;
 
195
        }
 
196
 
 
197
 
 
198
        /**
 
199
         * Resets the scanner to read from a new input stream.
 
200
         * Does not close the old reader.
 
201
         *
 
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>.
 
205
         *
 
206
         * @param reader   the new input stream 
 
207
         */
 
208
        public final void yyreset(java.io.Reader reader) throws java.io.IOException {
 
209
                // 's' has been updated.
 
210
                zzBuffer = s.array;
 
211
                /*
 
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.
 
216
                 */
 
217
                //zzStartRead = zzEndRead = s.offset;
 
218
                zzStartRead = s.offset;
 
219
                zzEndRead = zzStartRead + s.count - 1;
 
220
                zzCurrentPos = zzMarkedPos = zzPushbackPos = s.offset;
 
221
                zzLexicalState = YYINITIAL;
 
222
                zzReader = reader;
 
223
                zzAtBOL  = true;
 
224
                zzAtEOF  = false;
 
225
        }
 
226
 
 
227
 
 
228
%}
 
229
 
 
230
Letter                                                  = [A-Za-z]
 
231
LetterOrUnderscore                              = ({Letter}|"_")
 
232
NonzeroDigit                                            = [1-9]
 
233
Digit                                                   = ("0"|{NonzeroDigit})
 
234
HexDigit                                                        = ({Digit}|[A-Fa-f])
 
235
OctalDigit                                              = ([0-7])
 
236
EscapedSourceCharacter                          = ("u"{HexDigit}{HexDigit}{HexDigit}{HexDigit})
 
237
NonSeparator                                            = ([^\t\f\r\n\ \(\)\{\}\[\]\;\,\.\=\>\<\!\~\?\:\+\-\*\/\&\|\^\%\"\']|"#"|"\\")
 
238
IdentifierStart                                 = ({LetterOrUnderscore}|"$")
 
239
IdentifierPart                                          = ({IdentifierStart}|{Digit}|("\\"{EscapedSourceCharacter}))
 
240
 
 
241
LineTerminator                          = (\n)
 
242
WhiteSpace                              = ([ \t\f])
 
243
 
 
244
MLCBegin                                        = "#|"
 
245
MLCEnd                                  = "|#"
 
246
LineCommentBegin                        = ";"
 
247
 
 
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}+)
 
259
 
 
260
Separator                                       = ([\(\)])
 
261
 
 
262
NonAssignmentOperator           = ("+"|"-"|"<="|"^"|"++"|"<"|"*"|">="|"%"|"--"|">"|"/"|"!="|"?"|">>"|"!"|"&"|"=="|":"|">>"|"~"|"|"|"&&"|">>>")
 
263
AssignmentOperator                      = ("="|"-="|"*="|"/="|"|="|"&="|"^="|"+="|"%="|"<<="|">>="|">>>=")
 
264
Operator                                        = ({NonAssignmentOperator}|{AssignmentOperator})
 
265
 
 
266
Identifier                              = ({IdentifierStart}{IdentifierPart}*)
 
267
ErrorIdentifier                 = ({NonSeparator}+)
 
268
 
 
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})?)
 
276
 
 
277
 
 
278
%state STRING
 
279
%state MLC
 
280
%state EOL_COMMENT
 
281
 
 
282
%%
 
283
 
 
284
<YYINITIAL> {
 
285
 
 
286
        "defclass" |
 
287
        "defconstant" |
 
288
        "defgeneric" |
 
289
        "define-compiler-macro" |
 
290
        "define-condition" |
 
291
        "define-method-combination" |
 
292
        "define-modify-macro" |
 
293
        "define-setf-expander" |
 
294
        "define-symbol-macro" |
 
295
        "defmacro" |
 
296
        "defmethod" |
 
297
        "defpackage" |
 
298
        "defparameter" |
 
299
        "defsetf" |
 
300
        "defstruct" |
 
301
        "deftype" |
 
302
        "defun" |
 
303
        "defvar"                                                { addToken(Token.RESERVED_WORD); }
 
304
 
 
305
        "abort" |
 
306
        "assert" |
 
307
        "block" |
 
308
        "break" |
 
309
        "case" |
 
310
        "catch" |
 
311
        "ccase" |
 
312
        "cerror" |
 
313
        "cond" |
 
314
        "ctypecase" |
 
315
        "declaim" |
 
316
        "declare" |
 
317
        "do" |
 
318
        "do*" |
 
319
        "do-all-symbols" |
 
320
        "do-external-symbols" |
 
321
        "do-symbols" |
 
322
        "dolist" |
 
323
        "dotimes" |
 
324
        "ecase" |
 
325
        "error" |
 
326
        "etypecase" |
 
327
        "eval-when" |
 
328
        "flet" |
 
329
        "handler-bind" |
 
330
        "handler-case" |
 
331
        "if" |
 
332
        "ignore-errors" |
 
333
        "in-package" |
 
334
        "labels" |
 
335
        "lambda" |
 
336
        "let" |
 
337
        "let*" |
 
338
        "locally" |
 
339
        "loop" |
 
340
        "macrolet" |
 
341
        "multiple-value-bind" |
 
342
        "proclaim" |
 
343
        "prog" |
 
344
        "prog*" |
 
345
        "prog1" |
 
346
        "prog2" |
 
347
        "progn" |
 
348
        "progv" |
 
349
        "provide" |
 
350
        "require" |
 
351
        "restart-bind" |
 
352
        "restart-case" |
 
353
        "restart-name" |
 
354
        "return" |
 
355
        "return-from" |
 
356
        "signal" |
 
357
        "symbol-macrolet" |
 
358
        "tagbody" |
 
359
        "the" |
 
360
        "throw" |
 
361
        "typecase" |
 
362
        "unless" |
 
363
        "unwind-protect" |
 
364
        "when" |
 
365
        "with-accessors" |
 
366
        "with-compilation-unit" |
 
367
        "with-condition-restarts" |
 
368
        "with-hash-table-iterator" |
 
369
        "with-input-from-string" |
 
370
        "with-open-file" |
 
371
        "with-open-stream" |
 
372
        "with-output-to-string" |
 
373
        "with-package-iterator" |
 
374
        "with-simple-restart" |
 
375
        "with-slots" |
 
376
        "with-standard-io-syntax"               { addToken(Token.RESERVED_WORD); }
 
377
 
 
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); }
 
386
 
 
387
        /* Numbers */
 
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); }
 
392
 
 
393
        {ErrorIdentifier}                               { addToken(Token.ERROR_IDENTIFIER); }
 
394
 
 
395
        /* Ended with a line not in a string or comment. */
 
396
        <<EOF>>                                         { addNullToken(); return firstToken; }
 
397
 
 
398
        /* Catch any other (unhandled) characters and flag them as bad. */
 
399
        .                                                       { addToken(Token.ERROR_IDENTIFIER); }
 
400
 
 
401
}
 
402
 
 
403
 
 
404
<STRING> {
 
405
        [^\n\\\"]+                      {}
 
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; }
 
410
}
 
411
 
 
412
 
 
413
<MLC> {
 
414
 
 
415
        [^hwf\n\|]+                             {}
 
416
        {URL}                                   { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_MULTILINE); start = zzMarkedPos; }
 
417
        [hwf]                                   {}
 
418
 
 
419
        \n                                              { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); return firstToken; }
 
420
        {MLCEnd}                                        { yybegin(YYINITIAL); addToken(start,zzStartRead+1, Token.COMMENT_MULTILINE); }
 
421
        \|                                              {}
 
422
        <<EOF>>                                 { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); return firstToken; }
 
423
 
 
424
}
 
425
 
 
426
 
 
427
<EOL_COMMENT> {
 
428
        [^hwf\n]+                               {}
 
429
        {URL}                                   { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_EOL); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_EOL); start = zzMarkedPos; }
 
430
        [hwf]                                   {}
 
431
        \n                                              { addToken(start,zzStartRead-1, Token.COMMENT_EOL); addNullToken(); return firstToken; }
 
432
        <<EOF>>                                 { addToken(start,zzStartRead-1, Token.COMMENT_EOL); addNullToken(); return firstToken; }
 
433
 
 
434
}