PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/syntax/ParserRuleSet.java

#
Java | 203 lines | 127 code | 27 blank | 49 comment | 8 complexity | e4542de1e70ec2fdefbf4091c86f1793 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. * ParserRuleSet.java - A set of parser rules
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1999 mike dillon
  7. * Portions copyright (C) 2001 Slava Pestov
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. package org.gjt.sp.jedit.syntax;
  24. import java.util.*;
  25. import org.gjt.sp.jedit.Mode;
  26. import javax.swing.text.Segment;
  27. /**
  28. * A set of parser rules.
  29. * @author mike dillon
  30. * @version $Id: ParserRuleSet.java 3930 2001-12-02 07:34:52Z spestov $
  31. */
  32. public class ParserRuleSet
  33. {
  34. //{{{ ParserRuleSet constructor
  35. public ParserRuleSet(String name, Mode mode)
  36. {
  37. this.name = name;
  38. this.mode = mode;
  39. ruleMapFirst = new ParserRule[RULE_BUCKET_COUNT];
  40. ruleMapLast = new ParserRule[RULE_BUCKET_COUNT];
  41. } //}}}
  42. //{{{ getMode() method
  43. public Mode getMode()
  44. {
  45. return mode;
  46. } //}}}
  47. //{{{ getProperties() method
  48. public Hashtable getProperties()
  49. {
  50. return props;
  51. } //}}}
  52. //{{{ setProperties() method
  53. public void setProperties(Hashtable props)
  54. {
  55. this.props = props;
  56. } //}}}
  57. //{{{ addRule() method
  58. public void addRule(ParserRule r)
  59. {
  60. int key = Character.toUpperCase(r.searchChars[0])
  61. % RULE_BUCKET_COUNT;
  62. ParserRule last = ruleMapLast[key];
  63. if(last == null)
  64. ruleMapFirst[key] = ruleMapLast[key] = r;
  65. else
  66. {
  67. last.next = r;
  68. ruleMapLast[key] = r;
  69. }
  70. } //}}}
  71. //{{{ getRules() method
  72. public ParserRule getRules(char ch)
  73. {
  74. int key = Character.toUpperCase(ch) % RULE_BUCKET_COUNT;
  75. return ruleMapFirst[key];
  76. } //}}}
  77. //{{{ getTerminateChar() method
  78. public int getTerminateChar()
  79. {
  80. return terminateChar;
  81. } //}}}
  82. //{{{ setTerminateChar() method
  83. public void setTerminateChar(int atChar)
  84. {
  85. terminateChar = (atChar >= 0) ? atChar : -1;
  86. } //}}}
  87. //{{{ getIgnoreCase() method
  88. public boolean getIgnoreCase()
  89. {
  90. return ignoreCase;
  91. } //}}}
  92. //{{{ setIgnoreCase() method
  93. public void setIgnoreCase(boolean b)
  94. {
  95. ignoreCase = b;
  96. } //}}}
  97. //{{{ getKeywords() method
  98. public KeywordMap getKeywords()
  99. {
  100. return keywords;
  101. } //}}}
  102. //{{{ setKeywords() method
  103. public void setKeywords(KeywordMap km)
  104. {
  105. keywords = km;
  106. } //}}}
  107. //{{{ getHighlightDigits() method
  108. public boolean getHighlightDigits()
  109. {
  110. return highlightDigits;
  111. } //}}}
  112. //{{{ setHighlightDigits() method
  113. public void setHighlightDigits(boolean highlightDigits)
  114. {
  115. this.highlightDigits = highlightDigits;
  116. } //}}}
  117. //{{{ getEscapeRule() method
  118. public ParserRule getEscapeRule()
  119. {
  120. return escapeRule;
  121. } //}}}
  122. //{{{ getEscapePattern() method
  123. public Segment getEscapePattern()
  124. {
  125. if (escapePattern == null && escapeRule != null)
  126. {
  127. escapePattern = new Segment(escapeRule.searchChars, 0,
  128. escapeRule.sequenceLengths[0]);
  129. }
  130. return escapePattern;
  131. } //}}}
  132. //{{{ setEscape() method
  133. public void setEscape(String esc)
  134. {
  135. if (esc == null)
  136. {
  137. escapeRule = null;
  138. }
  139. else
  140. {
  141. escapeRule = ParserRuleFactory.createEscapeRule(esc);
  142. }
  143. escapePattern = null;
  144. } //}}}
  145. //{{{ getDefault() method
  146. public byte getDefault()
  147. {
  148. return defaultToken;
  149. } //}}}
  150. //{{{ setDefault() method
  151. public void setDefault(byte def)
  152. {
  153. defaultToken = def;
  154. } //}}}
  155. //{{{ toString() method
  156. public String toString()
  157. {
  158. return getClass().getName() + "[" + mode.getName() + "::"
  159. + name + "]";
  160. } //}}}
  161. //{{{ Private members
  162. private static final int RULE_BUCKET_COUNT = 32;
  163. private String name;
  164. private Mode mode;
  165. private Hashtable props;
  166. private KeywordMap keywords;
  167. private ParserRule[] ruleMapFirst;
  168. private ParserRule[] ruleMapLast;
  169. private ParserRule escapeRule;
  170. private Segment escapePattern;
  171. private int terminateChar = -1;
  172. private boolean ignoreCase = true;
  173. private boolean highlightDigits;
  174. private byte defaultToken;
  175. //}}}
  176. }