PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/syntax/Token.java

#
Java | 164 lines | 79 code | 15 blank | 70 comment | 0 complexity | 56837f3cb0e8edba74dbd705ff10fb5c MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. */
  22. package org.gjt.sp.jedit.syntax;
  23. import java.lang.reflect.Field;
  24. /**
  25. * A linked list of syntax tokens.
  26. *
  27. * @author Slava Pestov
  28. * @version $Id: Token.java 4554 2003-03-16 20:55:49Z spestov $
  29. */
  30. public 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. try
  41. {
  42. Field f = Token.class.getField(value);
  43. return (byte)f.getByte(null);
  44. }
  45. catch(Exception e)
  46. {
  47. return -1;
  48. }
  49. } //}}}
  50. //{{{ tokenToString() method
  51. /**
  52. * Converts a token type constant to a token type string.
  53. * @since jEdit 4.2pre1
  54. */
  55. public static String tokenToString(byte token)
  56. {
  57. return TOKEN_TYPES[token];
  58. } //}}}
  59. //{{{ Token types
  60. public static final String[] TOKEN_TYPES = new String[] {
  61. "NULL",
  62. "COMMENT1",
  63. "COMMENT2",
  64. "COMMENT3",
  65. "COMMENT4",
  66. "DIGIT",
  67. "FUNCTION",
  68. "INVALID",
  69. "KEYWORD1",
  70. "KEYWORD2",
  71. "KEYWORD3",
  72. "KEYWORD4",
  73. "LABEL",
  74. "LITERAL1",
  75. "LITERAL2",
  76. "LITERAL3",
  77. "LITERAL4",
  78. "MARKUP",
  79. "OPERATOR"
  80. };
  81. public static final byte NULL = 0;
  82. public static final byte COMMENT1 = 1;
  83. public static final byte COMMENT2 = 2;
  84. public static final byte COMMENT3 = 3;
  85. public static final byte COMMENT4 = 4;
  86. public static final byte DIGIT = 5;
  87. public static final byte FUNCTION = 6;
  88. public static final byte INVALID = 7;
  89. public static final byte KEYWORD1 = 8;
  90. public static final byte KEYWORD2 = 9;
  91. public static final byte KEYWORD3 = 10;
  92. public static final byte KEYWORD4 = 11;
  93. public static final byte LABEL = 12;
  94. public static final byte LITERAL1 = 13;
  95. public static final byte LITERAL2 = 14;
  96. public static final byte LITERAL3 = 15;
  97. public static final byte LITERAL4 = 16;
  98. public static final byte MARKUP = 17;
  99. public static final byte OPERATOR = 18;
  100. //}}}
  101. public static final byte ID_COUNT = 19;
  102. // Special:
  103. public static final byte END = 127;
  104. //{{{ Instance variables
  105. /**
  106. * The id of this token.
  107. */
  108. public byte id;
  109. /**
  110. * The start offset of this token.
  111. */
  112. public int offset;
  113. /**
  114. * The length of this token.
  115. */
  116. public int length;
  117. /**
  118. * The rule set of this token.
  119. */
  120. public ParserRuleSet rules;
  121. /**
  122. * The next token in the linked list.
  123. */
  124. public Token next;
  125. //}}}
  126. //{{{ Token constructor
  127. /**
  128. * Creates a new token.
  129. * @param id The id of the token
  130. * @param offset The start offset of the token
  131. * @param length The length of the token
  132. * @param rules The parser rule set that generated this token
  133. */
  134. public Token(byte id, int offset, int length, ParserRuleSet rules)
  135. {
  136. this.id = id;
  137. this.offset = offset;
  138. this.length = length;
  139. this.rules = rules;
  140. } //}}}
  141. //{{{ toString() method
  142. /**
  143. * Returns a string representation of this token.
  144. */
  145. public String toString()
  146. {
  147. return "[id=" + id + ",offset=" + offset + ",length=" + length + "]";
  148. } //}}}
  149. }