1 19 package org.netbeans.modules.ruby.lexer; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import java.util.Map ; 26 import org.netbeans.api.gsf.GsfTokenId; 27 import org.netbeans.api.lexer.InputAttributes; 28 import org.netbeans.api.lexer.Language; 29 import org.netbeans.api.lexer.LanguagePath; 30 import org.netbeans.api.lexer.Token; 31 import org.netbeans.api.lexer.TokenId; 32 import org.netbeans.api.lexer.TokenId; 33 import org.netbeans.modules.ruby.RubyMimeResolver; 34 import org.netbeans.modules.ruby.lexer.RubyLexer; 35 import org.netbeans.modules.ruby.lexer.RubyStringTokenId; 36 import org.netbeans.spi.lexer.LanguageEmbedding; 37 import org.netbeans.spi.lexer.LanguageHierarchy; 38 import org.netbeans.spi.lexer.Lexer; 39 import org.netbeans.spi.lexer.LexerRestartInfo; 40 41 42 46 public class RubyTokenId extends GsfTokenId { 47 public static final GsfTokenId DOT = new GsfTokenId("DOT", null, "operator"); 51 public static final GsfTokenId RANGE = new GsfTokenId("RANGE", null, "operator"); 52 public static final GsfTokenId COLON3 = new GsfTokenId("COLON3", null, "operator"); 53 public static final GsfTokenId SUPER = new GsfTokenId("SUPER", null, "keyword"); 54 public static final GsfTokenId SELF = new GsfTokenId("SELF", null, "keyword"); 55 public static final GsfTokenId QUOTED_STRING_LITERAL = 56 new GsfTokenId("QUOTED_STRING_LITERAL", null, "string"); 57 public static final GsfTokenId QUOTED_STRING_BEGIN = 58 new GsfTokenId("QUOTED_STRING_BEGIN", null, "string"); 59 public static final GsfTokenId QUOTED_STRING_END = 60 new GsfTokenId("QUOTED_STRING_END", null, "string"); 61 public static final GsfTokenId EMBEDDED_RUBY = 62 new GsfTokenId("EMBEDDED_RUBY", null, "default"); 64 public static final GsfTokenId MODULE = new GsfTokenId("MODULE", null, "keyword"); 65 public static final GsfTokenId CLASS = new GsfTokenId("CLASS", null, "keyword"); 66 public static final GsfTokenId DEF = new GsfTokenId("DEF", null, "keyword"); 67 public static final GsfTokenId END = new GsfTokenId("END", null, "keyword"); 68 public static final GsfTokenId BEGIN = new GsfTokenId("BEGIN", null, "keyword"); 69 public static final GsfTokenId FOR = new GsfTokenId("FOR", null, "keyword"); 70 public static final GsfTokenId CASE = new GsfTokenId("CASE", null, "keyword"); 71 public static final GsfTokenId LOOP = new GsfTokenId("LOOP", null, "keyword"); 72 73 74 public static final GsfTokenId DO = new GsfTokenId("DO", null, "keyword"); 75 76 77 public static final GsfTokenId IF = new GsfTokenId("IF", null, "keyword"); 78 79 80 public static final GsfTokenId WHILE = new GsfTokenId("WHILE", null, "keyword"); 81 82 83 public static final GsfTokenId UNTIL = new GsfTokenId("UNTIL", null, "keyword"); 84 85 86 public static final GsfTokenId UNLESS = new GsfTokenId("UNLESS", null, "keyword"); 87 88 public static final GsfTokenId ELSE = new GsfTokenId("ELSE", null, "keyword"); 90 public static final GsfTokenId ELSIF = new GsfTokenId("ELSIF", null, "keyword"); 91 public static final GsfTokenId ENSURE = new GsfTokenId("ENSURE", null, "keyword"); 92 public static final GsfTokenId WHEN = new GsfTokenId("WHEN", null, "keyword"); 93 public static final GsfTokenId RESCUE = new GsfTokenId("RESCUE", null, "keyword"); 94 private static final Language<GsfTokenId> language = 95 new LanguageHierarchy<GsfTokenId>() { 96 protected String mimeType() { 97 return RubyMimeResolver.RUBY_MIME_TYPE; 98 } 99 100 protected Collection <GsfTokenId> createTokenIds() { 101 return getUsedTokens(); 102 } 103 104 protected Map <String , Collection <GsfTokenId>> createTokenCategories() { 105 Map <String , Collection <GsfTokenId>> cats = 106 new HashMap <String , Collection <GsfTokenId>>(); 107 108 return cats; 136 } 137 138 protected Lexer<GsfTokenId> createLexer(LexerRestartInfo<GsfTokenId> info) { 139 return RubyLexer.create(info); 140 } 141 142 @Override 143 protected LanguageEmbedding<?extends TokenId> embedding(Token<GsfTokenId> token, 144 LanguagePath languagePath, InputAttributes inputAttributes) { 145 GsfTokenId id = token.id(); 146 147 if (id == QUOTED_STRING_LITERAL) { 148 return LanguageEmbedding.create(RubyStringTokenId.languageDouble(), 0, 0); 149 } else if (id == STRING_LITERAL) { 150 return LanguageEmbedding.create(RubyStringTokenId.languageSingle(), 0, 0); 151 } else if ((id == LINE_COMMENT) || (id == BLOCK_COMMENT) || 152 (id == BLOCK_COMMENT_INCOMPLETE)) { 153 return LanguageEmbedding.create(RubyCommentTokenId.language(), 1, 0); 154 155 } else if (id == EMBEDDED_RUBY) { 158 return LanguageEmbedding.create(RubyTokenId.language(), 0, 0); 159 } 160 161 return null; } 163 164 }.language(); 168 169 public RubyTokenId(String name, String fixedText, String primaryCategory) { 170 super(name, fixedText, primaryCategory); 171 } 172 173 public static List <GsfTokenId> getUsedTokens() { 174 List <GsfTokenId> types = new ArrayList <GsfTokenId>(20); 175 types.add(ERROR); 176 types.add(IDENTIFIER); 177 types.add(CLASS_VAR); 178 types.add(INSTANCE_VAR); 179 types.add(GLOBAL_VAR); 180 types.add(CONSTANT); 181 types.add(DOCUMENTATION); 182 types.add(INT_LITERAL); 183 types.add(REGEXP_LITERAL); 184 types.add(LONG_LITERAL); 185 types.add(FLOAT_LITERAL); 186 types.add(DOUBLE_LITERAL); 187 types.add(CHAR_LITERAL); 188 types.add(QUOTED_STRING_LITERAL); 189 types.add(STRING_LITERAL); 190 types.add(WHITESPACE); 191 types.add(LINE_COMMENT); 192 types.add(BLOCK_COMMENT); 193 types.add(TODO); 194 types.add(TYPE_SYMBOL); 195 types.add(EMBEDDED_RUBY); 196 197 types.add(LPAREN); 198 types.add(RPAREN); 199 types.add(LBRACE); 200 types.add(RBRACE); 201 types.add(LBRACKET); 202 types.add(RBRACKET); 203 types.add(STRING_BEGIN); 204 types.add(STRING_END); 205 types.add(REGEXP_BEGIN); 206 types.add(REGEXP_END); 207 208 types.add(DEF); 210 types.add(END); 211 types.add(DO); 212 types.add(BEGIN); 213 types.add(IF); 214 types.add(CLASS); 215 types.add(MODULE); 216 types.add(FOR); 217 types.add(CASE); 218 types.add(LOOP); 219 types.add(WHILE); 220 types.add(UNTIL); 221 types.add(UNLESS); 222 223 types.add(ANY_KEYWORD); 224 types.add(ANY_OPERATOR); 225 226 return types; 227 } 228 229 public static Language<GsfTokenId> language() { 230 return language; 231 } 232 } 233 | Popular Tags |