Source code: jpicedt/graphic/io/parser/AbstractRegularExpression.java
1 /* jPicEdt version 1.3.2, a picture editor for LaTeX.
2 Copyright (C) 1999-2002 Sylvain Reynal
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 Sylvain Reynal
19 Département de Physique
20 Ecole Nationale Supérieure de l'Electronique et de ses Applications (ENSEA)
21 6, avenue du Ponceau
22 95014 CERGY CEDEX
23 FRANCE
24
25 Tel : 00 +33 130 736 245
26 Fax : 00 +33 130 736 667
27 e-mail : reynal@ensea.fr
28 jPicEdt web page : http://www.jpicedt.org
29 */
30
31 package jpicedt.graphic.io.parser;
32
33
34 /**
35 * This is the abstract superclass for all regular expression that build up the LaTeX parser.
36 * It mimics the RegExp scheme, while at the same time allowing expression to send ParserEvent when
37 * a piece of text was successfully parsed (instead of delegating to a separate ParserHandler,
38 * events are handled directly in the core of the <code>action</code> method).
39 * A <code>Context</code> is then used to feed successive pieces of text to the reg-exp's that build up
40 * the grammar tree,
41 * and a <code>Pool</code> (currently implemented as an inner class of the LaTeXParser) allow reg-exp to
42 * share data.
43 */
44 public abstract class AbstractRegularExpression implements ExpressionConstants {
45
46 /**
47 * Parses this expression, possibly using Context to fetch the String to interpret
48 * if this Expression is a leaf expression.
49 * @return TRUE if parsing was successful
50 * @throws ParserException if an error occur during parsing
51 */
52 public abstract boolean interpret(Context c) throws ParserException;
53
54 /**
55 * Called during interpret operation at the end of a SUCCESSFUL interpret operation.
56 * Should be overriden by daughter classes to process proper action, e.g. set object properties...
57 * Current implementation does nothing.
58 */
59 public void action(ParserEvent e) throws ParserException {if (DEBUG) System.out.println(e);}
60
61 }