PageRenderTime 151ms CodeModel.GetById 138ms app.highlight 10ms RepoModel.GetById 1ms 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
  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
 24package org.gjt.sp.jedit.syntax;
 25
 26import java.util.*;
 27import org.gjt.sp.jedit.Mode;
 28import javax.swing.text.Segment;
 29
 30/**
 31 * A set of parser rules.
 32 * @author mike dillon
 33 * @version $Id: ParserRuleSet.java 3930 2001-12-02 07:34:52Z spestov $
 34 */
 35public class ParserRuleSet
 36{
 37	//{{{ ParserRuleSet constructor
 38	public ParserRuleSet(String name, Mode mode)
 39	{
 40		this.name = name;
 41		this.mode = mode;
 42		ruleMapFirst = new ParserRule[RULE_BUCKET_COUNT];
 43		ruleMapLast = new ParserRule[RULE_BUCKET_COUNT];
 44	} //}}}
 45
 46	//{{{ getMode() method
 47	public Mode getMode()
 48	{
 49		return mode;
 50	} //}}}
 51
 52	//{{{ getProperties() method
 53	public Hashtable getProperties()
 54	{
 55		return props;
 56	} //}}}
 57
 58	//{{{ setProperties() method
 59	public void setProperties(Hashtable props)
 60	{
 61		this.props = props;
 62	} //}}}
 63
 64	//{{{ addRule() method
 65	public void addRule(ParserRule r)
 66	{
 67		int key = Character.toUpperCase(r.searchChars[0])
 68			% RULE_BUCKET_COUNT;
 69		ParserRule last = ruleMapLast[key];
 70		if(last == null)
 71			ruleMapFirst[key] = ruleMapLast[key] = r;
 72		else
 73		{
 74			last.next = r;
 75			ruleMapLast[key] = r;
 76		}
 77	} //}}}
 78
 79	//{{{ getRules() method
 80	public ParserRule getRules(char ch)
 81	{
 82		int key = Character.toUpperCase(ch) % RULE_BUCKET_COUNT;
 83		return ruleMapFirst[key];
 84	} //}}}
 85
 86	//{{{ getTerminateChar() method
 87	public int getTerminateChar()
 88	{
 89		return terminateChar;
 90	} //}}}
 91
 92	//{{{ setTerminateChar() method
 93	public void setTerminateChar(int atChar)
 94	{
 95		terminateChar = (atChar >= 0) ? atChar : -1;
 96	} //}}}
 97
 98	//{{{ getIgnoreCase() method
 99	public boolean getIgnoreCase()
100	{
101		return ignoreCase;
102	} //}}}
103
104	//{{{ setIgnoreCase() method
105	public void setIgnoreCase(boolean b)
106	{
107		ignoreCase = b;
108	} //}}}
109
110	//{{{ getKeywords() method
111	public KeywordMap getKeywords()
112	{
113		return keywords;
114	} //}}}
115
116	//{{{ setKeywords() method
117	public void setKeywords(KeywordMap km)
118	{
119		keywords = km;
120	} //}}}
121
122	//{{{ getHighlightDigits() method
123	public boolean getHighlightDigits()
124	{
125		return highlightDigits;
126	} //}}}
127
128	//{{{ setHighlightDigits() method
129	public void setHighlightDigits(boolean highlightDigits)
130	{
131		this.highlightDigits = highlightDigits;
132	} //}}}
133
134	//{{{ getEscapeRule() method
135	public ParserRule getEscapeRule()
136	{
137		return escapeRule;
138	} //}}}
139
140	//{{{ getEscapePattern() method
141	public Segment getEscapePattern()
142	{
143		if (escapePattern == null && escapeRule != null)
144		{
145			escapePattern = new Segment(escapeRule.searchChars, 0,
146				escapeRule.sequenceLengths[0]);
147		}
148		return escapePattern;
149	} //}}}
150
151	//{{{ setEscape() method
152	public void setEscape(String esc)
153	{
154		if (esc == null)
155		{
156			escapeRule = null;
157		}
158		else
159		{
160			escapeRule = ParserRuleFactory.createEscapeRule(esc);
161		}
162		escapePattern = null;
163	} //}}}
164
165	//{{{ getDefault() method
166	public byte getDefault()
167	{
168		return defaultToken;
169	} //}}}
170
171	//{{{ setDefault() method
172	public void setDefault(byte def)
173	{
174		defaultToken = def;
175	} //}}}
176
177	//{{{ toString() method
178	public String toString()
179	{
180		return getClass().getName() + "[" + mode.getName() + "::"
181			+ name + "]";
182	} //}}}
183
184	//{{{ Private members
185	private static final int RULE_BUCKET_COUNT = 32;
186
187	private String name;
188	private Mode mode;
189	private Hashtable props;
190
191	private KeywordMap keywords;
192
193	private ParserRule[] ruleMapFirst;
194	private ParserRule[] ruleMapLast;
195
196	private ParserRule escapeRule;
197	private Segment escapePattern;
198	private int terminateChar = -1;
199	private boolean ignoreCase = true;
200	private boolean highlightDigits;
201	private byte defaultToken;
202	//}}}
203}