KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > lexer > demo > javacc > CalcLanguage


1
2 package org.netbeans.modules.lexer.demo.javacc;
3
4 import org.netbeans.api.lexer.Lexer;
5 import org.netbeans.api.lexer.TokenId;
6 import org.netbeans.spi.lexer.AbstractLanguage;
7 import org.netbeans.spi.lexer.MatcherFactory;
8
9 public class CalcLanguage extends AbstractLanguage {
10
11     /** Maximum lexer state determined from xxxConstants class. */
12     static final int MAX_STATE = 1;
13
14     /** Lazily initialized singleton instance of this language. */
15     private static CalcLanguage INSTANCE;
16
17     /** @return singleton instance of this language. */
18     public static synchronized CalcLanguage get() {
19         if (INSTANCE == null)
20             INSTANCE = new CalcLanguage();
21
22         return INSTANCE;
23     }
24
25     public static final int WHITESPACE_INT = 1;
26     public static final int INCOMPLETE_ML_COMMENT_INT = 2;
27     public static final int ML_COMMENT_INT = 3;
28     public static final int PLUS_INT = 4;
29     public static final int MINUS_INT = 5;
30     public static final int MUL_INT = 6;
31     public static final int DIV_INT = 7;
32     public static final int MUL3_INT = 8;
33     public static final int PLUS5_INT = 9;
34     public static final int LPAREN_INT = 10;
35     public static final int RPAREN_INT = 11;
36     public static final int CONSTANT_INT = 12;
37     public static final int ML_COMMENT_END_INT = 16;
38     public static final int ERROR_INT = 17;
39
40
41     public static final TokenId CONSTANT = new TokenId("constant", CONSTANT_INT, new String JavaDoc[]{"literal"});
42     public static final TokenId DIV = new TokenId("div", DIV_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("/"));
43     public static final TokenId ERROR = new TokenId("error", ERROR_INT, new String JavaDoc[]{"error"});
44     public static final TokenId INCOMPLETE_ML_COMMENT = new TokenId("incomplete-ml-comment", INCOMPLETE_ML_COMMENT_INT, new String JavaDoc[]{"comment", "incomplete", "error"});
45     public static final TokenId LPAREN = new TokenId("lparen", LPAREN_INT, new String JavaDoc[]{"separator"}, MatcherFactory.createTextCheckMatcher("("));
46     public static final TokenId MINUS = new TokenId("minus", MINUS_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("-"));
47     public static final TokenId ML_COMMENT = new TokenId("ml-comment", ML_COMMENT_INT, new String JavaDoc[]{"comment"});
48     public static final TokenId ML_COMMENT_END = new TokenId("ml-comment-end", ML_COMMENT_END_INT, new String JavaDoc[]{"error"}, MatcherFactory.createTextCheckMatcher("*/"));
49     public static final TokenId MUL = new TokenId("mul", MUL_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("*"));
50     public static final TokenId MUL3 = new TokenId("mul3", MUL3_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("***")); // Special token for testing extra lookahead and lookback
51
public static final TokenId PLUS = new TokenId("plus", PLUS_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("+"));
52     public static final TokenId PLUS5 = new TokenId("plus5", PLUS5_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("+++++")); // Special token for testing extra lookahead and lookback
53
public static final TokenId RPAREN = new TokenId("rparen", RPAREN_INT, new String JavaDoc[]{"separator"}, MatcherFactory.createTextCheckMatcher(")"));
54     public static final TokenId WHITESPACE = new TokenId("whitespace", WHITESPACE_INT, new String JavaDoc[]{"whitespace"}, MatcherFactory.createTextCheckMatcher(" "));
55
56     CalcLanguage() {
57     }
58
59     public Lexer createLexer() {
60         return new CalcLexer();
61     }
62
63 }
64
Popular Tags