2
* Sun Public License Notice
4
* The contents of this file are subject to the Sun Public License
5
* Version 1.0 (the "License"). You may not use this file except in
6
* compliance with the License. A copy of the License is available at
9
* The Original Code is NetBeans. The Initial Developer of the Original
10
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
* Microsystems, Inc. All Rights Reserved.
13
If you wish your version of this file to be governed by only the CDDL
14
or only the GPL Version 2, indicate your decision by adding
15
"[Contributor] elects to include this software in this distribution
16
under the [CDDL or GPL Version 2] license." If you do not indicate a
17
single choice of license, a recipient has the option to distribute
18
your version of this file under either the CDDL, the GPL Version 2 or
19
to extend the choice of license to its licensees as provided above.
20
However, if you add GPL Version 2 code and therefore, elected the GPL
21
Version 2 license, then the option applies only if the new code is
22
made subject to such option by the copyright holder.
24
If you wish your version of this file to be governed by only the CDDL
25
or only the GPL Version 2, indicate your decision by adding
26
"[Contributor] elects to include this software in this distribution
27
under the [CDDL or GPL Version 2] license." If you do not indicate a
28
single choice of license, a recipient has the option to distribute
29
your version of this file under either the CDDL, the GPL Version 2 or
30
to extend the choice of license to its licensees as provided above.
31
However, if you add GPL Version 2 code and therefore, elected the GPL
32
Version 2 license, then the option applies only if the new code is
33
made subject to such option by the copyright holder.
35
package org.netbeans.api.xml.lexer;
37
import java.util.Collection;
38
import java.util.EnumSet;
39
import java.util.HashMap;
41
import org.netbeans.api.lexer.InputAttributes;
42
import org.netbeans.api.lexer.Language;
43
import org.netbeans.api.lexer.LanguagePath;
44
import org.netbeans.api.lexer.Token;
45
import org.netbeans.api.lexer.TokenId;
46
import org.netbeans.lib.xml.lexer.XMLLexer;
47
import org.netbeans.spi.lexer.LanguageEmbedding;
48
import org.netbeans.spi.lexer.LanguageHierarchy;
49
import org.netbeans.spi.lexer.Lexer;
50
import org.netbeans.spi.lexer.LexerRestartInfo;
53
* Token ids of XML language
55
public enum XMLTokenId implements TokenId {
65
/** Argument of a tag */
66
ARGUMENT("xml-attribute"),
67
/** Operators - '=' between arg and value */
68
OPERATOR("xml-operator"),
69
/** Value - value of an argument */
72
BLOCK_COMMENT("xml-comment"),
73
/** SGML declaration in XML document - e.g. <!DOCTYPE> */
74
DECLARATION("xml-doctype"),
75
/** Character reference, e.g. &lt; = < */
79
/* PI start delimiter <sample><b><?</b>target content of pi ?></sample> */
80
PI_START("xml-pi-start"),
81
/* PI target <sample><?<b>target</b> content of pi ?></sample> */
82
PI_TARGET("xml-pi-target"),
83
/* PI conetnt <sample><?target <b>content of pi </b>?></sample> */
84
PI_CONTENT("pi-content"),
85
/* PI end delimiter <sample><?target <content of pi <b>?></b></sample> */
87
/** Cdata section including its delimiters. */
88
CDATA_SECTION("xml-cdata-section");
90
private final String primaryCategory;
96
XMLTokenId(String primaryCategory) {
97
this.primaryCategory = primaryCategory;
100
public String primaryCategory() {
101
return primaryCategory;
104
private static final Language<XMLTokenId> language = new LanguageHierarchy<XMLTokenId>() {
106
protected Collection<XMLTokenId> createTokenIds() {
107
return EnumSet.allOf(XMLTokenId.class);
111
protected Map<String,Collection<XMLTokenId>> createTokenCategories() {
112
Map<String,Collection<XMLTokenId>> cats = new HashMap<String,Collection<XMLTokenId>>();
114
// Incomplete literals
115
//cats.put("incomplete", EnumSet.of());
116
// Additional literals being a lexical error
117
//cats.put("error", EnumSet.of());
123
public Lexer<XMLTokenId> createLexer(LexerRestartInfo<XMLTokenId> info) {
124
return new XMLLexer(info);
128
public LanguageEmbedding<?> embedding(
129
Token<XMLTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) {
130
return null; // No embedding
134
public String mimeType() {
139
public static Language<XMLTokenId> language() {