001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 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: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.cnd.editor.cplusplus;
043:
044: import java.util.HashMap;
045: import org.netbeans.editor.BaseTokenCategory;
046: import org.netbeans.editor.BaseTokenID;
047: import org.netbeans.editor.TokenID;
048: import org.netbeans.editor.BaseImageTokenID;
049: import org.netbeans.editor.TokenContext;
050: import org.netbeans.editor.TokenContextPath;
051:
052: /**
053: * CC token-context defines token-ids and token-categories
054: * used in CC language.
055: */
056: public class CCTokenContext extends TokenContext {
057:
058: // Token category-ids
059: public static final int KEYWORDS_ID = 1;
060: public static final int OPERATORS_ID = KEYWORDS_ID + 1;
061: public static final int NUMERIC_LITERALS_ID = OPERATORS_ID + 1;
062: public static final int ERRORS_ID = NUMERIC_LITERALS_ID + 1;
063: // XXX: need to use CPP_ID somewhere to get special highlighting
064: public static final int CPP_ID = ERRORS_ID + 1;
065:
066: // Numeric-ids for token-ids
067: public static final int WHITESPACE_ID = CPP_ID + 1;
068: public static final int IDENTIFIER_ID = WHITESPACE_ID + 1;
069: public static final int LINE_COMMENT_ID = IDENTIFIER_ID + 1;
070: public static final int BLOCK_COMMENT_ID = LINE_COMMENT_ID + 1;
071: public static final int CHAR_LITERAL_ID = BLOCK_COMMENT_ID + 1;
072: public static final int STRING_LITERAL_ID = CHAR_LITERAL_ID + 1;
073: public static final int INT_LITERAL_ID = STRING_LITERAL_ID + 1;
074: public static final int LONG_LITERAL_ID = INT_LITERAL_ID + 1;
075: public static final int HEX_LITERAL_ID = LONG_LITERAL_ID + 1;
076: public static final int OCTAL_LITERAL_ID = HEX_LITERAL_ID + 1;
077: public static final int FLOAT_LITERAL_ID = OCTAL_LITERAL_ID + 1;
078: public static final int DOUBLE_LITERAL_ID = FLOAT_LITERAL_ID + 1;
079: public static final int BACKSLASH_ID = DOUBLE_LITERAL_ID + 1;
080: public static final int LINE_CONTINUATION_ID = BACKSLASH_ID + 1; // not used
081:
082: // Operator numeric-ids
083: public static final int HASH_ID = LINE_CONTINUATION_ID + 1; // #
084: public static final int DOUBLE_HASH_ID = HASH_ID + 1; // ##
085: public static final int EQ_ID = DOUBLE_HASH_ID + 1; // =
086: public static final int LT_ID = EQ_ID + 1; // <
087: public static final int GT_ID = LT_ID + 1; // >
088: public static final int LSHIFT_ID = GT_ID + 1; // <<
089: public static final int RSSHIFT_ID = LSHIFT_ID + 1; // >>
090: public static final int PLUS_ID = RSSHIFT_ID + 1; // +
091: public static final int MINUS_ID = PLUS_ID + 1; // -
092: public static final int MUL_ID = MINUS_ID + 1; // *
093: public static final int DIV_ID = MUL_ID + 1; // /
094: public static final int AND_ID = DIV_ID + 1; // &
095: public static final int OR_ID = AND_ID + 1; // |
096: public static final int XOR_ID = OR_ID + 1; // ^
097: public static final int MOD_ID = XOR_ID + 1; // %
098: public static final int NOT_ID = MOD_ID + 1; // !
099: public static final int NEG_ID = NOT_ID + 1; // ~
100: public static final int EQ_EQ_ID = NEG_ID + 1; // ==
101: public static final int LT_EQ_ID = EQ_EQ_ID + 1; // <=
102: public static final int GT_EQ_ID = LT_EQ_ID + 1; // >=
103: public static final int LSHIFT_EQ_ID = GT_EQ_ID + 1; // <<=
104: public static final int RSSHIFT_EQ_ID = LSHIFT_EQ_ID + 1; // >>=
105: public static final int PLUS_EQ_ID = RSSHIFT_EQ_ID + 1; // +=
106: public static final int MINUS_EQ_ID = PLUS_EQ_ID + 1; // -=
107: public static final int ARROW_ID = MINUS_EQ_ID + 1; // ->
108: public static final int ARROWMBR_ID = ARROW_ID + 1; // ->*
109: public static final int MUL_EQ_ID = ARROWMBR_ID + 1; // *=
110: public static final int DIV_EQ_ID = MUL_EQ_ID + 1; // /=
111: public static final int AND_EQ_ID = DIV_EQ_ID + 1; // &=
112: public static final int OR_EQ_ID = AND_EQ_ID + 1; // |=
113: public static final int XOR_EQ_ID = OR_EQ_ID + 1; // ^=
114: public static final int MOD_EQ_ID = XOR_EQ_ID + 1; // %=
115: public static final int NOT_EQ_ID = MOD_EQ_ID + 1; // !=
116: public static final int DOT_ID = NOT_EQ_ID + 1; // .
117: public static final int DOTMBR_ID = DOT_ID + 1; // .*
118: public static final int COMMA_ID = DOTMBR_ID + 1; // ,
119: public static final int COLON_ID = COMMA_ID + 1; // :
120: public static final int SCOPE_ID = COLON_ID + 1; // ::
121: public static final int SEMICOLON_ID = SCOPE_ID + 1; // ;
122: public static final int QUESTION_ID = SEMICOLON_ID + 1; // ?
123: public static final int LPAREN_ID = QUESTION_ID + 1; // (
124: public static final int RPAREN_ID = LPAREN_ID + 1; // )
125: public static final int LBRACKET_ID = RPAREN_ID + 1; // [
126: public static final int RBRACKET_ID = LBRACKET_ID + 1; // ]
127: public static final int LBRACE_ID = RBRACKET_ID + 1; // {
128: public static final int RBRACE_ID = LBRACE_ID + 1; // }
129: public static final int PLUS_PLUS_ID = RBRACE_ID + 1; // ++
130: public static final int MINUS_MINUS_ID = PLUS_PLUS_ID + 1; // --
131: public static final int AND_AND_ID = MINUS_MINUS_ID + 1; // &&
132: public static final int OR_OR_ID = AND_AND_ID + 1; // ||
133:
134: // Data type keyword numeric-ids
135: public static final int ASM_ID = OR_OR_ID + 1;
136: public static final int AUTO_ID = ASM_ID + 1;
137: public static final int BOOLEAN_ID = AUTO_ID + 1;
138: public static final int CHAR_ID = BOOLEAN_ID + 1;
139: public static final int DOUBLE_ID = CHAR_ID + 1;
140: public static final int ENUM_ID = DOUBLE_ID + 1;
141: public static final int EXPORT_ID = ENUM_ID + 1;
142: public static final int FLOAT_ID = EXPORT_ID + 1;
143: public static final int INLINE_ID = FLOAT_ID + 1;
144: public static final int INT_ID = INLINE_ID + 1;
145: public static final int LONG_ID = INT_ID + 1;
146: public static final int MUTABLE_ID = LONG_ID + 1;
147: public static final int REGISTER_ID = MUTABLE_ID + 1;
148: public static final int SHORT_ID = REGISTER_ID + 1;
149: public static final int SIGNED_ID = SHORT_ID + 1;
150: public static final int STRUCT_ID = SIGNED_ID + 1;
151: public static final int TYPEDEF_ID = STRUCT_ID + 1;
152: public static final int TYPEID_ID = TYPEDEF_ID + 1;
153: public static final int TYPENAME_ID = TYPEID_ID + 1;
154: public static final int TYPEOF_ID = TYPENAME_ID + 1;
155: public static final int UNSIGNED_ID = TYPEOF_ID + 1;
156:
157: // Void type keyword numeric-id
158: public static final int VOID_ID = UNSIGNED_ID + 1;
159: public static final int WCHAR_T_ID = VOID_ID + 1;
160: public static final int UNION_ID = WCHAR_T_ID + 1;
161:
162: // Other keywords numeric-ids
163: public static final int BREAK_ID = UNION_ID + 1;
164: public static final int CASE_ID = BREAK_ID + 1;
165: public static final int CATCH_ID = CASE_ID + 1;
166: public static final int CLASS_ID = CATCH_ID + 1;
167: public static final int CONST_ID = CLASS_ID + 1;
168: public static final int CONTINUE_ID = CONST_ID + 1;
169: public static final int DEFAULT_ID = CONTINUE_ID + 1;
170: public static final int DELETE_ID = DEFAULT_ID + 1;
171: public static final int DO_ID = DELETE_ID + 1;
172: public static final int ELSE_ID = DO_ID + 1;
173: public static final int EXPLICIT_ID = ELSE_ID + 1;
174: public static final int EXTERN_ID = EXPLICIT_ID + 1;
175: public static final int FALSE_ID = EXTERN_ID + 1;
176: public static final int FOR_ID = FALSE_ID + 1;
177: public static final int FRIEND_ID = FOR_ID + 1;
178: public static final int GOTO_ID = FRIEND_ID + 1;
179: public static final int IF_ID = GOTO_ID + 1;
180: public static final int NAMESPACE_ID = IF_ID + 1;
181: public static final int NEW_ID = NAMESPACE_ID + 1;
182: public static final int NULL_ID = NEW_ID + 1;
183: public static final int OPERATOR_ID = NULL_ID + 1;
184: public static final int PRIVATE_ID = OPERATOR_ID + 1;
185: public static final int PROTECTED_ID = PRIVATE_ID + 1;
186: public static final int PUBLIC_ID = PROTECTED_ID + 1;
187: public static final int RETURN_ID = PUBLIC_ID + 1;
188: public static final int SIZEOF_ID = RETURN_ID + 1;
189: public static final int STATIC_ID = SIZEOF_ID + 1;
190: public static final int SWITCH_ID = STATIC_ID + 1;
191: public static final int TEMPLATE_ID = SWITCH_ID + 1;
192: public static final int THIS_ID = TEMPLATE_ID + 1;
193: public static final int THROW_ID = THIS_ID + 1;
194: public static final int TRUE_ID = THROW_ID + 1;
195: public static final int TRY_ID = TRUE_ID + 1;
196: public static final int USING_ID = TRY_ID + 1;
197: public static final int VIRTUAL_ID = USING_ID + 1;
198: public static final int VOLATILE_ID = VIRTUAL_ID + 1;
199: public static final int WHILE_ID = VOLATILE_ID + 1;
200:
201: public static final int DYNAMIC_CAST_ID = WHILE_ID + 1;
202: public static final int STATIC_CAST_ID = DYNAMIC_CAST_ID + 1;
203: public static final int REINTERPRET_CAST_ID = STATIC_CAST_ID + 1;
204: public static final int CONST_CAST_ID = REINTERPRET_CAST_ID + 1;
205:
206: // New C keywords
207: public static final int RESTRICT_ID = CONST_CAST_ID + 1;
208: public static final int _BOOL_ID = RESTRICT_ID + 1;
209: public static final int _COMPLEX_ID = _BOOL_ID + 1;
210: public static final int _IMAGINARY_ID = _COMPLEX_ID + 1;
211:
212: // Preprocessor directives
213: public static final int CPPDEFINE_ID = _IMAGINARY_ID + 1;
214: public static final int CPPELIF_ID = CPPDEFINE_ID + 1;
215: public static final int CPPELSE_ID = CPPELIF_ID + 1;
216: public static final int CPPENDIF_ID = CPPELSE_ID + 1;
217: public static final int CPPERROR_ID = CPPENDIF_ID + 1;
218: public static final int CPPIF_ID = CPPERROR_ID + 1;
219: public static final int CPPIFDEF_ID = CPPIF_ID + 1;
220: public static final int CPPIFNDEF_ID = CPPIFDEF_ID + 1;
221: public static final int CPPINCLUDE_ID = CPPIFNDEF_ID + 1;
222: public static final int CPPINCLUDE_NEXT_ID = CPPINCLUDE_ID + 1;
223: public static final int CPPLINE_ID = CPPINCLUDE_NEXT_ID + 1;
224: public static final int CPPPRAGMA_ID = CPPLINE_ID + 1;
225: public static final int CPPUNDEF_ID = CPPPRAGMA_ID + 1;
226: public static final int CPPWARNING_ID = CPPUNDEF_ID + 1;
227: public static final int CPPIDENTIFIER_ID = CPPWARNING_ID + 1; // not recognized # id
228:
229: // include directives
230: public static final int SYS_INCLUDE_ID = CPPIDENTIFIER_ID + 1; // <filename>
231: public static final int USR_INCLUDE_ID = SYS_INCLUDE_ID + 1; // "filename"
232:
233: // Incomplete tokens
234: public static final int INCOMPLETE_STRING_LITERAL_ID = USR_INCLUDE_ID + 1;
235: public static final int INCOMPLETE_CHAR_LITERAL_ID = INCOMPLETE_STRING_LITERAL_ID + 1;
236: public static final int INCOMPLETE_HEX_LITERAL_ID = INCOMPLETE_CHAR_LITERAL_ID + 1;
237: public static final int INVALID_CHAR_ID = INCOMPLETE_HEX_LITERAL_ID + 1;
238: public static final int INVALID_OPERATOR_ID = INVALID_CHAR_ID + 1;
239: public static final int INVALID_OCTAL_LITERAL_ID = INVALID_OPERATOR_ID + 1;
240: public static final int INVALID_COMMENT_END_ID = INVALID_OCTAL_LITERAL_ID + 1;
241: public static final int INVALID_BACKSLASH_ID = INVALID_COMMENT_END_ID + 1;
242: public static final int INCOMPLETE_SYS_INCLUDE_ID = INVALID_BACKSLASH_ID + 1;
243: public static final int INCOMPLETE_USR_INCLUDE_ID = INCOMPLETE_SYS_INCLUDE_ID + 1;
244:
245: // Token-categories
246: /** All the keywords belong to this category. */
247: public static final BaseTokenCategory KEYWORDS = new BaseTokenCategory(
248: "keywords", KEYWORDS_ID); // NOI18N
249:
250: /** All the operators belong to this category. */
251: public static final BaseTokenCategory OPERATORS = new BaseTokenCategory(
252: "operators", OPERATORS_ID); // NOI18N
253:
254: /** All the numeric literals belong to this category. */
255: public static final BaseTokenCategory NUMERIC_LITERALS = new BaseTokenCategory(
256: "numeric-literals", NUMERIC_LITERALS_ID); // NOI18N
257:
258: /** All the errorneous constructions and incomplete tokens
259: * belong to this category.
260: */
261: public static final BaseTokenCategory ERRORS = new BaseTokenCategory(
262: "errors", ERRORS_ID); // NOI18N
263:
264: /* All C preprocessor directive keywords belong to this category */
265: public static final BaseTokenCategory CPP = new BaseTokenCategory(
266: "preprocessor", CPP_ID); // NOI18N
267:
268: // Token-ids
269: public static final BaseTokenID WHITESPACE = new BaseTokenID(
270: "whitespace", WHITESPACE_ID); // NOI18N
271:
272: public static final BaseTokenID BACKSLASH = new BaseTokenID(
273: "backslash", BACKSLASH_ID); // NOI18N
274:
275: public static final BaseTokenID LINE_CONTINUATION = new BaseTokenID(
276: "line-continuation", LINE_CONTINUATION_ID); // NOI18N
277:
278: public static final BaseTokenID IDENTIFIER = new BaseTokenID(
279: "identifier", IDENTIFIER_ID); // NOI18N
280:
281: /** Comment with the '//' prefix */
282: public static final BaseTokenID LINE_COMMENT = new BaseTokenID(
283: "line-comment", LINE_COMMENT_ID); // NOI18N
284:
285: /** Block comment */
286: public static final BaseTokenID BLOCK_COMMENT = new BaseTokenID(
287: "block-comment", BLOCK_COMMENT_ID); // NOI18N
288:
289: /** Character literal e.g. 'c' */
290: public static final BaseTokenID CHAR_LITERAL = new BaseTokenID(
291: "char-literal", CHAR_LITERAL_ID); // NOI18N
292:
293: /** CC string literal e.g. "hello" */
294: public static final BaseTokenID STRING_LITERAL = new BaseTokenID(
295: "string-literal", STRING_LITERAL_ID); // NOI18N
296:
297: /** CC integer literal e.g. 1234 */
298: public static final BaseTokenID INT_LITERAL = new BaseTokenID(
299: "int-literal", INT_LITERAL_ID, NUMERIC_LITERALS); // NOI18N
300:
301: /** CC long literal e.g. 12L */
302: public static final BaseTokenID LONG_LITERAL = new BaseTokenID(
303: "long-literal", LONG_LITERAL_ID, NUMERIC_LITERALS);// NOI18N
304:
305: /** CC hexadecimal literal e.g. 0x5a */
306: public static final BaseTokenID HEX_LITERAL = new BaseTokenID(
307: "hex-literal", HEX_LITERAL_ID, NUMERIC_LITERALS); // NOI18N
308:
309: /** CC octal literal e.g. 0123 */
310: public static final BaseTokenID OCTAL_LITERAL = new BaseTokenID(
311: "octal-literal", // NOI18N
312: OCTAL_LITERAL_ID, NUMERIC_LITERALS);
313: /** CC float literal e.g. 1.5e+20f */
314: public static final BaseTokenID FLOAT_LITERAL = new BaseTokenID(
315: "float-literal", // NOI18N
316: FLOAT_LITERAL_ID, NUMERIC_LITERALS);
317:
318: /** CC double literal e.g. 1.5e+20 */
319: public static final BaseTokenID DOUBLE_LITERAL = new BaseTokenID(
320: "double-literal", // NOI18N
321: DOUBLE_LITERAL_ID, NUMERIC_LITERALS);
322:
323: /** PP system include <filename> */
324: public static final BaseTokenID SYS_INCLUDE = new BaseTokenID(
325: "sys-include", SYS_INCLUDE_ID); // NOI18N
326:
327: /** PP user include "filename" */
328: public static final BaseTokenID USR_INCLUDE = new BaseTokenID(
329: "user-include", USR_INCLUDE_ID); // NOI18N
330:
331: // Operators
332: public static final BaseImageTokenID HASH = new BaseImageTokenID(
333: "hash", HASH_ID, CPP, "#"); // NOI18N
334:
335: public static final BaseImageTokenID DOUBLE_HASH = new BaseImageTokenID(
336: "double-hash", DOUBLE_HASH_ID, CPP, "##"); // NOI18N
337:
338: public static final BaseImageTokenID EQ = new BaseImageTokenID(
339: "eq", EQ_ID, OPERATORS, "="); // NOI18N
340:
341: public static final BaseImageTokenID LT = new BaseImageTokenID(
342: "lt", LT_ID, OPERATORS, "<"); // NOI18N
343:
344: public static final BaseImageTokenID GT = new BaseImageTokenID(
345: "gt", GT_ID, OPERATORS, ">"); // NOI18N
346:
347: public static final BaseImageTokenID LSHIFT = new BaseImageTokenID(
348: "lshift", LSHIFT_ID, OPERATORS, "<<"); // NOI18N
349:
350: public static final BaseImageTokenID RSSHIFT = new BaseImageTokenID(
351: "rsshift", RSSHIFT_ID, OPERATORS, ">>"); // NOI18N
352:
353: public static final BaseImageTokenID PLUS = new BaseImageTokenID(
354: "plus", PLUS_ID, OPERATORS, "+"); // NOI18N
355:
356: public static final BaseImageTokenID MINUS = new BaseImageTokenID(
357: "minus", MINUS_ID, OPERATORS, "-"); // NOI18N
358:
359: public static final BaseImageTokenID MUL = new BaseImageTokenID(
360: "mul", MUL_ID, OPERATORS, "*"); // NOI18N
361:
362: public static final BaseImageTokenID DIV = new BaseImageTokenID(
363: "div", DIV_ID, OPERATORS, "/"); // NOI18N
364:
365: public static final BaseImageTokenID AND = new BaseImageTokenID(
366: "and", AND_ID, OPERATORS, "&"); // NOI18N
367:
368: public static final BaseImageTokenID OR = new BaseImageTokenID(
369: "or", OR_ID, OPERATORS, "|"); // NOI18N
370:
371: public static final BaseImageTokenID XOR = new BaseImageTokenID(
372: "xor", XOR_ID, OPERATORS, "^"); // NOI18N
373:
374: public static final BaseImageTokenID MOD = new BaseImageTokenID(
375: "mod", MOD_ID, OPERATORS, "%"); // NOI18N
376:
377: public static final BaseImageTokenID NOT = new BaseImageTokenID(
378: "not", NOT_ID, OPERATORS, "!"); // NOI18N
379:
380: public static final BaseImageTokenID NEG = new BaseImageTokenID(
381: "neg", NEG_ID, OPERATORS, "~"); // NOI18N
382:
383: public static final BaseImageTokenID EQ_EQ = new BaseImageTokenID(
384: "eq-eq", EQ_EQ_ID, OPERATORS, "=="); // NOI18N
385:
386: public static final BaseImageTokenID LT_EQ = new BaseImageTokenID(
387: "le", LT_EQ_ID, OPERATORS, "<="); // NOI18N
388:
389: public static final BaseImageTokenID GT_EQ = new BaseImageTokenID(
390: "ge", GT_EQ_ID, OPERATORS, ">="); // NOI18N
391:
392: public static final BaseImageTokenID LSHIFT_EQ = new BaseImageTokenID(
393: "lshift-eq", LSHIFT_EQ_ID, OPERATORS, "<<=");// NOI18N
394:
395: public static final BaseImageTokenID RSSHIFT_EQ = new BaseImageTokenID(
396: "rsshift-eq", RSSHIFT_EQ_ID, OPERATORS, ">>=");// NOI18N
397:
398: public static final BaseImageTokenID PLUS_EQ = new BaseImageTokenID(
399: "plus-eq", PLUS_EQ_ID, OPERATORS, "+="); // NOI18N
400:
401: public static final BaseImageTokenID MINUS_EQ = new BaseImageTokenID(
402: "minus-eq", MINUS_EQ_ID, OPERATORS, "-="); // NOI18N
403:
404: public static final BaseImageTokenID ARROW = new BaseImageTokenID(
405: "arrow", ARROW_ID, OPERATORS, "->"); // NOI18N
406:
407: public static final BaseImageTokenID ARROWMBR = new BaseImageTokenID(
408: "arrow-member", ARROWMBR_ID, OPERATORS, "->*"); // NOI18N
409:
410: public static final BaseImageTokenID MUL_EQ = new BaseImageTokenID(
411: "mul-eq", MUL_EQ_ID, OPERATORS, "*="); // NOI18N
412:
413: public static final BaseImageTokenID DIV_EQ = new BaseImageTokenID(
414: "div-eq", DIV_EQ_ID, OPERATORS, "/="); // NOI18N
415:
416: public static final BaseImageTokenID AND_EQ = new BaseImageTokenID(
417: "and-eq", AND_EQ_ID, OPERATORS, "&="); // NOI18N
418:
419: public static final BaseImageTokenID OR_EQ = new BaseImageTokenID(
420: "or-eq", OR_EQ_ID, OPERATORS, "|="); // NOI18N
421:
422: public static final BaseImageTokenID XOR_EQ = new BaseImageTokenID(
423: "xor-eq", XOR_EQ_ID, OPERATORS, "^="); // NOI18N
424:
425: public static final BaseImageTokenID MOD_EQ = new BaseImageTokenID(
426: "mod-eq", MOD_EQ_ID, OPERATORS, "%="); // NOI18N
427:
428: public static final BaseImageTokenID NOT_EQ = new BaseImageTokenID(
429: "not-eq", NOT_EQ_ID, OPERATORS, "!="); // NOI18N
430:
431: public static final BaseImageTokenID DOT = new BaseImageTokenID(
432: "dot", DOT_ID, OPERATORS, "."); // NOI18N
433:
434: public static final BaseImageTokenID DOTMBR = new BaseImageTokenID(
435: "dot-member", DOTMBR_ID, OPERATORS, ".*"); // NOI18N
436:
437: public static final BaseImageTokenID COMMA = new BaseImageTokenID(
438: "comma", COMMA_ID, OPERATORS, ","); // NOI18N
439:
440: public static final BaseImageTokenID COLON = new BaseImageTokenID(
441: "colon", COLON_ID, OPERATORS, ":"); // NOI18N
442:
443: public static final BaseImageTokenID SCOPE = new BaseImageTokenID(
444: "scope", SCOPE_ID, OPERATORS, "::"); // NOI18N
445:
446: public static final BaseImageTokenID SEMICOLON = new BaseImageTokenID(
447: "semicolon", SEMICOLON_ID, OPERATORS, ";"); // NOI18N
448:
449: public static final BaseImageTokenID QUESTION = new BaseImageTokenID(
450: "question", QUESTION_ID, OPERATORS, "?"); // NOI18N
451:
452: public static final BaseImageTokenID LPAREN = new BaseImageTokenID(
453: "lparen", LPAREN_ID, OPERATORS, "("); // NOI18N
454:
455: public static final BaseImageTokenID RPAREN = new BaseImageTokenID(
456: "rparen", RPAREN_ID, OPERATORS, ")"); // NOI18N
457:
458: public static final BaseImageTokenID LBRACKET = new BaseImageTokenID(
459: "lbracket", LBRACKET_ID, OPERATORS, "["); // NOI18N
460:
461: public static final BaseImageTokenID RBRACKET = new BaseImageTokenID(
462: "rbracket", RBRACKET_ID, OPERATORS, "]"); // NOI18N
463:
464: public static final BaseImageTokenID LBRACE = new BaseImageTokenID(
465: "lbrace", LBRACE_ID, OPERATORS, "{"); // NOI18N
466:
467: public static final BaseImageTokenID RBRACE = new BaseImageTokenID(
468: "rbrace", RBRACE_ID, OPERATORS, "}"); // NOI18N
469:
470: public static final BaseImageTokenID PLUS_PLUS = new BaseImageTokenID(
471: "plus-plus", PLUS_PLUS_ID, OPERATORS, "++"); // NOI18N
472:
473: public static final BaseImageTokenID MINUS_MINUS = new BaseImageTokenID(
474: "minus-minus", // NOI18N
475: MINUS_MINUS_ID, OPERATORS, "--"); // NOI18N
476:
477: public static final BaseImageTokenID AND_AND = new BaseImageTokenID(
478: "and-and", AND_AND_ID, OPERATORS, "&&"); // NOI18N
479:
480: public static final BaseImageTokenID OR_OR = new BaseImageTokenID(
481: "or-or", OR_OR_ID, OPERATORS, "||"); // NOI18N
482:
483: // Data types
484: public static final BaseImageTokenID ASM = new BaseImageTokenID(
485: "asm", ASM_ID, KEYWORDS); // NOI18N
486:
487: public static final BaseImageTokenID AUTO = new BaseImageTokenID(
488: "auto", AUTO_ID, KEYWORDS); // NOI18N
489:
490: public static final BaseImageTokenID BOOLEAN = new BaseImageTokenID(
491: "bool", BOOLEAN_ID, KEYWORDS); // NOI18N
492:
493: public static final BaseImageTokenID CHAR = new BaseImageTokenID(
494: "char", CHAR_ID, KEYWORDS); // NOI18N
495:
496: public static final BaseImageTokenID DOUBLE = new BaseImageTokenID(
497: "double", DOUBLE_ID, KEYWORDS); // NOI18N
498:
499: public static final BaseImageTokenID ENUM = new BaseImageTokenID(
500: "enum", ENUM_ID, KEYWORDS); // NOI18N
501:
502: public static final BaseImageTokenID EXPORT = new BaseImageTokenID(
503: "export", EXPORT_ID, KEYWORDS); // NOI18N
504:
505: public static final BaseImageTokenID FLOAT = new BaseImageTokenID(
506: "float", FLOAT_ID, KEYWORDS); // NOI18N
507:
508: public static final BaseImageTokenID INT = new BaseImageTokenID(
509: "int", INT_ID, KEYWORDS); // NOI18N
510:
511: public static final BaseImageTokenID LONG = new BaseImageTokenID(
512: "long", LONG_ID, KEYWORDS); // NOI18N
513:
514: public static final BaseImageTokenID MUTABLE = new BaseImageTokenID(
515: "mutable", MUTABLE_ID, KEYWORDS); // NOI18N
516:
517: public static final BaseImageTokenID REGISTER = new BaseImageTokenID(
518: "register", REGISTER_ID, KEYWORDS); // NOI18N
519:
520: public static final BaseImageTokenID SHORT = new BaseImageTokenID(
521: "short", SHORT_ID, KEYWORDS); // NOI18N
522:
523: public static final BaseImageTokenID SIGNED = new BaseImageTokenID(
524: "signed", SIGNED_ID, KEYWORDS); // NOI18N
525:
526: public static final BaseImageTokenID STRUCT = new BaseImageTokenID(
527: "struct", STRUCT_ID, KEYWORDS); // NOI18N
528:
529: public static final BaseImageTokenID TYPEDEF = new BaseImageTokenID(
530: "typedef", TYPEDEF_ID, KEYWORDS); // NOI18N
531:
532: public static final BaseImageTokenID UNSIGNED = new BaseImageTokenID(
533: "unsigned", UNSIGNED_ID, KEYWORDS); // NOI18N
534:
535: public static final BaseImageTokenID VOID = new BaseImageTokenID(
536: "void", VOID_ID, KEYWORDS); // NOI18N
537:
538: public static final BaseImageTokenID WCHAR_T = new BaseImageTokenID(
539: "wchar_t", WCHAR_T_ID, KEYWORDS); // NOI18N
540:
541: public static final BaseImageTokenID UNION = new BaseImageTokenID(
542: "union", UNION_ID, KEYWORDS); // NOI18N
543:
544: public static final BaseImageTokenID BREAK = new BaseImageTokenID(
545: "break", BREAK_ID, KEYWORDS); // NOI18N
546:
547: public static final BaseImageTokenID CASE = new BaseImageTokenID(
548: "case", CASE_ID, KEYWORDS); // NOI18N
549:
550: public static final BaseImageTokenID CATCH = new BaseImageTokenID(
551: "catch", CATCH_ID, KEYWORDS); // NOI18N
552:
553: public static final BaseImageTokenID CLASS = new BaseImageTokenID(
554: "class", CLASS_ID, KEYWORDS); // NOI18N
555:
556: public static final BaseImageTokenID CONST = new BaseImageTokenID(
557: "const", CONST_ID, KEYWORDS); // NOI18N
558:
559: public static final BaseImageTokenID CONTINUE = new BaseImageTokenID(
560: "continue", CONTINUE_ID, KEYWORDS); // NOI18N
561:
562: public static final BaseImageTokenID DEFAULT = new BaseImageTokenID(
563: "default", DEFAULT_ID, KEYWORDS); // NOI18N
564:
565: public static final BaseImageTokenID DELETE = new BaseImageTokenID(
566: "delete", DELETE_ID, KEYWORDS); // NOI18N
567:
568: public static final BaseImageTokenID DO = new BaseImageTokenID(
569: "do", DO_ID, KEYWORDS); // NOI18N
570:
571: public static final BaseImageTokenID ELSE = new BaseImageTokenID(
572: "else", ELSE_ID, KEYWORDS); // NOI18N
573:
574: public static final BaseImageTokenID EXPLICIT = new BaseImageTokenID(
575: "explicit", EXPLICIT_ID, KEYWORDS); // NOI18N
576:
577: public static final BaseImageTokenID EXTERN = new BaseImageTokenID(
578: "extern", EXTERN_ID, KEYWORDS); // NOI18N
579:
580: public static final BaseImageTokenID FALSE = new BaseImageTokenID(
581: "false", FALSE_ID, KEYWORDS); // NOI18N
582:
583: public static final BaseImageTokenID FOR = new BaseImageTokenID(
584: "for", FOR_ID, KEYWORDS); // NOI18N
585:
586: public static final BaseImageTokenID FRIEND = new BaseImageTokenID(
587: "friend", FRIEND_ID, KEYWORDS); // NOI18N
588:
589: public static final BaseImageTokenID GOTO = new BaseImageTokenID(
590: "goto", GOTO_ID, KEYWORDS); // NOI18N
591:
592: public static final BaseImageTokenID IF = new BaseImageTokenID(
593: "if", IF_ID, KEYWORDS); // NOI18N
594:
595: public static final BaseImageTokenID INLINE = new BaseImageTokenID(
596: "inline", INLINE_ID, KEYWORDS); // NOI18N
597:
598: public static final BaseImageTokenID NAMESPACE = new BaseImageTokenID(
599: "namespace", NAMESPACE_ID, KEYWORDS); // NOI18N
600:
601: public static final BaseImageTokenID NEW = new BaseImageTokenID(
602: "new", NEW_ID, KEYWORDS); // NOI18N
603:
604: public static final BaseImageTokenID NULL = new BaseImageTokenID(
605: "null", NULL_ID, KEYWORDS); // NOI18N
606:
607: public static final BaseImageTokenID OPERATOR = new BaseImageTokenID(
608: "operator", OPERATOR_ID, KEYWORDS); // NOI18N
609:
610: public static final BaseImageTokenID PRIVATE = new BaseImageTokenID(
611: "private", PRIVATE_ID, KEYWORDS); // NOI18N
612:
613: public static final BaseImageTokenID PROTECTED = new BaseImageTokenID(
614: "protected", PROTECTED_ID, KEYWORDS); // NOI18N
615:
616: public static final BaseImageTokenID PUBLIC = new BaseImageTokenID(
617: "public", PUBLIC_ID, KEYWORDS); // NOI18N
618:
619: public static final BaseImageTokenID RETURN = new BaseImageTokenID(
620: "return", RETURN_ID, KEYWORDS); // NOI18N
621:
622: public static final BaseImageTokenID SIZEOF = new BaseImageTokenID(
623: "sizeof", SIZEOF_ID, KEYWORDS); // NOI18N
624:
625: public static final BaseImageTokenID STATIC = new BaseImageTokenID(
626: "static", STATIC_ID, KEYWORDS); // NOI18N
627:
628: public static final BaseImageTokenID SWITCH = new BaseImageTokenID(
629: "switch", SWITCH_ID, KEYWORDS); // NOI18N
630:
631: public static final BaseImageTokenID THIS = new BaseImageTokenID(
632: "this", THIS_ID, KEYWORDS); // NOI18N
633:
634: public static final BaseImageTokenID THROW = new BaseImageTokenID(
635: "throw", THROW_ID, KEYWORDS); // NOI18N
636:
637: public static final BaseImageTokenID TRUE = new BaseImageTokenID(
638: "true", TRUE_ID, KEYWORDS); // NOI18N
639:
640: public static final BaseImageTokenID TRY = new BaseImageTokenID(
641: "try", TRY_ID, KEYWORDS); // NOI18N
642:
643: public static final BaseImageTokenID TYPEID = new BaseImageTokenID(
644: "typeid", TYPEID_ID, KEYWORDS); // NOI18N
645:
646: public static final BaseImageTokenID TYPEOF = new BaseImageTokenID(
647: "typeof", TYPEOF_ID, KEYWORDS); // NOI18N
648:
649: public static final BaseImageTokenID TYPENAME = new BaseImageTokenID(
650: "typename", TYPENAME_ID, KEYWORDS); // NOI18N
651:
652: public static final BaseImageTokenID TEMPLATE = new BaseImageTokenID(
653: "template", TEMPLATE_ID, KEYWORDS); // NOI18N
654:
655: public static final BaseImageTokenID USING = new BaseImageTokenID(
656: "using", USING_ID, KEYWORDS); // NOI18N
657:
658: public static final BaseImageTokenID VIRTUAL = new BaseImageTokenID(
659: "virtual", VIRTUAL_ID, KEYWORDS); // NOI18N
660:
661: public static final BaseImageTokenID VOLATILE = new BaseImageTokenID(
662: "volatile", VOLATILE_ID, KEYWORDS); // NOI18N
663:
664: public static final BaseImageTokenID WHILE = new BaseImageTokenID(
665: "while", WHILE_ID, KEYWORDS); // NOI18N
666:
667: public static final BaseImageTokenID DYNAMIC_CAST = new BaseImageTokenID(
668: "dynamic_cast", DYNAMIC_CAST_ID, KEYWORDS); // NOI18N
669:
670: public static final BaseImageTokenID STATIC_CAST = new BaseImageTokenID(
671: "static_cast", STATIC_CAST_ID, KEYWORDS); // NOI18N
672:
673: public static final BaseImageTokenID REINTERPRET_CAST = new BaseImageTokenID(
674: "reinterpret_cast", // NOI18N
675: REINTERPRET_CAST_ID, KEYWORDS);
676:
677: public static final BaseImageTokenID CONST_CAST = new BaseImageTokenID(
678: "const_cast", CONST_CAST_ID, KEYWORDS); // NOI18N
679:
680: public static final BaseImageTokenID RESTRICT = new BaseImageTokenID(
681: "restrict", RESTRICT_ID, KEYWORDS); // NOI18N
682:
683: public static final BaseImageTokenID _BOOL = new BaseImageTokenID(
684: "_Bool", _BOOL_ID, KEYWORDS); // NOI18N
685:
686: public static final BaseImageTokenID _COMPLEX = new BaseImageTokenID(
687: "_Complex", _COMPLEX_ID, KEYWORDS); // NOI18N
688:
689: public static final BaseImageTokenID _IMAGINARY = new BaseImageTokenID(
690: "_Imaginary", _IMAGINARY_ID, KEYWORDS); // NOI18N
691:
692: // Preprocessor directives
693: public static final BaseImageTokenID CPPDEFINE = new BaseImageTokenID(
694: "#define", CPPDEFINE_ID, CPP); // NOI18N
695:
696: public static final BaseImageTokenID CPPELIF = new BaseImageTokenID(
697: "#elif", CPPELIF_ID, CPP); // NOI18N
698:
699: public static final BaseImageTokenID CPPELSE = new BaseImageTokenID(
700: "#else", CPPELSE_ID, CPP); // NOI18N
701:
702: public static final BaseImageTokenID CPPENDIF = new BaseImageTokenID(
703: "#endif", CPPENDIF_ID, CPP); // NOI18N
704:
705: public static final BaseImageTokenID CPPERROR = new BaseImageTokenID(
706: "#error", CPPERROR_ID, CPP); // NOI18N
707:
708: public static final BaseImageTokenID CPPIF = new BaseImageTokenID(
709: "#if", CPPIF_ID, CPP); // NOI18N
710:
711: public static final BaseImageTokenID CPPIFDEF = new BaseImageTokenID(
712: "#ifdef", CPPIFDEF_ID, CPP); // NOI18N
713:
714: public static final BaseImageTokenID CPPIFNDEF = new BaseImageTokenID(
715: "#ifndef", CPPIFNDEF_ID, CPP); // NOI18N
716:
717: public static final BaseImageTokenID CPPINCLUDE = new BaseImageTokenID(
718: "#include", CPPINCLUDE_ID, CPP); // NOI18N
719:
720: public static final BaseImageTokenID CPPINCLUDE_NEXT = new BaseImageTokenID(
721: "#include_next", CPPINCLUDE_NEXT_ID, CPP); // NOI18N
722:
723: public static final BaseImageTokenID CPPLINE = new BaseImageTokenID(
724: "#line", CPPLINE_ID, CPP); // NOI18N
725:
726: public static final BaseImageTokenID CPPPRAGMA = new BaseImageTokenID(
727: "#pragma", CPPPRAGMA_ID, CPP); // NOI18N
728:
729: public static final BaseImageTokenID CPPUNDEF = new BaseImageTokenID(
730: "#undef", CPPUNDEF_ID, CPP); // NOI18N
731:
732: public static final BaseImageTokenID CPPWARNING = new BaseImageTokenID(
733: "#warning", CPPWARNING_ID, CPP); // NOI18N
734:
735: public static final BaseImageTokenID CPPIDENTIFIER = new BaseImageTokenID(
736: "#preproc-identifier", CPPIDENTIFIER_ID, CPP); // NOI18N
737:
738: // Incomplete and error token-ids
739: public static final BaseTokenID INCOMPLETE_STRING_LITERAL = new BaseTokenID(
740: "incomplete-string-literal", // NOI18N
741: INCOMPLETE_STRING_LITERAL_ID, ERRORS);
742:
743: public static final BaseTokenID INCOMPLETE_CHAR_LITERAL = new BaseTokenID(
744: "incomplete-char-literal", // NOI18N
745: INCOMPLETE_CHAR_LITERAL_ID, ERRORS);
746:
747: public static final BaseTokenID INCOMPLETE_HEX_LITERAL = new BaseTokenID(
748: "incomplete-hex-literal", // NOI18N
749: INCOMPLETE_HEX_LITERAL_ID, ERRORS);
750:
751: public static final BaseTokenID INVALID_CHAR = new BaseTokenID(
752: "invalid-char", INVALID_CHAR_ID, ERRORS); // NOI18N
753:
754: public static final BaseTokenID INVALID_OPERATOR = new BaseTokenID(
755: "invalid-operator", INVALID_OPERATOR_ID, ERRORS);// NOI18N
756:
757: public static final BaseTokenID INVALID_OCTAL_LITERAL = new BaseTokenID(
758: "invalid-octal-literal", // NOI18N
759: INVALID_OCTAL_LITERAL_ID, ERRORS);
760:
761: public static final BaseTokenID INVALID_COMMENT_END = new BaseTokenID(
762: "invalid-comment-end", // NOI18N
763: INVALID_COMMENT_END_ID, ERRORS);
764:
765: public static final BaseTokenID INVALID_BACKSLASH = new BaseTokenID(
766: "invalid-backslash", INVALID_BACKSLASH_ID, ERRORS); // NOI18N
767:
768: public static final BaseTokenID INCOMPLETE_SYS_INCLUDE = new BaseTokenID(
769: "incomplete-sys-include", INCOMPLETE_SYS_INCLUDE_ID, ERRORS); // NOI18N
770:
771: public static final BaseTokenID INCOMPLETE_USR_INCLUDE = new BaseTokenID(
772: "incomplete-user-include", INCOMPLETE_USR_INCLUDE_ID,
773: ERRORS); // NOI18N
774:
775: // Context instance declaration
776: public static final CCTokenContext context = new CCTokenContext();
777:
778: public static final TokenContextPath contextPath = context
779: .getContextPath();
780:
781: private static final HashMap str2kwd = new HashMap();
782:
783: /* static {
784: BaseImageTokenID[] kwds = new BaseImageTokenID[] {
785: BREAK, CASE, CATCH, CLASS, CONST, CONST_CAST, CONTINUE,
786: DEFAULT, DELETE, DO, DYNAMIC_CAST,
787: ELSE, EXPLICIT, EXPORT, EXTERN, FALSE, FOR, FRIEND, GOTO, IF,
788: NAMESPACE, NEW, NULL, OPERATOR, PRIVATE,
789: PROTECTED, PUBLIC, REINTERPRET_CAST, RETURN,
790: SIZEOF, STATIC, STATIC_CAST, SWITCH,
791: TEMPLATE, THIS, THROW, TRUE, TRY, TYPEID, TYPENAME,
792: USING, VIRTUAL, VOLATILE, WHILE
793: };
794:
795: for (int i = kwds.length - 1; i >= 0; i--) {
796: str2kwd.put(kwds[i].getImage(), kwds[i]);
797: }
798: }*/
799:
800: /** Checks whether the given token-id is a type-keyword.
801: * @return true when the keyword is a data type.
802: */
803: public static boolean isType(TokenID keywordTokenID) {
804: int numID = (keywordTokenID != null) ? keywordTokenID
805: .getNumericID() : -1;
806: return (numID >= BOOLEAN_ID && numID <= VOID_ID);
807: }
808:
809: /** Checks whether the given string is a type-keyword. */
810: public static boolean isType(String s) {
811: return isType((TokenID) str2kwd.get(s));
812: }
813:
814: /** Checks whether the given token-id is a data-type-keyword or void-keyword.
815: * @return true when the keyword is a data-type-keyword or void-keyword.
816: */
817: public static boolean isTypeOrVoid(TokenID keywordTokenID) {
818: int numID = (keywordTokenID != null) ? keywordTokenID
819: .getNumericID() : -1;
820: return (numID >= BOOLEAN_ID && numID <= VOID_ID);
821: }
822:
823: /** Checks whether the given string is a data-type-keyword or void-keyword. */
824: public static boolean isTypeOrVoid(String s) {
825: return isTypeOrVoid((TokenID) str2kwd.get(s));
826: }
827:
828: /** Get the keyword token-id from string */
829: public static TokenID getKeyword(String s) {
830: return (TokenID) str2kwd.get(s);
831: }
832:
833: private CCTokenContext() {
834: super ("cc-"); // NOI18N
835:
836: try {
837: addDeclaredTokenIDs();
838: } catch (Exception e) {
839: if (Boolean.getBoolean("netbeans.debug.exceptions")) { //NOI18N
840: e.printStackTrace();
841: }
842: }
843:
844: }
845:
846: }
|