1 19 20 package org.netbeans.modules.ruby.rhtml; 21 22 import java.util.Collection ; 23 import java.util.EnumSet ; 24 import java.util.Map ; 25 import org.netbeans.modules.ruby.lexer.RubyTokenId; 26 import org.netbeans.api.html.lexer.HTMLTokenId; 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.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 42 43 public enum RhtmlTokenId implements TokenId { 44 45 TEXT("text"), 46 SCRIPTLET("scriptlet"), 47 ERROR("error"), 48 TAG("tag-directive"), 49 SYMBOL("symbol"), 50 SYMBOL2("scriptlet-delimiter"), 51 COMMENT("comment"), 52 ATTRIBUTE("attribute-name"), 53 ATTR_VALUE("attribute-value"), 54 EOL("EOL"), 55 WHITESPACE("whitespace"), 56 EL("expression-language"); 57 58 59 private final String primaryCategory; 60 61 RhtmlTokenId(String primaryCategory) { 62 this.primaryCategory = primaryCategory; 63 } 64 65 public String primaryCategory() { 66 return primaryCategory; 67 } 68 69 private static final Language<RhtmlTokenId> language = new LanguageHierarchy<RhtmlTokenId>() { 71 protected Collection <RhtmlTokenId> createTokenIds() { 72 return EnumSet.allOf(RhtmlTokenId.class); 73 } 74 75 protected Map <String ,Collection <RhtmlTokenId>> createTokenCategories() { 76 return null; 80 } 81 82 public Lexer<RhtmlTokenId> createLexer(LexerRestartInfo<RhtmlTokenId> info) { 83 return new RhtmlLexer(info); 84 } 85 86 @Override 87 protected LanguageEmbedding embedding(Token<RhtmlTokenId> token, 88 LanguagePath languagePath, InputAttributes inputAttributes) { 89 switch(token.id()) { 90 case TEXT: 91 return LanguageEmbedding.create(HTMLTokenId.language(), 0, 0); 93 case SCRIPTLET: 94 return LanguageEmbedding.create(RubyTokenId.language(), 0, 0); 96 default: 97 return null; 98 } 99 } 100 101 public String mimeType() { 102 return RhtmlKit.RHTML_MIME_TYPE; 103 } 104 }.language(); 105 106 public static Language<RhtmlTokenId> language() { 107 return language; 108 } 109 } 110 | Popular Tags |