source: other-projects/rsyntax-textarea/src/java/org/fife/ui/rsyntaxtextarea/modes/MxmlTokenMaker.flex@ 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: 24.8 KB
Line 
1/*
2 * 01/21/2011
3 *
4 * MxmlTokenMaker.java - Generates tokens for MXML syntax highlighting.
5 *
6 * This library is distributed under a modified BSD license. See the included
7 * RSyntaxTextArea.License.txt file for details.
8 */
9package org.fife.ui.rsyntaxtextarea.modes;
10
11import java.io.*;
12import javax.swing.text.Segment;
13
14import org.fife.ui.rsyntaxtextarea.*;
15
16
17/**
18 * Scanner for MXML.
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 <code>MXMLTokenMaker.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 MxmlTokenMaker
59%extends AbstractMarkupTokenMaker
60%unicode
61%type org.fife.ui.rsyntaxtextarea.Token
62
63
64%{
65
66 /**
67 * Type specific to JSPTokenMaker denoting a line ending with an unclosed
68 * double-quote attribute.
69 */
70 public static final int INTERNAL_ATTR_DOUBLE = -1;
71
72
73 /**
74 * Type specific to JSPTokenMaker denoting a line ending with an unclosed
75 * single-quote attribute.
76 */
77 public static final int INTERNAL_ATTR_SINGLE = -2;
78
79
80 /**
81 * Token type specific to this class; this signals that the user has
82 * ended a line with an unclosed XML tag; thus a new line is beginning
83 * still inside of the tag.
84 */
85 public static final int INTERNAL_INTAG = -3;
86
87 /**
88 * Token type specific to this class; this signals that the user has
89 * ended a line with an unclosed Script tag; thus a new line is beginning
90 * still inside of the tag.
91 */
92 public static final int INTERNAL_INTAG_SCRIPT = -4;
93
94 /**
95 * Token type specific to this class; this signals that the user has
96 * ended a line in the middle of a double-quoted attribute in a Script
97 * tag.
98 */
99 public static final int INTERNAL_ATTR_DOUBLE_QUOTE_SCRIPT = -5;
100
101 /**
102 * Token type specific to this class; this signals that the user has
103 * ended a line in the middle of a single-quoted attribute in a Script
104 * tag.
105 */
106 public static final int INTERNAL_ATTR_SINGLE_QUOTE_SCRIPT = -6;
107
108 /**
109 * Token type specific to this class; this signals that the user has
110 * ended a line in an ActionScript code block (text content inside a
111 * Script tag).
112 */
113 public static final int INTERNAL_IN_AS = -7;
114
115 /**
116 * Token type specific to this class; this signals that the user has
117 * ended a line in an MLC in an ActionScript code block (text content
118 * inside a Script tag).
119 */
120 public static final int INTERNAL_IN_AS_MLC = -8;
121
122 /**
123 * Whether closing markup tags are automatically completed for HTML.
124 */
125 private static boolean completeCloseTags;
126
127
128 /**
129 * Constructor. This must be here because JFlex does not generate a
130 * no-parameter constructor.
131 */
132 public MxmlTokenMaker() {
133 }
134
135
136 static {
137 completeCloseTags = true;
138 }
139
140
141 /**
142 * Adds the token specified to the current linked list of tokens as an
143 * "end token;" that is, at <code>zzMarkedPos</code>.
144 *
145 * @param tokenType The token's type.
146 */
147 private void addEndToken(int tokenType) {
148 addToken(zzMarkedPos,zzMarkedPos, tokenType);
149 }
150
151
152 /**
153 * Adds the token specified to the current linked list of tokens.
154 *
155 * @param tokenType The token's type.
156 * @see #addToken(int, int, int)
157 */
158 private void addHyperlinkToken(int start, int end, int tokenType) {
159 int so = start + offsetShift;
160 addToken(zzBuffer, start,end, tokenType, so, true);
161 }
162
163
164 /**
165 * Adds the token specified to the current linked list of tokens.
166 *
167 * @param tokenType The token's type.
168 */
169 private void addToken(int tokenType) {
170 addToken(zzStartRead, zzMarkedPos-1, tokenType);
171 }
172
173
174 /**
175 * Adds the token specified to the current linked list of tokens.
176 *
177 * @param tokenType The token's type.
178 */
179 private void addToken(int start, int end, int tokenType) {
180 int so = start + offsetShift;
181 addToken(zzBuffer, start,end, tokenType, so);
182 }
183
184
185 /**
186 * Adds the token specified to the current linked list of tokens.
187 *
188 * @param array The character array.
189 * @param start The starting offset in the array.
190 * @param end The ending offset in the array.
191 * @param tokenType The token's type.
192 * @param startOffset The offset in the document at which this token
193 * occurs.
194 * @param hyperlink Whether this token is a hyperlink.
195 */
196 public void addToken(char[] array, int start, int end, int tokenType,
197 int startOffset, boolean hyperlink) {
198 super.addToken(array, start,end, tokenType, startOffset, hyperlink);
199 zzStartRead = zzMarkedPos;
200 }
201
202
203 /**
204 * Returns whether markup close tags should be completed. For XML, the
205 * default value is <code>true</code>.
206 *
207 * @return Whether closing markup tags are completed.
208 * @see #setCompleteCloseTags(boolean)
209 */
210 public boolean getCompleteCloseTags() {
211 return completeCloseTags;
212 }
213
214
215 /**
216 * Static version of {@link #getCompleteCloseTags()}. This hack is
217 * unfortunately needed for applications to be able to query this value
218 * without instantiating this class.
219 *
220 * @return Whether closing markup tags are completed.
221 * @see #setCompleteCloseTags(boolean)
222 */
223 public static boolean getCompleteCloseMarkupTags() {
224 return completeCloseTags;
225 }
226
227
228 /**
229 * Always returns <tt>false</tt>, as you never want "mark occurrences"
230 * working in XML files.
231 *
232 * @param type The token type.
233 * @return Whether tokens of this type should have "mark occurrences"
234 * enabled.
235 */
236 public boolean getMarkOccurrencesOfTokenType(int type) {
237 return false;
238 }
239
240
241 /**
242 * Returns the first token in the linked list of tokens generated
243 * from <code>text</code>. This method must be implemented by
244 * subclasses so they can correctly implement syntax highlighting.
245 *
246 * @param text The text from which to get tokens.
247 * @param initialTokenType The token type we should start with.
248 * @param startOffset The offset into the document at which
249 * <code>text</code> starts.
250 * @return The first <code>Token</code> in a linked list representing
251 * the syntax highlighted text.
252 */
253 public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
254
255 resetTokenList();
256 this.offsetShift = -text.offset + startOffset;
257
258 // Start off in the proper state.
259 int state = Token.NULL;
260 switch (initialTokenType) {
261 case Token.COMMENT_MULTILINE:
262 state = COMMENT;
263 start = text.offset;
264 break;
265 case Token.FUNCTION:
266 state = DTD;
267 start = text.offset;
268 break;
269 case INTERNAL_ATTR_DOUBLE:
270 state = INATTR_DOUBLE;
271 start = text.offset;
272 break;
273 case INTERNAL_ATTR_SINGLE:
274 state = INATTR_SINGLE;
275 start = text.offset;
276 break;
277 case Token.MARKUP_PROCESSING_INSTRUCTION:
278 state = PI;
279 start = text.offset;
280 break;
281 case INTERNAL_INTAG:
282 state = INTAG;
283 start = text.offset;
284 break;
285 case INTERNAL_INTAG_SCRIPT:
286 state = INTAG_SCRIPT;
287 start = text.offset;
288 break;
289 case INTERNAL_ATTR_DOUBLE_QUOTE_SCRIPT:
290 state = INATTR_DOUBLE_SCRIPT;
291 start = text.offset;
292 break;
293 case INTERNAL_ATTR_SINGLE_QUOTE_SCRIPT:
294 state = INATTR_SINGLE_SCRIPT;
295 start = text.offset;
296 break;
297 case INTERNAL_IN_AS:
298 state = AS;
299 start = text.offset;
300 break;
301 case INTERNAL_IN_AS_MLC:
302 state = AS_MLC;
303 start = text.offset;
304 break;
305 case Token.MARKUP_CDATA:
306 state = CDATA;
307 start = text.offset;
308 break;
309 default:
310 state = Token.NULL;
311 }
312
313 s = text;
314 try {
315 yyreset(zzReader);
316 yybegin(state);
317 return yylex();
318 } catch (IOException ioe) {
319 ioe.printStackTrace();
320 return new DefaultToken();
321 }
322
323 }
324
325
326 /**
327 * Sets whether markup close tags should be completed.
328 *
329 * @param complete Whether closing markup tags are completed.
330 * @see #getCompleteCloseTags()
331 */
332 public static void setCompleteCloseTags(boolean complete) {
333 completeCloseTags = complete;
334 }
335
336
337 /**
338 * Refills the input buffer.
339 *
340 * @return <code>true</code> if EOF was reached, otherwise
341 * <code>false</code>.
342 */
343 private boolean zzRefill() {
344 return zzCurrentPos>=s.offset+s.count;
345 }
346
347
348 /**
349 * Resets the scanner to read from a new input stream.
350 * Does not close the old reader.
351 *
352 * All internal variables are reset, the old input stream
353 * <b>cannot</b> be reused (internal buffer is discarded and lost).
354 * Lexical state is set to <tt>YY_INITIAL</tt>.
355 *
356 * @param reader the new input stream
357 */
358 public final void yyreset(java.io.Reader reader) {
359 // 's' has been updated.
360 zzBuffer = s.array;
361 /*
362 * We replaced the line below with the two below it because zzRefill
363 * no longer "refills" the buffer (since the way we do it, it's always
364 * "full" the first time through, since it points to the segment's
365 * array). So, we assign zzEndRead here.
366 */
367 //zzStartRead = zzEndRead = s.offset;
368 zzStartRead = s.offset;
369 zzEndRead = zzStartRead + s.count - 1;
370 zzCurrentPos = zzMarkedPos = zzPushbackPos = s.offset;
371 zzLexicalState = YYINITIAL;
372 zzReader = reader;
373 zzAtBOL = true;
374 zzAtEOF = false;
375 }
376
377
378%}
379
380/* XML macros (and some building-block macros used by AS macros). */
381Letter = [A-Za-z]
382NonzeroDigit = [1-9]
383Digit = ("0"|{NonzeroDigit})
384LetterOrUnderscore = ({Letter}|"_")
385NameStartChar = ({Letter}|[\:])
386NameChar = ({NameStartChar}|[\-\.]|{Digit})
387TagName = ({NameStartChar}{NameChar}*)
388Whitespace = ([ \t\f])
389LineTerminator = ([\n])
390Identifier = ([^ \t\n<&]+)
391AmperItem = ([&][^; \t]*[;]?)
392InTagIdentifier = ([^ \t\n\"\'=\/>]+)
393CDataBegin = ("<![CDATA[")
394CDataEnd = ("]]>")
395
396
397/* ActionScript macros. */
398HexDigit = ({Digit}|[A-Fa-f])
399OctalDigit = ([0-7])
400AnyCharacterButApostropheOrBackSlash = ([^\\'])
401AnyCharacterButDoubleQuoteOrBackSlash = ([^\\\"\n])
402EscapedSourceCharacter = ("u"{HexDigit}{HexDigit}{HexDigit}{HexDigit})
403Escape = ("\\"(([btnfr\"'\\])|([0123]{OctalDigit}?{OctalDigit}?)|({OctalDigit}{OctalDigit}?)|{EscapedSourceCharacter}))
404NonSeparator = ([^\t\f\r\n\ \(\)\{\}\[\]\;\,\.\=\>\<\!\~\?\:\+\-\*\/\&\|\^\%\"\']|"#"|"\\")
405IdentifierStart = ({LetterOrUnderscore}|"$")
406IdentifierPart = ({IdentifierStart}|{Digit}|("\\"{EscapedSourceCharacter}))
407
408AS_CharLiteral = ([\']({AnyCharacterButApostropheOrBackSlash}|{Escape})*[\'])
409AS_UnclosedCharLiteral = ([\']([\\].|[^\\\'])*[^\']?)
410AS_ErrorCharLiteral = ({AS_UnclosedCharLiteral}[\'])
411AS_StringLiteral = ([\"]({AnyCharacterButDoubleQuoteOrBackSlash}|{Escape})*[\"])
412AS_UnclosedStringLiteral = ([\"]([\\].|[^\\\"])*[^\"]?)
413AS_ErrorStringLiteral = ({AS_UnclosedStringLiteral}[\"])
414
415AS_MLCBegin = ("/*")
416AS_MLCEnd = ("*/")
417AS_LineCommentBegin = ("//")
418IntegerHelper1 = (({NonzeroDigit}{Digit}*)|"0")
419IntegerHelper2 = ("0"(([xX]{HexDigit}+)|({OctalDigit}*)))
420AS_IntegerLiteral = ({IntegerHelper1}[lL]?)
421AS_HexLiteral = ({IntegerHelper2}[lL]?)
422FloatHelper1 = ([fFdD]?)
423FloatHelper2 = ([eE][+-]?{Digit}+{FloatHelper1})
424FloatLiteral1 = ({Digit}+"."({FloatHelper1}|{FloatHelper2}|{Digit}+({FloatHelper1}|{FloatHelper2})))
425FloatLiteral2 = ("."{Digit}+({FloatHelper1}|{FloatHelper2}))
426FloatLiteral3 = ({Digit}+{FloatHelper2})
427AS_FloatLiteral = ({FloatLiteral1}|{FloatLiteral2}|{FloatLiteral3}|({Digit}+[fFdD]))
428AS_ErrorNumberFormat = (({AS_IntegerLiteral}|{AS_HexLiteral}|{AS_FloatLiteral}){NonSeparator}+)
429AS_BooleanLiteral = ("true"|"false")
430
431AS_Separator = ([\(\)\{\}\[\]])
432AS_Separator2 = ([\;,.])
433
434NonAssignmentOperator = ("+"|"-"|"<="|"^"|"++"|"<"|"*"|">="|"%"|"--"|">"|"/"|"!="|"?"|">>"|"!"|"&"|"=="|":"|">>"|"~"|"|"|"&&"|">>>")
435AssignmentOperator = ("="|"-="|"*="|"/="|"|="|"&="|"^="|"+="|"%="|"<<="|">>="|">>>=")
436AS_Operator = ({NonAssignmentOperator}|{AssignmentOperator})
437
438AS_Identifier = ({IdentifierStart}{IdentifierPart}*)
439AS_ErrorIdentifier = ({NonSeparator}+)
440AS_EndScriptTag = ("</"({NameStartChar}{NameChar}*":")?"Script"{Whitespace}*">")
441
442URLGenDelim = ([:\/\?#\[\]@])
443URLSubDelim = ([\!\$&'\(\)\*\+,;=])
444URLUnreserved = ({LetterOrUnderscore}|{Digit}|[\-\.\~])
445URLCharacter = ({URLGenDelim}|{URLSubDelim}|{URLUnreserved}|[%])
446URLCharacters = ({URLCharacter}*)
447URLEndCharacter = ([\/\$]|{Letter}|{Digit})
448URL = (((https?|f(tp|ile))"://"|"www.")({URLCharacters}{URLEndCharacter})?)
449
450%state COMMENT
451%state PI
452%state DTD
453%state INTAG
454%state INATTR_DOUBLE
455%state INATTR_SINGLE
456%state INTAG_SCRIPT
457%state INATTR_DOUBLE_SCRIPT
458%state INATTR_SINGLE_SCRIPT
459%state CDATA
460
461%state AS
462%state AS_MLC
463%state AS_EOL_COMMENT
464
465%%
466
467<YYINITIAL> {
468 "<!--" { start = zzMarkedPos-4; yybegin(COMMENT); }
469 {CDataBegin} { addToken(Token.DATA_TYPE); start = zzMarkedPos; yybegin(CDATA); }
470 "<!" { start = zzMarkedPos-2; yybegin(DTD); }
471 "<?" { start = zzMarkedPos-2; yybegin(PI); }
472 "<"{TagName} {
473 int count = yylength();
474 String tag = yytext(); // Get before addToken calls
475 addToken(zzStartRead,zzStartRead, Token.MARKUP_TAG_DELIMITER);
476 addToken(zzMarkedPos-(count-1), zzMarkedPos-1, Token.MARKUP_TAG_NAME);
477 if (tag.endsWith(":Script") || tag.equals("<Script")) {
478 yybegin(INTAG_SCRIPT);
479 }
480 else {
481 yybegin(INTAG);
482 }
483 }
484 "</"{TagName} {
485 int count = yylength();
486 addToken(zzStartRead,zzStartRead+1, Token.MARKUP_TAG_DELIMITER);
487 addToken(zzMarkedPos-(count-2), zzMarkedPos-1, Token.MARKUP_TAG_NAME);
488 yybegin(INTAG);
489 }
490 "<" { addToken(Token.MARKUP_TAG_DELIMITER); yybegin(INTAG); }
491 "</" { addToken(Token.MARKUP_TAG_DELIMITER); yybegin(INTAG); }
492 {LineTerminator} { addNullToken(); return firstToken; }
493 {Identifier} { addToken(Token.IDENTIFIER); }
494 {AmperItem} { addToken(Token.DATA_TYPE); }
495 {Whitespace}+ { addToken(Token.WHITESPACE); }
496 <<EOF>> { addNullToken(); return firstToken; }
497}
498
499<COMMENT> {
500 [^\n\-]+ {}
501 {LineTerminator} { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); return firstToken; }
502 "-->" { yybegin(YYINITIAL); addToken(start,zzStartRead+2, Token.COMMENT_MULTILINE); }
503 "-" {}
504 <<EOF>> { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); return firstToken; }
505}
506
507<PI> {
508 [^\n\?]+ {}
509 {LineTerminator} { addToken(start,zzStartRead-1, Token.MARKUP_PROCESSING_INSTRUCTION); return firstToken; }
510 "?>" { yybegin(YYINITIAL); addToken(start,zzStartRead+1, Token.MARKUP_PROCESSING_INSTRUCTION); }
511 "?" {}
512 <<EOF>> { addToken(start,zzStartRead-1, Token.MARKUP_PROCESSING_INSTRUCTION); return firstToken; }
513}
514
515<DTD> {
516 [^\n>]+ {}
517 {LineTerminator} { addToken(start,zzStartRead-1, Token.FUNCTION); return firstToken; }
518 ">" { yybegin(YYINITIAL); addToken(start,zzStartRead, Token.FUNCTION); }
519 <<EOF>> { addToken(start,zzStartRead-1, Token.FUNCTION); return firstToken; }
520}
521
522<INTAG> {
523 {InTagIdentifier} { addToken(Token.MARKUP_TAG_ATTRIBUTE); }
524 {Whitespace}+ { addToken(Token.WHITESPACE); }
525 "=" { addToken(Token.OPERATOR); }
526 "/" { addToken(Token.MARKUP_TAG_DELIMITER); /* Not valid but we'll still accept it */ }
527 "/>" { yybegin(YYINITIAL); addToken(Token.MARKUP_TAG_DELIMITER); }
528 ">" { yybegin(YYINITIAL); addToken(Token.MARKUP_TAG_DELIMITER); }
529 [\"] { start = zzMarkedPos-1; yybegin(INATTR_DOUBLE); }
530 [\'] { start = zzMarkedPos-1; yybegin(INATTR_SINGLE); }
531 <<EOF>> { addToken(start,zzStartRead-1, INTERNAL_INTAG); return firstToken; }
532}
533
534<INATTR_DOUBLE> {
535 [^\"]* {}
536 [\"] { yybegin(INTAG); addToken(start,zzStartRead, Token.MARKUP_TAG_ATTRIBUTE_VALUE); }
537 <<EOF>> { addToken(start,zzStartRead-1, Token.MARKUP_TAG_ATTRIBUTE_VALUE); addEndToken(INTERNAL_ATTR_DOUBLE); return firstToken; }
538}
539
540<INATTR_SINGLE> {
541 [^\']* {}
542 [\'] { yybegin(INTAG); addToken(start,zzStartRead, Token.MARKUP_TAG_ATTRIBUTE_VALUE); }
543 <<EOF>> { addToken(start,zzStartRead-1, Token.MARKUP_TAG_ATTRIBUTE_VALUE); addEndToken(INTERNAL_ATTR_SINGLE); return firstToken; }
544}
545
546<INTAG_SCRIPT> {
547 {InTagIdentifier} { addToken(Token.MARKUP_TAG_ATTRIBUTE); }
548 {Whitespace}+ { addToken(Token.WHITESPACE); }
549 "=" { addToken(Token.OPERATOR); }
550 "/" { addToken(Token.MARKUP_TAG_DELIMITER); /* Not valid but we'll still accept it */ }
551 "/>" { yybegin(YYINITIAL); addToken(Token.MARKUP_TAG_DELIMITER); }
552 ">" { yybegin(AS); addToken(Token.MARKUP_TAG_DELIMITER); }
553 [\"] { start = zzMarkedPos-1; yybegin(INATTR_DOUBLE_SCRIPT); }
554 [\'] { start = zzMarkedPos-1; yybegin(INATTR_SINGLE_SCRIPT); }
555 <<EOF>> { addToken(start,zzStartRead-1, INTERNAL_INTAG_SCRIPT); return firstToken; }
556}
557
558<INATTR_DOUBLE_SCRIPT> {
559 [^\"]* {}
560 [\"] { yybegin(INTAG_SCRIPT); addToken(start,zzStartRead, Token.MARKUP_TAG_ATTRIBUTE_VALUE); }
561 <<EOF>> { addToken(start,zzStartRead-1, Token.MARKUP_TAG_ATTRIBUTE_VALUE); addEndToken(INTERNAL_ATTR_DOUBLE_QUOTE_SCRIPT); return firstToken; }
562}
563
564<INATTR_SINGLE_SCRIPT> {
565 [^\']* {}
566 [\'] { yybegin(INTAG_SCRIPT); addToken(start,zzStartRead, Token.MARKUP_TAG_ATTRIBUTE_VALUE); }
567 <<EOF>> { addToken(start,zzStartRead-1, Token.MARKUP_TAG_ATTRIBUTE_VALUE); addEndToken(INTERNAL_ATTR_SINGLE_QUOTE_SCRIPT); return firstToken; }
568}
569
570<CDATA> {
571 [^\]]+ {}
572 {CDataEnd} { int temp=zzStartRead; yybegin(YYINITIAL); addToken(start,zzStartRead-1, Token.MARKUP_CDATA); addToken(temp,zzMarkedPos-1, Token.DATA_TYPE); }
573 "]" {}
574 <<EOF>> { addToken(start,zzStartRead-1, Token.MARKUP_CDATA); return firstToken; }
575}
576
577<AS> {
578
579 {AS_EndScriptTag} {
580 int origStart = zzStartRead;
581 String text = yytext();
582 int tagNameEnd = text.length() - 2; // "-1" is '>'
583 while (Character.isWhitespace(text.charAt(tagNameEnd))) {
584 tagNameEnd--;
585 }
586 int tagNameLen = tagNameEnd - 1;
587 yybegin(YYINITIAL);
588 addToken(zzStartRead,zzStartRead+1, Token.MARKUP_TAG_DELIMITER);
589 addToken(origStart+2,origStart+2+tagNameLen-1, Token.MARKUP_TAG_NAME);
590 if (tagNameEnd<text.length()-2) {
591 addToken(origStart+tagNameEnd+1, zzMarkedPos-2, Token.WHITESPACE);
592 }
593 addToken(zzMarkedPos-1,zzMarkedPos-1, Token.MARKUP_TAG_DELIMITER);
594 }
595
596 /* ActionScript snippets are usually wrapped in CDATA. */
597 {CDataBegin} |
598 {CDataEnd} { addToken(Token.DATA_TYPE); }
599
600 /* Keywords */
601 "add" |
602 "and" |
603 "break" |
604 "case" |
605 "catch" |
606 "class" |
607 "const" |
608 "continue" |
609 "default" |
610 "delete" |
611 "do" |
612 "dynamic" |
613 "else" |
614 "eq" |
615 "extends" |
616 "final" |
617 "finally" |
618 "for" |
619 "for each" |
620 "function" |
621 "ge" |
622 "get" |
623 "gt" |
624 "if" |
625 "ifFrameLoaded" |
626 "implements" |
627 "import" |
628 "in" |
629 "include" |
630 "interface" |
631 "internal" |
632 "label" |
633 "le" |
634 "lt" |
635 "namespace" |
636 "native" |
637 "ne" |
638 "new" |
639 "not" |
640 "on" |
641 "onClipEvent" |
642 "or" |
643 "override" |
644 "package" |
645 "private" |
646 "protected" |
647 "public" |
648 "return" |
649 "set" |
650 "static" |
651 "super" |
652 "switch" |
653 "tellTarget" |
654 "this" |
655 "throw" |
656 "try" |
657 "typeof" |
658 "use" |
659 "var" |
660 "void" |
661 "while" |
662 "with" |
663
664 "null" |
665 "undefined" { addToken(Token.RESERVED_WORD); }
666
667 /* Built-in objects (good idea not to use these names!) */
668 "Array" |
669 "Boolean" |
670 "Color" |
671 "Date" |
672 "Function" |
673 "int" |
674 "Key" |
675 "MovieClip" |
676 "Math" |
677 "Mouse" |
678 "Null" |
679 "Number" |
680 "Object" |
681 "Selection" |
682 "Sound" |
683 "String" |
684 "uint" |
685 "Vector" |
686 "void" |
687 "XML" |
688 "XMLNode" |
689 "XMLSocket" { addToken(Token.DATA_TYPE); }
690
691 /* Global functions */
692 "call" |
693 "escape" |
694 "eval" |
695 "fscommand" |
696 "getProperty" |
697 "getTimer" |
698 "getURL" |
699 "getVersion" |
700 "gotoAndPlay" |
701 "gotoAndStop" |
702 "#include" |
703 "int" |
704 "isFinite" |
705 "isNaN" |
706 "loadMovie" |
707 "loadMovieNum" |
708 "loadVariables" |
709 "loadVariablesNum" |
710 "maxscroll" |
711 "newline" |
712 "nextFrame" |
713 "nextScene" |
714 "Number" |
715 "parseFloat" |
716 "parseInt" |
717 "play" |
718 "prevFrame" |
719 "prevScene" |
720 "print" |
721 "printAsBitmap" |
722 "printAsBitmapNum" |
723 "printNum" |
724 "random" |
725 "removeMovieClip" |
726 "scroll" |
727 "setProperty" |
728 "startDrag" |
729 "stop" |
730 "stopAllSounds" |
731 "stopDrag" |
732 "String" |
733 "targetPath" |
734 "tellTarget" |
735 "toggleHighQuality" |
736 "trace" |
737 "unescape" |
738 "unloadMovie" |
739 "unloadMovieNum" |
740 "updateAfterEvent" { addToken(Token.FUNCTION); }
741
742 /* Booleans. */
743 {AS_BooleanLiteral} { addToken(Token.LITERAL_BOOLEAN); }
744
745 {LineTerminator} { addEndToken(INTERNAL_IN_AS); return firstToken; }
746
747 {AS_Identifier} { addToken(Token.IDENTIFIER); }
748
749 {Whitespace}+ { addToken(Token.WHITESPACE); }
750
751 /* String/Character literals. */
752 {AS_CharLiteral} { addToken(Token.LITERAL_CHAR); }
753 {AS_UnclosedCharLiteral} { addToken(Token.ERROR_CHAR); addNullToken(); return firstToken; }
754 {AS_ErrorCharLiteral} { addToken(Token.ERROR_CHAR); }
755 {AS_StringLiteral} { addToken(Token.LITERAL_STRING_DOUBLE_QUOTE); }
756 {AS_UnclosedStringLiteral} { addToken(Token.ERROR_STRING_DOUBLE); addNullToken(); return firstToken; }
757 {AS_ErrorStringLiteral} { addToken(Token.ERROR_STRING_DOUBLE); }
758
759 /* Comment literals. */
760 "/**/" { addToken(Token.COMMENT_MULTILINE); }
761 {AS_MLCBegin} { start = zzMarkedPos-2; yybegin(AS_MLC); }
762 {AS_LineCommentBegin} { start = zzMarkedPos-2; yybegin(AS_EOL_COMMENT); }
763
764 /* Separators. */
765 {AS_Separator} { addToken(Token.SEPARATOR); }
766 {AS_Separator2} { addToken(Token.IDENTIFIER); }
767
768 /* Operators. */
769 {AS_Operator} { addToken(Token.OPERATOR); }
770
771 /* Numbers */
772 {AS_IntegerLiteral} { addToken(Token.LITERAL_NUMBER_DECIMAL_INT); }
773 {AS_HexLiteral} { addToken(Token.LITERAL_NUMBER_HEXADECIMAL); }
774 {AS_FloatLiteral} { addToken(Token.LITERAL_NUMBER_FLOAT); }
775 {AS_ErrorNumberFormat} { addToken(Token.ERROR_NUMBER_FORMAT); }
776
777 {AS_ErrorIdentifier} { addToken(Token.ERROR_IDENTIFIER); }
778
779 /* Ended with a line not in a string or comment. */
780 <<EOF>> { addEndToken(INTERNAL_IN_AS); return firstToken; }
781
782 /* Catch any other (unhandled) characters and flag them as bad. */
783 . { addToken(Token.ERROR_IDENTIFIER); }
784
785}
786
787
788<AS_MLC> {
789
790 [^hwf\n\*]+ {}
791 {URL} { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_MULTILINE); start = zzMarkedPos; }
792 [hwf] {}
793
794 \n { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addEndToken(INTERNAL_IN_AS_MLC); return firstToken; }
795 {AS_MLCEnd} { yybegin(AS); addToken(start,zzStartRead+1, Token.COMMENT_MULTILINE); }
796 \* {}
797 <<EOF>> { addToken(start,zzStartRead-1, Token.COMMENT_MULTILINE); addEndToken(INTERNAL_IN_AS_MLC); return firstToken; }
798
799}
800
801
802<AS_EOL_COMMENT> {
803 [^hwf\n]+ {}
804 {URL} { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.COMMENT_EOL); addHyperlinkToken(temp,zzMarkedPos-1, Token.COMMENT_EOL); start = zzMarkedPos; }
805 [hwf] {}
806 \n { addToken(start,zzStartRead-1, Token.COMMENT_EOL); addEndToken(INTERNAL_IN_AS); return firstToken; }
807 <<EOF>> { addToken(start,zzStartRead-1, Token.COMMENT_EOL); addEndToken(INTERNAL_IN_AS); return firstToken; }
808
809}
Note: See TracBrowser for help on using the repository browser.