1 19 20 package org.netbeans.modules.lexer.editorbridge.calc.lang; 21 22 import java.util.Collection ; 23 import java.util.EnumSet ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import org.netbeans.api.lexer.InputAttributes; 27 import org.netbeans.api.lexer.Language; 28 import org.netbeans.api.lexer.LanguagePath; 29 import org.netbeans.api.lexer.Token; 30 import org.netbeans.api.lexer.TokenId; 31 import org.netbeans.modules.lexer.editorbridge.calc.CalcDataLoader; 32 import org.netbeans.spi.lexer.LanguageEmbedding; 33 import org.netbeans.spi.lexer.LanguageHierarchy; 34 import org.netbeans.spi.lexer.Lexer; 35 import org.netbeans.spi.lexer.LexerRestartInfo; 36 37 43 44 public enum CalcTokenId implements TokenId { 45 46 WHITESPACE(null, "whitespace"), 47 LINE_COMMENT(null, "comment"), 48 BLOCK_COMMENT(null, "comment"), 49 E("e", "keyword"), 50 PI("pi", "keyword"), 51 IDENTIFIER(null, null), 52 INT_LITERAL(null, "number"), 53 FLOAT_LITERAL(null, "number"), 54 PLUS("+", "operator"), 55 MINUS("-", "operator"), 56 STAR("*", "operator"), 57 SLASH("/", "operator"), 58 LPAREN("(", "separator"), 59 RPAREN(")", "separator"), 60 ERROR(null, "error"), 61 BLOCK_COMMENT_INCOMPLETE(null, "comment"); 62 63 64 private final String fixedText; 65 66 private final String primaryCategory; 67 68 private CalcTokenId(String fixedText, String primaryCategory) { 69 this.fixedText = fixedText; 70 this.primaryCategory = primaryCategory; 71 } 72 73 public String fixedText() { 74 return fixedText; 75 } 76 77 public String primaryCategory() { 78 return primaryCategory; 79 } 80 81 private static final Language<CalcTokenId> language = new LanguageHierarchy<CalcTokenId>() { 82 @Override 83 protected Collection <CalcTokenId> createTokenIds() { 84 return EnumSet.allOf(CalcTokenId.class); 85 } 86 87 @Override 88 protected Map <String ,Collection <CalcTokenId>> createTokenCategories() { 89 Map <String ,Collection <CalcTokenId>> cats = new HashMap <String ,Collection <CalcTokenId>>(); 90 91 cats.put("incomplete", EnumSet.of(CalcTokenId.BLOCK_COMMENT_INCOMPLETE)); 93 cats.put("error", EnumSet.of(CalcTokenId.BLOCK_COMMENT_INCOMPLETE)); 95 96 return cats; 97 } 98 99 @Override 100 protected Lexer<CalcTokenId> createLexer(LexerRestartInfo<CalcTokenId> info) { 101 return new CalcLexer(info); 102 } 103 104 @Override 105 protected LanguageEmbedding embedding( 106 Token<CalcTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) { 107 return null; } 109 110 @Override 111 protected String mimeType() { 112 return CalcDataLoader.CALC_MIME_TYPE; 113 } 114 115 }.language(); 116 117 public static final Language<CalcTokenId> language() { 118 return language; 119 } 120 121 } 122 | Popular Tags |