1 13 package org.netbeans.modules.el.lexer.api; 14 15 import java.util.Collection ; 16 import java.util.EnumSet ; 17 import java.util.HashMap ; 18 import java.util.Map ; 19 import org.netbeans.api.lexer.InputAttributes; 20 import org.netbeans.api.lexer.Language; 21 import org.netbeans.api.lexer.LanguagePath; 22 import org.netbeans.api.lexer.Token; 23 import org.netbeans.api.lexer.TokenId; 24 import org.netbeans.modules.el.lexer.ELLexer; 25 import org.netbeans.spi.lexer.LanguageEmbedding; 26 import org.netbeans.spi.lexer.LanguageHierarchy; 27 import org.netbeans.spi.lexer.Lexer; 28 import org.netbeans.spi.lexer.LexerRestartInfo; 29 30 36 public enum ELTokenId implements TokenId { 37 38 LT("<", ELTokenCategories.OPERATORS.categoryName), 40 GT(">", ELTokenCategories.OPERATORS.categoryName), 41 DOT(".", ELTokenCategories.OPERATORS.categoryName), 42 COMMA(",", ELTokenCategories.OPERATORS.categoryName), 43 QUESTION("?", ELTokenCategories.OPERATORS.categoryName), 44 PLUS("+", ELTokenCategories.OPERATORS.categoryName), 45 MINUS("-", ELTokenCategories.OPERATORS.categoryName), 46 MUL("*", ELTokenCategories.OPERATORS.categoryName), 47 DIV("/", ELTokenCategories.OPERATORS.categoryName), 48 MOD("%", ELTokenCategories.OPERATORS.categoryName), 49 EQ_EQ("==", ELTokenCategories.OPERATORS.categoryName), 50 LT_EQ("<=", ELTokenCategories.OPERATORS.categoryName), 51 GT_EQ(">=", ELTokenCategories.OPERATORS.categoryName), 52 NOT_EQ("!=", ELTokenCategories.OPERATORS.categoryName), 53 AND_AND("&&", ELTokenCategories.OPERATORS.categoryName), 54 OR_OR("||", ELTokenCategories.OPERATORS.categoryName), 55 COLON(":", ELTokenCategories.OPERATORS.categoryName), 56 NOT("!", ELTokenCategories.OPERATORS.categoryName), 57 LPAREN("(", ELTokenCategories.OPERATORS.categoryName), 58 RPAREN(")", ELTokenCategories.OPERATORS.categoryName), 59 LBRACKET("[", ELTokenCategories.OPERATORS.categoryName), 60 RBRACKET("]", ELTokenCategories.OPERATORS.categoryName), 61 62 AND_KEYWORD("and", ELTokenCategories.KEYWORDS.categoryName), 64 DIV_KEYWORD("div", ELTokenCategories.KEYWORDS.categoryName), 65 EMPTY_KEYWORD("empty", ELTokenCategories.KEYWORDS.categoryName), 66 EQ_KEYWORD("eq", ELTokenCategories.KEYWORDS.categoryName), 67 FALSE_KEYWORD("false", ELTokenCategories.KEYWORDS.categoryName), 68 GE_KEYWORD("ge", ELTokenCategories.KEYWORDS.categoryName), 69 GT_KEYWORD("gt", ELTokenCategories.KEYWORDS.categoryName), 70 INSTANCEOF_KEYWORD("instanceof", ELTokenCategories.KEYWORDS.categoryName), 71 LE_KEYWORD("le", ELTokenCategories.KEYWORDS.categoryName), 72 LT_KEYWORD("lt", ELTokenCategories.KEYWORDS.categoryName), 73 MOD_KEYWORD("mod", ELTokenCategories.KEYWORDS.categoryName), 74 NE_KEYWORD("ne", ELTokenCategories.KEYWORDS.categoryName), 75 NOT_KEYWORD("not", ELTokenCategories.KEYWORDS.categoryName), 76 NULL_KEYWORD("null", ELTokenCategories.KEYWORDS.categoryName), 77 OR_KEYWORD("or", ELTokenCategories.KEYWORDS.categoryName), 78 TRUE_KEYWORD("true", ELTokenCategories.KEYWORDS.categoryName), 79 80 WHITESPACE(null, "whitespace"), 82 EOL("\n", "eol"), 83 STRING_LITERAL(null, "string"), 84 TAG_LIB_PREFIX(null, "tag-lib-prefix"), 85 IDENTIFIER(null, "identifier"), 86 CHAR_LITERAL(null, "char-literal"), 87 88 90 INT_LITERAL(null, "int-literal"), 91 92 LONG_LITERAL(null, "long-literal"), 93 94 HEX_LITERAL(null, "hex-literal"), 95 96 OCTAL_LITERAL(null, "octal-literal"), 97 98 FLOAT_LITERAL(null, "float-literal"), 99 100 DOUBLE_LITERAL(null, "double-literal"), 101 INVALID_OCTAL_LITERAL(null, "invalid-octal-literal"), 103 INVALID_CHAR(null, "invalid-char"); 104 105 106 107 public static enum ELTokenCategories { 108 109 110 KEYWORDS("keyword"), 111 112 OPERATORS("operators"), 113 114 NUMERIC_LITERALS("numeric-literals"), 115 116 ERRORS("error"); 117 118 private final String categoryName; 119 120 ELTokenCategories(String categoryName) { 121 this.categoryName = categoryName; 122 } 123 124 } 125 126 private final String fixedText; 128 private final String primaryCategory; 129 130 ELTokenId(String fixedText, String primaryCategory) { 131 this.fixedText = fixedText; 132 this.primaryCategory = primaryCategory; 133 } 134 135 136 public String fixedText() { 137 return fixedText; 138 } 139 140 148 149 public String primaryCategory() { 150 return primaryCategory; 151 } 152 153 private static final Language<ELTokenId> language = new LanguageHierarchy<ELTokenId>() { 154 @Override 155 protected Collection <ELTokenId> createTokenIds() { 156 return EnumSet.allOf(ELTokenId.class); 157 } 158 159 @Override 160 protected Map <String ,Collection <ELTokenId>> createTokenCategories() { 161 Map <String ,Collection <ELTokenId>> cats = new HashMap <String ,Collection <ELTokenId>>(); 162 163 cats.put(ELTokenCategories.NUMERIC_LITERALS.categoryName, EnumSet.of( 164 ELTokenId.INT_LITERAL, 165 ELTokenId.LONG_LITERAL, 166 ELTokenId.HEX_LITERAL, 167 ELTokenId.OCTAL_LITERAL, 168 ELTokenId.FLOAT_LITERAL, 169 ELTokenId.DOUBLE_LITERAL)); 170 171 cats.put(ELTokenCategories.ERRORS.categoryName, EnumSet.of( 172 ELTokenId.INVALID_OCTAL_LITERAL, 173 ELTokenId.INVALID_CHAR)); 174 175 return cats; 176 } 177 178 @Override 179 protected Lexer<ELTokenId> createLexer(LexerRestartInfo<ELTokenId> info) { 180 return new ELLexer(info); 181 } 182 183 @Override 184 public LanguageEmbedding<? extends TokenId> embedding( 185 Token<ELTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) { 186 return null; } 188 189 @Override 190 protected String mimeType() { 191 return "text/x-el"; } 193 }.language(); 194 195 200 public static Language<ELTokenId> language() { 201 return language; 202 } 203 204 205 } 206 | Popular Tags |