KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rhtml > RhtmlTokenId


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ruby.rhtml;
21
22 import java.util.Collection JavaDoc;
23 import java.util.EnumSet JavaDoc;
24 import java.util.Map JavaDoc;
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 /**
38  * Token Ids for Embedded Ruby (RHTML)
39  *
40  * @author Marek Fukala
41  */

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 JavaDoc primaryCategory;
60
61     RhtmlTokenId(String JavaDoc primaryCategory) {
62         this.primaryCategory = primaryCategory;
63     }
64
65     public String JavaDoc primaryCategory() {
66         return primaryCategory;
67     }
68
69     // Token ids declaration
70
private static final Language<RhtmlTokenId> language = new LanguageHierarchy<RhtmlTokenId>() {
71         protected Collection JavaDoc<RhtmlTokenId> createTokenIds() {
72             return EnumSet.allOf(RhtmlTokenId.class);
73         }
74         
75         protected Map JavaDoc<String JavaDoc,Collection JavaDoc<RhtmlTokenId>> createTokenCategories() {
76             //Map<String,Collection<RhtmlTokenId>> cats = new HashMap<String,Collection<RhtmlTokenId>>();
77
// Additional literals being a lexical error
78
//cats.put("error", EnumSet.of());
79
return null;
80         }
81         
82         public Lexer<RhtmlTokenId> createLexer(LexerRestartInfo<RhtmlTokenId> info) {
83             return new RhtmlLexer(info);
84         }
85         
86         @Override JavaDoc
87         protected LanguageEmbedding embedding(Token<RhtmlTokenId> token,
88                                   LanguagePath languagePath, InputAttributes inputAttributes) {
89             switch(token.id()) {
90                 case TEXT:
91                     // XXX Should I pass in a fourth argument, joinsections=true?
92
return LanguageEmbedding.create(HTMLTokenId.language(), 0, 0);
93                 case SCRIPTLET:
94                     // XXX Should I pass in a fourth argument, joinsections=true?
95
return LanguageEmbedding.create(RubyTokenId.language(), 0, 0);
96                 default:
97                     return null;
98             }
99         }
100         
101         public String JavaDoc 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