001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
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: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039: package org.netbeans.modules.php.editor.lexer;
040:
041: import java.util.Collection;
042: import java.util.EnumSet;
043: import java.util.HashMap;
044: import java.util.Map;
045: import org.netbeans.api.html.lexer.HTMLTokenId;
046: import org.netbeans.api.lexer.InputAttributes;
047: import org.netbeans.api.lexer.Language;
048: import org.netbeans.api.lexer.LanguagePath;
049: import org.netbeans.api.lexer.Token;
050: import org.netbeans.api.lexer.TokenId;
051: import org.netbeans.modules.php.editor.PHPLanguage;
052: import org.netbeans.spi.lexer.LanguageEmbedding;
053: import org.netbeans.spi.lexer.LanguageHierarchy;
054: import org.netbeans.spi.lexer.Lexer;
055: import org.netbeans.spi.lexer.LexerRestartInfo;
056:
057: /**
058: *
059: * @author Petr Pisl
060: */
061: public enum PHPTokenId implements TokenId {
062:
063: T_INLINE_HTML(null, "php"), PHP_OPENTAG(null, "phpopenclose"), //NOI18N
064: T_OPEN_TAG_WITH_ECHO(null, "phpopenclose"), PHP_CLOSETAG(null,
065: "phpopenclose"), //NOI18N
066: PHP_CONTENT(null, "php"), //NOI18N
067: // PHP_RESERVED_WORD(null, "php"),
068: PHP_DIE(null, "keyword"), //NOI18N
069: // PHP_FILE(null, "php"),
070: // PHP_REFERENCE(null, "php"),
071: PHP_SEMICOLON(null, "php"), //NOI18N
072: PHP_CASE(null, "keyword"), //NOI18N
073: PHP_NUMBER(null, "php"), //NOI18N
074: // PHP_DNUMBER(null, "php"),
075: PHP_GLOBAL(null, "keyword"), //NOI18N
076: PHP_ARRAY(null, "keyword"), //NOI18N
077: // PHP_TILDA(null, "php"),
078: PHP_FINAL(null, "keyword"), //NOI18N
079: // PHP_CLASS_C(null, "php"),
080: PHP_PAAMAYIM_NEKUDOTAYIM(null, "php"), //NOI18N
081: PHP_EXTENDS(null, "php"), //NOI18N
082: PHP_VAR_COMMENT(null, "comment"), //NOI18N
083: PHP_USE(null, "php"), //NOI18N
084: // PHP_MINUS_EQUAL(null, "php"),
085: // PHP_INT_CAST(null, "php"),
086: // PHP_BOOLEAN_OR(null, "php"),
087: PHP_INCLUDE(null, "keyword"), //NOI18N
088: PHP_EMPTY(null, "php"), //NOI18N
089: // PHP_XOR_EQUAL(null, "php"),
090: PHP_CLASS("class", "keyword"), //NOI18N
091: // PHP_END_HEREDOC(null, "php"),
092: PHP_FOR("for", "keyword"), //NOI18N
093: PHP_STRING(null, "string"), //NOI18N
094: // PHP_DIV(null, "php"),
095: // PHP_START_HEREDOC(null, "php"),
096: // PHP_AT(null, "php"),
097: PHP_AS(null, "php"), //NOI18N
098: // PHP_STRING_CAST(null, "php"),
099: PHP_TRY("try", "keyword"), //NOI18N
100: PHP_STATIC(null, "keyword"), //NOI18N
101: // PHP_EQUAL(null, "php"),
102: PHP_WHILE("while", "keyword"), //NOI18N
103: // PHP_METHOD_C(null, "php"),
104: // PHP_CLOSE_RECT(null, "php"),
105: // PHP_SR(null, "php"),
106: PHP_ENDFOREACH(null, "keyword"), //NOI18N
107: // PHP_FUNC_C(null, "php"),
108: PHP_EVAL(null, "keyword"), //NOI18N
109: PHP_INSTANCEOF("instanceof", "keyword"), //NOI18N
110: // PHP_OPEN_RECT(null, "php"),
111: // PHP_NEKUDA(null, "php"),
112: // PHP_SL(null, "php"),
113: // PHP_INC(null, "php"),
114: // PHP_KOVA(null, "php"),
115: // PHP_BOOLEAN_AND(null, "php"),
116: PHP_ENDWHILE(null, "keyword"), //NOI18N
117: // PHP_STRING_VARNAME(null, "php"),
118: // PHP_DIV_EQUAL(null, "php"),
119: PHP_BREAK("break", "keyword"), //NOI18N
120: // PHP_DEFINE(null, "php"),
121: // PHP_BACKQUATE(null, "php"),
122: // PHP_AND_EQUAL(null, "php"),
123: PHP_DEFAULT(null, "keyword"), //NOI18N
124: // PHP_SR_EQUAL(null, "php"),
125: PHP_VARIABLE(null, "identifier"), //NOI18N
126: PHP_ABSTRACT(null, "keyword"), //NOI18N
127: // PHP_SL_EQUAL(null, "php"),
128: PHP_PRINT(null, "keyword"), //NOI18N
129: PHP_CURLY_OPEN(null, "php"), //NOI18N
130: PHP_ENDIF("endif", "keyword"), //NOI18N
131: PHP_ELSEIF("elseif", "keyword"), //NOI18N
132: // PHP_MINUS(null, "php"),
133: // PHP_IS_EQUAL(null, "php"),
134: // PHP_UNSET_CAST(null, "php"),
135: PHP_HALT_COMPILER(null, "php"), //NOI18N
136: PHP_INCLUDE_ONCE(null, "keyword"), //NOI18N
137: // PHP_BAD_CHARACTER(null, "php"),
138: // PHP_OBJECT_CAST(null, "php"),
139: // PHP_OR_EQUAL(null, "php"),
140: // PHP_INLINE_HTML(null, "php"),
141: PHP_NEW("new", "keyword"), //NOI18N
142: // PHP_SINGLE_QUATE(null, "php"),
143: PHP_UNSET(null, "keyword"), //NOI18N
144: // PHP_MOD_EQUAL(null, "php"),
145: // PHP_DOLLAR(null, "php"),
146: PHP_ENDSWITCH(null, "keyword"), //NOI18N
147: PHP_FOREACH(null, "keyword"), //NOI18N
148: PHP_IMPLEMENTS(null, "keyword"), //NOI18N
149: // PHP_NEKUDOTAIM(null, "php"),
150: PHP_CLONE(null, "php"), //NOI18N
151: // PHP_EOF(null, "php"),
152: // PHP_PLUS(null, "php"),
153: // PHP_NUM_STRING(null, "php"),
154: PHP_ENDFOR(null, "keyword"), //NOI18N
155: // PHP_IS_SMALLER_OR_EQUAL(null, "php"),
156: PHP_REQUIRE_ONCE(null, "keyword"), //NOI18N
157: // PHP_LNUMBER(null, "php"),
158: PHP_FUNCTION(null, "keyword"), //NOI18N
159: PHP_PROTECTED(null, "keyword"), //NOI18N
160: // PHP_QUATE(null, "php"),
161: PHP_PRIVATE(null, "keyword"), //NOI18N
162: // PHP_IS_NOT_EQUAL(null, "php"),
163: PHP_ENDDECLARE(null, "php"), //NOI18N
164: PHP_CURLY_CLOSE(null, "php"), //NOI18N
165: // PHP_PRECENT(null, "php"),
166: // PHP_PLUS_EQUAL(null, "php"),
167: // PHP_error(null, "php"),
168: PHP_ELSE("else", "keyword"), //NOI18N
169: PHP_DO(null, "keyword"), //NOI18N
170: // PHP_RGREATER(null, "php"),
171: PHP_CONTINUE(null, "keyword"), //NOI18N
172: // PHP_IS_IDENTICAL(null, "php"),
173: PHP_ECHO(null, "keyword"), //NOI18N
174: // PHP_DOUBLE_ARROW(null, "php"),
175: // PHP_CHARACTER(null, "php"),
176: // PHP_TIMES(null, "php"),
177: PHP_REQUIRE(null, "keyword"), //NOI18N
178: // PHP_ARRAY_CAST(null, "php"),
179: PHP_CONSTANT_ENCAPSED_STRING(null, "string"), //NOI18N
180: PHP_ENCAPSED_AND_WHITESPACE(null, "string"), //NOI18N
181: WHITESPACE(null, "whitespace"), //NOI18N
182: PHP_SWITCH("switch", "keyword"), //NOI18N
183: // PHP_DOUBLE_CAST(null, "php"),
184: // PHP_LINE(null, "php"),
185: // PHP_BOOL_CAST(null, "php"),
186: PHP_CONST(null, "keyword"), //NOI18N
187: PHP_PUBLIC(null, "keyword"), //NOI18N
188: PHP_RETURN(null, "keyword"), //NOI18N
189: // PHP_IS_NOT_IDENTICAL(null, "php"),
190: // PHP_IS_GREATER_OR_EQUAL(null, "php"),
191: PHP_LOGICAL_AND(null, "operator"), //NOI18N
192: PHP_INTERFACE(null, "keyword"), //NOI18N
193: PHP_EXIT(null, "keyword"), //NOI18N
194: // PHP_DOLLAR_OPEN_CURLY_BRACES(null, "php"),
195: PHP_LOGICAL_OR(null, "operator"), //NOI18N
196: // PHP_CLOSE_PARENTHESE(null, "php"),
197: PHP_NOT(null, "operator"), //NOI18N
198: // PHP_CONCAT_EQUAL(null, "php"),
199: PHP_LOGICAL_XOR(null, "php"), //NOI18N
200: PHP_ISSET(null, "php"), //NOI18N
201: // PHP_QUESTION_MARK(null, "php"),
202: // PHP_OPEN_PARENTHESE(null, "php"),
203: PHP_LIST(null, "php"), //NOI18N
204: // PHP_OR(null, "php"),
205: // PHP_COMMA(null, "php"),
206: PHP_CATCH(null, "php"), //NOI18N
207: // PHP_DEC(null, "php"),
208: // PHP_MUL_EQUAL(null, "php"),
209: PHP_VAR("var", "keyword"), //NOI18N
210: PHP_THROW(null, "keyword"), //NOI18N
211: // PHP_LGREATER(null, "php"),
212: PHP_IF("if", "keyword"), //NOI18N
213: PHP_DECLARE(null, "php"), //NOI18N
214: PHP_OBJECT_OPERATOR(null, "php"), //NOI18N
215: PHP_SELF(null, "php"), //NOI18N
216: PHPDOC_VAR(null, "phpdockeyword"), //NOI18N
217: PHPDOC_SEE(null, "phpdockeyword"), //NOI18N
218: PHP_COMMENT(null, "comment"), //NOI18N
219: PHP_COMMENT_START(null, "comment"), //NOI18N
220: PHP_COMMENT_END(null, "comment"), //NOI18N
221: PHP_LINE_COMMENT(null, "comment"), //NOI18N
222: PHPDOC_COMMENT(null, "comment"), //NOI18N
223: PHPDOC_COMMENT_START(null, "comment"), //NOI18N
224: PHPDOC_COMMENT_END(null, "comment"), //NOI18N
225: PHPDOC_NAME(null, "phpdockeyword"), //NOI18N
226: PHPDOC_DESC(null, "phpdockeyword"), //NOI18N
227: PHPDOC_TODO(null, "phpdockeyword"), //NOI18N
228: PHPDOC_LINK(null, "phpdockeyword"), //NOI18N
229: PHPDOC_EXAMPLE(null, "phpdockeyword"), //NOI18N
230: PHPDOC_LICENSE(null, "phpdockeyword"), //NOI18N
231: PHPDOC_PACKAGE(null, "phpdockeyword"), //NOI18N
232: PHPDOC_VERSION(null, "phpdockeyword"), //NOI18N
233: PHPDOC_ABSTRACT(null, "phpdockeyword"), //NOI18N
234: PHPDOC_INTERNAL(null, "phpdockeyword"), //NOI18N
235: PHPDOC_TUTORIAL(null, "phpdockeyword"), //NOI18N
236: PHPDOC_METHOD(null, "phpdockeyword"), //NOI18N
237: PHPDOC_PROPERTY(null, "phpdockeyword"), //NOI18N
238: PHPDOC_USES(null, "phpdockeyword"), //NOI18N
239: PHPDOC_CATEGORY(null, "phpdockeyword"), //NOI18N
240: UNKNOWN_TOKEN(null, "error"), //NOI18N
241: PHPDOC_FINAL(null, "phpdockeyword"), //NOI18N
242: PHPDOC_SINCE(null, "phpdockeyword"), //NOI18N
243: PHPDOC_PARAM(null, "phpdockeyword"), //NOI18N
244: PHPDOC_MAGIC(null, "phpdockeyword"), //NOI18N
245: PHPDOC_RETURN(null, "phpdockeyword"), //NOI18N
246: PHPDOC_AUTHOR(null, "phpdockeyword"), //NOI18N
247: PHPDOC_ACCESS(null, "phpdockeyword"), //NOI18N
248: PHPDOC_IGNORE(null, "phpdockeyword"), //NOI18N
249: PHPDOC_THROWS(null, "phpdockeyword"), //NOI18N
250: PHPDOC_STATIC(null, "phpdockeyword"), //NOI18N
251: PHPDOC_GLOBAL(null, "phpdockeyword"), //NOI18N
252: PHPDOC_SUBPACKAGE(null, "phpdockeyword"), //NOI18N
253: PHPDOC_FILESOURCE(null, "phpdockeyword"), //NOI18N
254: PHPDOC_EXCEPTION(null, "phpdockeyword"), //NOI18N
255: PHPDOC_COPYRIGHT(null, "phpdockeyword"), //NOI18N
256: PHPDOC_STATICVAR(null, "phpdockeyword"), //NOI18N
257: PHPDOC_DEPRECATED(null, "phpdockeyword"), //NOI18N
258: PHP_HEREDOC_TAG(null, "php"), //NOI18N
259: PHP_TOKEN(null, "php"), //NOI18N
260: PHP__FUNCTION__(null, "php"), //NOI18N
261: PHP_CASTING(null, "php"), //NOI18N
262: PHP__FILE__(null, "php"), //NOI18N
263: PHP__LINE__(null, "php"), //NOI18N
264: PHP_OPERATOR(null, "php"), //NOI18N
265: PHP_PARENT(null, "php"), //NOI18N
266: PHP__CLASS__(null, "php"), //NOI18N
267: PHP__METHOD__(null, "php"), //NOI18N
268: PHP_FROM(null, "php"), //NOI18N
269: PHP_TRUE(null, "php"), //NOI18N
270: PHP_FALSE(null, "php"), //NOI18N
271: TASK(null, "php"); //NOI18N
272:
273: private final String fixedText;
274: private final String primaryCategory;
275:
276: PHPTokenId(String fixedText, String primaryCategory) {
277: this .fixedText = fixedText;
278: this .primaryCategory = primaryCategory;
279: }
280:
281: public String fixedText() {
282: return fixedText;
283: }
284:
285: public String primaryCategory() {
286: return primaryCategory;
287: }
288:
289: private static final Language<PHPTokenId> language = new LanguageHierarchy<PHPTokenId>() {
290:
291: @Override
292: protected Collection<PHPTokenId> createTokenIds() {
293: return EnumSet.allOf(PHPTokenId.class);
294: }
295:
296: @Override
297: protected Map<String, Collection<PHPTokenId>> createTokenCategories() {
298: Map<String, Collection<PHPTokenId>> cats = new HashMap<String, Collection<PHPTokenId>>();
299: return cats;
300: }
301:
302: @Override
303: protected Lexer<PHPTokenId> createLexer(
304: LexerRestartInfo<PHPTokenId> info) {
305: return GSFPHPLexer.create(info);
306: }
307:
308: @Override
309: protected String mimeType() {
310: return PHPLanguage.PHP_MIME_TYPE;
311: }
312:
313: // unfortunately this doesn't work correctly
314: /*@Override
315: protected LanguageEmbedding<?> embedding(Token<PHPTokenId> token,
316: LanguagePath languagePath, InputAttributes inputAttributes) {
317: PHPTokenId id = token.id();
318:
319: if (id == T_INLINE_HTML) {
320: return LanguageEmbedding.create(HTMLTokenId.language(), 0, 0);
321: }
322:
323: return null; // No embedding
324: }*/
325:
326: }.language();
327:
328: public static Language<PHPTokenId> language() {
329: return language;
330: }
331: }
|