| PatternElement.java |
1 /*
2 * PatternElement.java - transducer class
3 *
4 * Copyright (c) 1998-2004, The University of Sheffield.
5 *
6 * This file is part of GATE (see http://gate.ac.uk/), and is free
7 * software, licenced under the GNU Library General Public License,
8 * Version 2, June 1991 (in the distribution as file licence.html,
9 * and also available at http://gate.ac.uk/gate/licence.html).
10 *
11 * Hamish Cunningham, 24/07/98
12 *
13 * $Id: PatternElement.java,v 1.6 2004/07/21 17:10:08 akshay Exp $
14 */
15
16
17 package gate.jape;
18
19 import java.util.Stack;
20
21 import gate.AnnotationSet;
22
23
24 /**
25 * Superclass of the various types of pattern element, and of
26 * ConstraintGroup. Inherits from Matcher, providing matches and reset.
27 * Provides access to the annotations that are cached by subclasses, and
28 * multilevel rollback of those caches. Stores the match history.
29 */
30 abstract public class PatternElement implements Cloneable, Matcher,
31 JapeConstants, java.io.Serializable
32 {
33 /** Debug flag */
34 private static final boolean DEBUG = false;
35
36 /** Match history stack, for use in rollback. In BasicPatternElements
37 * the objects on the stack are Integers giving the number of annots that
38 * were cached at that point in the history. In ComplexPatternElements
39 * the objects are Integers giving the number of times the component
40 * ConstraintGroup was successfully matched. In ConstraintGroups the
41 * elements are arrays representing conjunctions of PatternElement that
42 * succeeded at that point in the history.
43 */
44 protected Stack matchHistory;
45
46 /** Anonymous construction. */
47 public PatternElement() {
48 matchHistory = new Stack();
49 } // Anonymous constructor.
50
51 /** Cloning for processing of macro references. Note that it doesn't
52 * really clone the match history, just set it to a new Stack. This is
53 * because a) JGL doesn't have real clone methods and b) we don't
54 * actually need it anywhere but during parsing the .jape, where there
55 * is no match history yet.
56 */
57 public Object clone() {
58 try {
59 PatternElement newPE = (PatternElement) super.clone();
60 newPE.matchHistory = new Stack();
61 return newPE;
62 } catch(CloneNotSupportedException e) {
63 throw(new InternalError(e.toString()));
64 }
65 } // clone
66
67 /** Access to the annotations that have been matched. */
68 abstract public AnnotationSet getMatchedAnnots();
69
70 /** Multilevel rollback of annotation caches. */
71 abstract public void rollback(int arity);
72
73 /** Reset: clear annotation caches etc. Most of the behaviour of
74 * this method is the responsibility of subclasses.
75 */
76 public void reset() {
77 matchHistory = new Stack();
78 } // reset
79
80 /** Create a string representation of the object with padding. */
81 abstract public String toString(String pad);
82
83 } // class PatternElement
84
85
86 // $Log: PatternElement.java,v $
87 // Revision 1.6 2004/07/21 17:10:08 akshay
88 // Changed copyright from 1998-2001 to 1998-2004
89 //
90 // Revision 1.5 2004/03/25 13:01:14 valyt
91 // Imports optimisation throughout the Java sources
92 // (to get rid of annoying warnings in Eclipse)
93 //
94 // Revision 1.4 2000/11/08 16:35:03 hamish
95 // formatting
96 //
97 // Revision 1.3 2000/10/16 16:44:34 oana
98 // Changed the comment of DEBUG variable
99 //
100 // Revision 1.2 2000/10/10 15:36:36 oana
101 // Changed System.out in Out and System.err in Err;
102 // Added the DEBUG variable seted on false;
103 // Added in the header the licence;
104 //
105 // Revision 1.1 2000/02/23 13:46:09 hamish
106 // added
107 //
108 // Revision 1.1.1.1 1999/02/03 16:23:02 hamish
109 // added gate2
110 //
111 // Revision 1.8 1998/11/03 19:06:49 hamish
112 // java stack, not jgl stack for matchHistory
113 //
114 // Revision 1.7 1998/11/01 23:18:44 hamish
115 // use new instead of clear on containers
116 //
117 // Revision 1.6 1998/09/26 09:19:18 hamish
118 // added cloning of PE macros
119 //
120 // Revision 1.5 1998/08/12 15:39:41 hamish
121 // added padding toString methods
122 //
123 // Revision 1.4 1998/08/03 19:51:24 hamish
124 // rollback added
125 //
126 // Revision 1.3 1998/07/30 11:05:22 hamish
127 // more jape
128 //
129 // Revision 1.2 1998/07/29 11:07:06 hamish
130 // first compiling version
131 //
132 // Revision 1.1.1.1 1998/07/28 16:37:46 hamish
133 // gate2 lives
134