001: // $ANTLR : "theme.g" -> "ThemeParser.java"$
002:
003: package com.ivata.mask.web.theme.parser;
004:
005: import java.io.DataInputStream;
006: import java.io.StringReader;
007: import java.util.Properties;
008:
009: import org.apache.log4j.Logger;
010:
011: import antlr.ParserSharedInputState;
012: import antlr.RecognitionException;
013: import antlr.TokenBuffer;
014: import antlr.TokenStream;
015: import antlr.TokenStreamException;
016: import antlr.collections.impl.BitSet;
017:
018: /**
019: * <p>This is ivata's theme parser, automatically generated by
020: * <a href='http://www.antlr.org'>antlr</a>. This theme parser applies
021: * simple property values to HTML texts, to customize the appearance of theme
022: * sections.</p>
023: *
024: * <br/> $Log: ThemeParser.java,v $
025: * <br/> Revision 1.9 2005/10/12 18:35:57 colinmacleod
026: * <br/> Standardized format of Logger declaration - to make it easier to find instances
027: * <br/> which are not both static and final.
028: * <br/>
029: * <br/> Revision 1.8 2005/10/03 10:17:26 colinmacleod
030: * <br/> Fixed some style and javadoc issues.
031: * <br/>
032: * <br/> Revision 1.5 2005/04/12 11:07:40 colinmacleod
033: * <br/> Added logger to improve error
034: * <br/> handling.
035: * <br/> Checked for empty strings when
036: * <br/> converting numbers in lexer.
037: * <br/>
038: * <br/> Revision 1.4 2005/04/11 12:11:59 colinmacleod
039: * <br/> Fixed comment (removed HTML style start and
040: * <br/> end to comment).
041: * <br/>
042: * <br/> Revision 1.3 2005/04/09 18:04:22 colinmacleod
043: * <br/> Changed copyright text to GPL v2 explicitly.
044: * <br/>
045: * <br/> Revision 1.2 2005/01/19 13:07:19 colinmacleod
046: * <br/> Updated comment format to include version in since line.
047: * <br/>
048: * <br/> Revision 1.1 2005/01/06 22:03:49 colinmacleod
049: * <br/> Moved up a version number.
050: * <br/> Changed copyright notices to 2005.
051: * <br/> Updated the documentation:
052: * <br/> - started working on multiproject:site docu.
053: * <br/> - changed the logo.
054: * <br/> Added checkstyle and fixed LOADS of style issues.
055: * <br/> Added separate thirdparty subproject.
056: * <br/> Added struts (in web), util and webgui (in webtheme) from ivata op.
057: * <br/>
058: * <br/> Revision 1.3 2004/11/03 16:16:45 colinmacleod
059: * <br/> Removed System.out.print("TEST")
060: * <br/>
061: * <br/> Revision 1.2 2004/03/21 21:16:38 colinmacleod
062: * <br/> Shortened name to ivata op.
063: * <br/>
064: * <br/> Revision 1.1.1.1 2004/01/27 20:59:53 colinmacleod
065: * <br/> Moved ivata op to SourceForge.
066: * <br/>
067: * <br/> Revision 1.2 2003/10/15 14:13:40 colin
068: * <br/> fixinf for XDoclet
069: * <br/>
070: * <br/> Revision 1.3 2003/02/28 15:29:50 colin
071: * <br/> made CONDITIONAL_CONTENT optional to fix bug in tabs
072: * <br/>
073: * <br/> Revision 1.2 2003/02/28 13:59:25 colin
074: * <br/> updated to fix bug with some characters in CONDITIONAL_CONTENT
075: * <br/> implemented ATTRIBUTE_VALUE
076: * <br/>
077: * <br/> Revision 1.1 2003/02/24 19:33:33 colin
078: * <br/> Moved to new subproject.
079: * <br/>
080: * </i><br/><br/><hr>
081: *
082: * @since ivata masks 0.4 (2001-06-29)
083: * @author Colin MacLeod
084: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
085: * @version $Revision: 1.9 $
086: * @see com.ivata.mask.web.theme
087: */
088: public class ThemeParser extends antlr.LLkParser implements
089: ThemeParserTokenTypes {
090: /**
091: * Logger for this class
092: */
093: private static final Logger logger = Logger
094: .getLogger(ThemeLexer.class);
095:
096: /**
097: * <p>Parse the given string using the properties provided.</p>
098: *
099: * @param parseString the string containing PROPERTY, ATTRIBUTE and
100: * IFPROPERTY tokens to parse.
101: * @param properties all values of properties to be replaced in the
102: * <code>parseString</code>.
103: * @param name the name of the html section for error messages.
104: * @exception TokenStreamException thrown by the lexer.
105: * @exception RecognitionException thrown by the parser.
106: */
107: public static String parse(String parseString,
108: Properties properties, String name)
109: throws TokenStreamException, RecognitionException {
110: ThemeLexer lexer = new ThemeLexer(new StringReader(parseString));
111: lexer.setFilename(name);
112: lexer.setProperties(properties);
113: ThemeParser parser = new ThemeParser(lexer);
114: parser.setFilename(name);
115:
116: // Parse the input expression
117: parser.document();
118: return lexer.toString();
119: }
120:
121: /**
122: * <p>This main routine can be used to text the parser. It uses
123: * a dummy properties object with one property, "test" set to
124: * "myest". The string taken from standard in is parsed and
125: * output.</p>
126: *
127: * @param args this parameter is reserved for future use.
128: */
129: public static void main(String[] args) {
130: try {
131: System.out.println("Please enter your test...");
132: Properties properties = new Properties();
133: properties.setProperty("test", "mytest");
134: properties.setProperty("two", "2");
135: properties.setProperty("five", "5");
136: properties.setProperty("ten", "10");
137: properties.setProperty("fortyfive", "45");
138: ThemeLexer lexer = new ThemeLexer(new DataInputStream(
139: System.in));
140: lexer.setFilename("<stdin>");
141: lexer.setProperties(properties);
142: // lexer.setBuffer(buffer);
143: ThemeParser parser = new ThemeParser(lexer);
144: parser.setFilename("<stdin>");
145: // parser.setBuffer(buffer);
146: // Parse the input expression
147: parser.document();
148: } catch (TokenStreamException e) {
149: logger.error(e);
150: } catch (RecognitionException e) {
151: logger.error(e);
152: }
153: }
154:
155: protected ThemeParser(TokenBuffer tokenBuf, int k) {
156: super (tokenBuf, k);
157: tokenNames = _tokenNames;
158: }
159:
160: public ThemeParser(TokenBuffer tokenBuf) {
161: this (tokenBuf, 1);
162: }
163:
164: protected ThemeParser(TokenStream lexer, int k) {
165: super (lexer, k);
166: tokenNames = _tokenNames;
167: }
168:
169: public ThemeParser(TokenStream lexer) {
170: this (lexer, 1);
171: }
172:
173: public ThemeParser(ParserSharedInputState state) {
174: super (state, 1);
175: tokenNames = _tokenNames;
176: }
177:
178: public final void document() throws RecognitionException,
179: TokenStreamException {
180:
181: try { // for error handling
182: {
183: _loop3: do {
184: switch (LA(1)) {
185: case ATTRIBUTE: {
186: attribute();
187: break;
188: }
189: case PROPERTY: {
190: property();
191: break;
192: }
193: case CONDITION: {
194: condition();
195: break;
196: }
197: case MATH: {
198: math();
199: break;
200: }
201: default: {
202: break _loop3;
203: }
204: }
205: } while (true);
206: }
207: } catch (RecognitionException ex) {
208: reportError(ex);
209: recover(ex, _tokenSet_0);
210: }
211: }
212:
213: public final void attribute() throws RecognitionException,
214: TokenStreamException {
215:
216: try { // for error handling
217: match(ATTRIBUTE);
218: } catch (RecognitionException ex) {
219: reportError(ex);
220: recover(ex, _tokenSet_1);
221: }
222: }
223:
224: public final void property() throws RecognitionException,
225: TokenStreamException {
226:
227: try { // for error handling
228: match(PROPERTY);
229: } catch (RecognitionException ex) {
230: reportError(ex);
231: recover(ex, _tokenSet_1);
232: }
233: }
234:
235: public final void condition() throws RecognitionException,
236: TokenStreamException {
237:
238: try { // for error handling
239: match(CONDITION);
240: } catch (RecognitionException ex) {
241: reportError(ex);
242: recover(ex, _tokenSet_1);
243: }
244: }
245:
246: public final void math() throws RecognitionException,
247: TokenStreamException {
248:
249: try { // for error handling
250: match(MATH);
251: } catch (RecognitionException ex) {
252: reportError(ex);
253: recover(ex, _tokenSet_1);
254: }
255: }
256:
257: public static final String[] _tokenNames = { "<0>", "EOF", "<2>",
258: "NULL_TREE_LOOKAHEAD", "ATTRIBUTE", "MATH", "PROPERTY",
259: "CONDITION", "LPAREN", "RPAREN", "COLON", "COMMA",
260: "LBRACE", "RBRACE", "PLUS", "STAR", "SLASH", "MINUS",
261: "MATH_ATOM", "IDENTIFIER", "EMBEDDED_MATH",
262: "ADDITIVE_EXPRESSION", "MULTIPLICATIVE_EXPRESSION", "WS",
263: "CONDITIONAL_CONTENT", "EMBEDDED_PROPERTY_CONDITION",
264: "EMBEDDED_CONDITION", "CONDITION_ATOM",
265: "CONDITION_EXPRESSION", "EQUALS", "LESS", "LESS_EQUALS",
266: "GREATER", "GREATER_EQUALS", "ATTRIBUTE_VALUE",
267: "EMBEDDED_ATTRIBUTE", "EMBEDDED_PROPERTY", "IGNORE" };
268:
269: private static final long[] mk_tokenSet_0() {
270: long[] data = { 2L, 0L };
271: return data;
272: }
273:
274: public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
275:
276: private static final long[] mk_tokenSet_1() {
277: long[] data = { 242L, 0L };
278: return data;
279: }
280:
281: public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
282:
283: }
|