PageRenderTime 125ms CodeModel.GetById 73ms app.highlight 13ms RepoModel.GetById 7ms app.codeStats 30ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/syntax/Token.java

#
Java | 148 lines | 72 code | 12 blank | 64 comment | 41 complexity | 04e98cec8b6287abaf9803cb3bf4b5a8 MD5 | raw file
  1/*
  2 * Token.java - Syntax token
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 1998, 1999, 2000, 2001, 2002 Slava Pestov
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22package org.gjt.sp.jedit.syntax;
 23
 24/**
 25 * A linked list of syntax tokens.
 26 *
 27 * @author Slava Pestov
 28 * @version $Id: Token.java 4191 2002-05-26 07:38:44Z spestov $
 29 */
 30public class Token
 31{
 32	//{{{ stringToToken() method
 33	/**
 34	 * Converts a token type string to a token type constant.
 35	 * @param value The token type
 36	 * @since jEdit 4.1pre1
 37	 */
 38	public static byte stringToToken(String value)
 39	{
 40		value = value.intern();
 41
 42		if (value == "NULL")
 43			return Token.NULL;
 44		else if (value == "COMMENT1")
 45			return Token.COMMENT1;
 46		else if (value == "COMMENT2")
 47			return Token.COMMENT2;
 48		else if (value == "LITERAL1")
 49			return Token.LITERAL1;
 50		else if (value == "LITERAL2")
 51			return Token.LITERAL2;
 52		else if (value == "LABEL")
 53			return Token.LABEL;
 54		else if (value == "KEYWORD1")
 55			return Token.KEYWORD1;
 56		else if (value == "KEYWORD2")
 57			return Token.KEYWORD2;
 58		else if (value == "KEYWORD3")
 59			return Token.KEYWORD3;
 60		else if (value == "FUNCTION")
 61			return Token.FUNCTION;
 62		else if (value == "MARKUP")
 63			return Token.MARKUP;
 64		else if (value == "OPERATOR")
 65			return Token.OPERATOR;
 66		else if (value == "DIGIT")
 67			return Token.DIGIT;
 68		else if (value == "INVALID")
 69			return Token.INVALID;
 70		else
 71			return -1;
 72	} //}}}
 73
 74	//{{{ Token types
 75	public static final byte NULL = 0;
 76	public static final byte COMMENT1 = 1;
 77	public static final byte COMMENT2 = 2;
 78	public static final byte LITERAL1 = 3;
 79	public static final byte LITERAL2 = 4;
 80	public static final byte LABEL = 5;
 81	public static final byte KEYWORD1 = 6;
 82	public static final byte KEYWORD2 = 7;
 83	public static final byte KEYWORD3 = 8;
 84	public static final byte FUNCTION = 9;
 85	public static final byte MARKUP = 10;
 86	public static final byte OPERATOR = 11;
 87	public static final byte DIGIT = 12;
 88	public static final byte INVALID = 13; //}}}
 89
 90	public static final byte ID_COUNT = 14;
 91
 92	// Special:
 93	public static final byte WHITESPACE = 125;
 94	public static final byte TAB = 126;
 95	public static final byte END = 127;
 96
 97	//{{{ Instance variables
 98	/**
 99	 * The id of this token.
100	 */
101	public byte id;
102
103	/**
104	 * The start offset of this token.
105	 */
106	public int offset;
107
108	/**
109	 * The length of this token.
110	 */
111	public int length;
112
113	/**
114	 * The rule set of this token.
115	 */
116	public ParserRuleSet rules;
117
118	/**
119	 * The next token in the linked list.
120	 */
121	public Token next;
122	//}}}
123
124	//{{{ Token constructor
125	/**
126	 * Creates a new token.
127	 * @param id The id of the token
128	 * @param offset The start offset of the token
129	 * @param length The length of the token
130	 * @param rules The parser rule set that generated this token
131	 */
132	public Token(byte id, int offset, int length, ParserRuleSet rules)
133	{
134		this.id = id;
135		this.offset = offset;
136		this.length = length;
137		this.rules = rules;
138	} //}}}
139
140	//{{{ toString() method
141	/**
142	 * Returns a string representation of this token.
143	 */
144	public String toString()
145	{
146		return "[id=" + id + ",offset=" + offset + ",length=" + length + "]";
147	} //}}}
148}