001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
011: * Microsystems, Inc. All Rights Reserved.
012:
013: If you wish your version of this file to be governed by only the CDDL
014: or only the GPL Version 2, indicate your decision by adding
015: "[Contributor] elects to include this software in this distribution
016: under the [CDDL or GPL Version 2] license." If you do not indicate a
017: single choice of license, a recipient has the option to distribute
018: your version of this file under either the CDDL, the GPL Version 2 or
019: to extend the choice of license to its licensees as provided above.
020: However, if you add GPL Version 2 code and therefore, elected the GPL
021: Version 2 license, then the option applies only if the new code is
022: made subject to such option by the copyright holder.
023:
024: If you wish your version of this file to be governed by only the CDDL
025: or only the GPL Version 2, indicate your decision by adding
026: "[Contributor] elects to include this software in this distribution
027: under the [CDDL or GPL Version 2] license." If you do not indicate a
028: single choice of license, a recipient has the option to distribute
029: your version of this file under either the CDDL, the GPL Version 2 or
030: to extend the choice of license to its licensees as provided above.
031: However, if you add GPL Version 2 code and therefore, elected the GPL
032: Version 2 license, then the option applies only if the new code is
033: made subject to such option by the copyright holder.
034: */
035: package org.netbeans.api.xml.lexer;
036:
037: import java.util.Collection;
038: import java.util.EnumSet;
039: import java.util.HashMap;
040: import java.util.Map;
041: import org.netbeans.api.lexer.InputAttributes;
042: import org.netbeans.api.lexer.Language;
043: import org.netbeans.api.lexer.LanguagePath;
044: import org.netbeans.api.lexer.Token;
045: import org.netbeans.api.lexer.TokenId;
046: import org.netbeans.lib.xml.lexer.XMLLexer;
047: import org.netbeans.spi.lexer.LanguageEmbedding;
048: import org.netbeans.spi.lexer.LanguageHierarchy;
049: import org.netbeans.spi.lexer.Lexer;
050: import org.netbeans.spi.lexer.LexerRestartInfo;
051:
052: /**
053: * Token ids of XML language
054: */
055: public enum XMLTokenId implements TokenId {
056:
057: /** Plain text */
058: TEXT("xml-text"),
059: /** Erroneous Text */
060: WS("xml-ws"),
061: /** Plain Text*/
062: ERROR("xml-error"),
063: /** XML Tag */
064: TAG("xml-tag"),
065: /** Argument of a tag */
066: ARGUMENT("xml-attribute"),
067: /** Operators - '=' between arg and value */
068: OPERATOR("xml-operator"),
069: /** Value - value of an argument */
070: VALUE("xml-value"),
071: /** Block comment */
072: BLOCK_COMMENT("xml-comment"),
073: /** SGML declaration in XML document - e.g. <!DOCTYPE> */
074: DECLARATION("xml-doctype"),
075: /** Character reference, e.g. &lt; = < */
076: CHARACTER("xml-ref"),
077: /** End of line */
078: EOL("xml-EOL"),
079: /* PI start delimiter <sample><b><?</b>target content of pi ?></sample> */
080: PI_START("xml-pi-start"),
081: /* PI target <sample><?<b>target</b> content of pi ?></sample> */
082: PI_TARGET("xml-pi-target"),
083: /* PI conetnt <sample><?target <b>content of pi </b>?></sample> */
084: PI_CONTENT("pi-content"),
085: /* PI end delimiter <sample><?target <content of pi <b>?></b></sample> */
086: PI_END("pi-end"),
087: /** Cdata section including its delimiters. */
088: CDATA_SECTION("xml-cdata-section");
089:
090: private final String primaryCategory;
091:
092: XMLTokenId() {
093: this (null);
094: }
095:
096: XMLTokenId(String primaryCategory) {
097: this .primaryCategory = primaryCategory;
098: }
099:
100: public String primaryCategory() {
101: return primaryCategory;
102: }
103:
104: private static final Language<XMLTokenId> language = new LanguageHierarchy<XMLTokenId>() {
105: @Override
106: protected Collection<XMLTokenId> createTokenIds() {
107: return EnumSet.allOf(XMLTokenId.class);
108: }
109:
110: @Override
111: protected Map<String, Collection<XMLTokenId>> createTokenCategories() {
112: Map<String, Collection<XMLTokenId>> cats = new HashMap<String, Collection<XMLTokenId>>();
113:
114: // Incomplete literals
115: //cats.put("incomplete", EnumSet.of());
116: // Additional literals being a lexical error
117: //cats.put("error", EnumSet.of());
118:
119: return cats;
120: }
121:
122: @Override
123: public Lexer<XMLTokenId> createLexer(
124: LexerRestartInfo<XMLTokenId> info) {
125: return new XMLLexer(info);
126: }
127:
128: @Override
129: public LanguageEmbedding<?> embedding(Token<XMLTokenId> token,
130: LanguagePath languagePath,
131: InputAttributes inputAttributes) {
132: return null; // No embedding
133: }
134:
135: @Override
136: public String mimeType() {
137: return "text/xml";
138: }
139: }.language();
140:
141: public static Language<XMLTokenId> language() {
142: return language;
143: }
144:
145: }
|