1 19 package org.netbeans.modules.ruby.lexer; 20 21 import java.util.Collection ; 22 import java.util.EnumSet ; 23 import java.util.Map ; 24 25 import org.netbeans.modules.ruby.lexer.RubyStringLexer; 26 import org.netbeans.modules.ruby.lexer.RubyTokenId; 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 44 public enum RubyStringTokenId implements TokenId { 45 STRING_TEXT("string"), 46 STRING_ESCAPE("string-escape"), 47 STRING_INVALID("string-escape-invalid"), 48 EMBEDDED_RUBY("string"); 49 50 private final String primaryCategory; 51 52 RubyStringTokenId() { 53 this(null); 54 } 55 56 RubyStringTokenId(String primaryCategory) { 57 this.primaryCategory = primaryCategory; 58 } 59 60 public String primaryCategory() { 61 return primaryCategory; 62 } 63 64 65 private static final Language<RubyStringTokenId> languageDouble = 66 new LanguageHierarchy<RubyStringTokenId>() { 67 @Override 68 protected Collection <RubyStringTokenId> createTokenIds() { 69 return EnumSet.allOf(RubyStringTokenId.class); 70 } 71 72 @Override 73 protected Map <String , Collection <RubyStringTokenId>> createTokenCategories() { 74 return null; } 76 77 @Override 78 protected Lexer<RubyStringTokenId> createLexer( 79 LexerRestartInfo<RubyStringTokenId> info) { 80 return new RubyStringLexer(info, true); 81 } 82 83 @Override 84 protected LanguageEmbedding<? extends TokenId> embedding(Token<RubyStringTokenId> token, 85 LanguagePath languagePath, InputAttributes inputAttributes) { 86 RubyStringTokenId id = token.id(); 87 88 if (id == EMBEDDED_RUBY) { 89 return LanguageEmbedding.create(RubyTokenId.language(), 0, 0); 90 } 91 92 return null; } 94 95 @Override 96 public String mimeType() { 97 return "text/x-ruby-string-double"; 98 } 99 }.language(); 100 101 102 private static final Language<RubyStringTokenId> languageSingle = 103 new LanguageHierarchy<RubyStringTokenId>() { 104 @Override 105 protected Collection <RubyStringTokenId> createTokenIds() { 106 return EnumSet.allOf(RubyStringTokenId.class); 107 } 108 109 @Override 110 protected Map <String , Collection <RubyStringTokenId>> createTokenCategories() { 111 return null; } 113 114 @Override 115 protected Lexer<RubyStringTokenId> createLexer( 116 LexerRestartInfo<RubyStringTokenId> info) { 117 return new RubyStringLexer(info, false); 118 } 119 120 @Override 121 protected LanguageEmbedding<? extends TokenId> embedding(Token<RubyStringTokenId> token, 122 LanguagePath languagePath, InputAttributes inputAttributes) { 123 RubyStringTokenId id = token.id(); 124 125 if (id == EMBEDDED_RUBY) { 126 return LanguageEmbedding.create(RubyTokenId.language(), 0, 0); 127 } 128 129 return null; } 131 132 @Override 133 public String mimeType() { 134 return "text/x-ruby-string-single"; 135 } 136 }.language(); 137 138 public static Language<RubyStringTokenId> languageDouble() { 139 return languageDouble; 140 } 141 142 public static Language<RubyStringTokenId> languageSingle() { 143 return languageSingle; 144 } 145 } 146 | Popular Tags |