KickJava   Java API By Example, From Geeks To Geeks.

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


1
2 package org.netbeans.modules.lexer.demo.antlr;
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     /** Lazily initialized singleton instance of this language. */
12     private static CalcLanguage INSTANCE;
13
14     /** @return singleton instance of this language. */
15     public static synchronized CalcLanguage get() {
16         if (INSTANCE == null)
17             INSTANCE = new CalcLanguage();
18
19         return INSTANCE;
20     }
21
22     public static final int WHITESPACE_INT = 4;
23     public static final int PLUS_INT = 5;
24     public static final int MINUS_INT = 6;
25     public static final int MUL_INT = 7;
26     public static final int DIV_INT = 8;
27     public static final int LPAREN_INT = 9;
28     public static final int RPAREN_INT = 10;
29     public static final int ABC_INT = 11;
30     public static final int CONSTANT_INT = 12;
31     public static final int ML_COMMENT_INT = 13;
32     public static final int INCOMPLETE_ML_COMMENT_INT = 17;
33     public static final int ERROR_INT = 18;
34
35
36     public static final TokenId ABC = new TokenId("abc", ABC_INT);
37     public static final TokenId CONSTANT = new TokenId("constant", CONSTANT_INT, new String JavaDoc[]{"literal"});
38     public static final TokenId DIV = new TokenId("div", DIV_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("/"));
39     public static final TokenId ERROR = new TokenId("error", ERROR_INT, new String JavaDoc[]{"error"});
40     public static final TokenId INCOMPLETE_ML_COMMENT = new TokenId("incomplete-ml-comment", INCOMPLETE_ML_COMMENT_INT, new String JavaDoc[]{"comment", "incomplete", "error"});
41     public static final TokenId LPAREN = new TokenId("lparen", LPAREN_INT, new String JavaDoc[]{"separator"}, MatcherFactory.createTextCheckMatcher("("));
42     public static final TokenId MINUS = new TokenId("minus", MINUS_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("-"));
43     public static final TokenId ML_COMMENT = new TokenId("ml-comment", ML_COMMENT_INT, new String JavaDoc[]{"comment"});
44     public static final TokenId MUL = new TokenId("mul", MUL_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("*"));
45     public static final TokenId PLUS = new TokenId("plus", PLUS_INT, new String JavaDoc[]{"operator"}, MatcherFactory.createTextCheckMatcher("+"));
46     public static final TokenId RPAREN = new TokenId("rparen", RPAREN_INT, new String JavaDoc[]{"separator"}, MatcherFactory.createTextCheckMatcher(")"));
47     public static final TokenId WHITESPACE = new TokenId("whitespace", WHITESPACE_INT, null, MatcherFactory.createTextCheckMatcher(" "));
48
49     CalcLanguage() {
50     }
51
52     public Lexer createLexer() {
53         return new CalcLexer();
54     }
55
56 }
57
Popular Tags