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

/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
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. /**
  24. * A linked list of syntax tokens.
  25. *
  26. * @author Slava Pestov
  27. * @version $Id: Token.java 4191 2002-05-26 07:38:44Z spestov $
  28. */
  29. public class Token
  30. {
  31. //{{{ stringToToken() method
  32. /**
  33. * Converts a token type string to a token type constant.
  34. * @param value The token type
  35. * @since jEdit 4.1pre1
  36. */
  37. public static byte stringToToken(String value)
  38. {
  39. value = value.intern();
  40. if (value == "NULL")
  41. return Token.NULL;
  42. else if (value == "COMMENT1")
  43. return Token.COMMENT1;
  44. else if (value == "COMMENT2")
  45. return Token.COMMENT2;
  46. else if (value == "LITERAL1")
  47. return Token.LITERAL1;
  48. else if (value == "LITERAL2")
  49. return Token.LITERAL2;
  50. else if (value == "LABEL")
  51. return Token.LABEL;
  52. else if (value == "KEYWORD1")
  53. return Token.KEYWORD1;
  54. else if (value == "KEYWORD2")
  55. return Token.KEYWORD2;
  56. else if (value == "KEYWORD3")
  57. return Token.KEYWORD3;
  58. else if (value == "FUNCTION")
  59. return Token.FUNCTION;
  60. else if (value == "MARKUP")
  61. return Token.MARKUP;
  62. else if (value == "OPERATOR")
  63. return Token.OPERATOR;
  64. else if (value == "DIGIT")
  65. return Token.DIGIT;
  66. else if (value == "INVALID")
  67. return Token.INVALID;
  68. else
  69. return -1;
  70. } //}}}
  71. //{{{ Token types
  72. public static final byte NULL = 0;
  73. public static final byte COMMENT1 = 1;
  74. public static final byte COMMENT2 = 2;
  75. public static final byte LITERAL1 = 3;
  76. public static final byte LITERAL2 = 4;
  77. public static final byte LABEL = 5;
  78. public static final byte KEYWORD1 = 6;
  79. public static final byte KEYWORD2 = 7;
  80. public static final byte KEYWORD3 = 8;
  81. public static final byte FUNCTION = 9;
  82. public static final byte MARKUP = 10;
  83. public static final byte OPERATOR = 11;
  84. public static final byte DIGIT = 12;
  85. public static final byte INVALID = 13; //}}}
  86. public static final byte ID_COUNT = 14;
  87. // Special:
  88. public static final byte WHITESPACE = 125;
  89. public static final byte TAB = 126;
  90. public static final byte END = 127;
  91. //{{{ Instance variables
  92. /**
  93. * The id of this token.
  94. */
  95. public byte id;
  96. /**
  97. * The start offset of this token.
  98. */
  99. public int offset;
  100. /**
  101. * The length of this token.
  102. */
  103. public int length;
  104. /**
  105. * The rule set of this token.
  106. */
  107. public ParserRuleSet rules;
  108. /**
  109. * The next token in the linked list.
  110. */
  111. public Token next;
  112. //}}}
  113. //{{{ Token constructor
  114. /**
  115. * Creates a new token.
  116. * @param id The id of the token
  117. * @param offset The start offset of the token
  118. * @param length The length of the token
  119. * @param rules The parser rule set that generated this token
  120. */
  121. public Token(byte id, int offset, int length, ParserRuleSet rules)
  122. {
  123. this.id = id;
  124. this.offset = offset;
  125. this.length = length;
  126. this.rules = rules;
  127. } //}}}
  128. //{{{ toString() method
  129. /**
  130. * Returns a string representation of this token.
  131. */
  132. public String toString()
  133. {
  134. return "[id=" + id + ",offset=" + offset + ",length=" + length + "]";
  135. } //}}}
  136. }