1 13 package org.netbeans.api.html.lexer; 14 15 import java.util.Collection ; 16 import java.util.EnumSet ; 17 import java.util.Map ; 18 import org.netbeans.api.lexer.InputAttributes; 19 import org.netbeans.api.lexer.Language; 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.lib.html.lexer.HTMLLexer; 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 35 public enum HTMLTokenId implements TokenId { 36 37 38 TEXT("text"), 39 40 SCRIPT("script"), 41 42 WS("ws"), 43 44 ERROR("error"), 45 46 TAG_OPEN("tag"), 47 48 TAG_CLOSE("tag"), 49 50 ARGUMENT("argument"), 51 52 OPERATOR("operator"), 53 54 VALUE("value"), 55 56 BLOCK_COMMENT("block-comment"), 57 58 SGML_COMMENT("sgml-comment"), 59 60 DECLARATION("sgml-declaration"), 61 62 CHARACTER("character"), 63 64 EOL("text"), 65 66 TAG_OPEN_SYMBOL("tag"), 67 68 TAG_CLOSE_SYMBOL("tag"); 69 70 private final String primaryCategory; 71 72 private static final String JAVASCRIPT_MIMETYPE = "text/javascript"; 74 HTMLTokenId(String primaryCategory) { 75 this.primaryCategory = primaryCategory; 76 } 77 78 private static final Language<HTMLTokenId> language = new LanguageHierarchy<HTMLTokenId>() { 79 @Override 80 protected Collection <HTMLTokenId> createTokenIds() { 81 return EnumSet.allOf(HTMLTokenId.class); 82 } 83 84 @Override 85 protected Map <String ,Collection <HTMLTokenId>> createTokenCategories() { 86 return null; 90 } 91 92 @Override 93 protected Lexer<HTMLTokenId> createLexer(LexerRestartInfo<HTMLTokenId> info) { 94 return new HTMLLexer(info); 95 } 96 97 @Override 98 protected LanguageEmbedding embedding( 99 Token<HTMLTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) { 100 if(token.id() == HTMLTokenId.SCRIPT) { 101 Language lang = Language.find(JAVASCRIPT_MIMETYPE); 102 if(lang == null) { 103 return null; } else { 105 return LanguageEmbedding.create(lang, 0, 0); 106 } 107 } else { 108 return null; 109 } 110 } 111 112 @Override 113 protected String mimeType() { 114 return "text/html"; 115 } 116 }.language(); 117 118 123 public static Language<HTMLTokenId> language() { 124 return language; 125 } 126 127 135 public String primaryCategory() { 136 return primaryCategory; 137 } 138 139 } 140 | Popular Tags |