PatternElement.java
001 /* 
002  *  PatternElement.java - transducer class
003  *
004  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
005  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006  *
007  *  This file is part of GATE (see http://gate.ac.uk/), and is free
008  *  software, licenced under the GNU Library General Public License,
009  *  Version 2, June 1991 (in the distribution as file licence.html,
010  *  and also available at http://gate.ac.uk/gate/licence.html).
011  *
012  *  Hamish Cunningham, 24/07/98
013  *
014  *  $Id: PatternElement.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015  */
016 
017 
018 package gate.jape;
019 
020 import java.util.Stack;
021 
022 import gate.AnnotationSet;
023 
024 
025 /**
026   * Superclass of the various types of pattern element, and of
027   * ConstraintGroup. Inherits from Matcher, providing matches and reset.
028   * Provides access to the annotations that are cached by subclasses, and
029   * multilevel rollback of those caches. Stores the match history.
030   */
031 abstract public class PatternElement implements Cloneable, 
032           JapeConstants, java.io.Serializable
033 {
034   /** Debug flag */
035   private static final boolean DEBUG = false;
036 
037   /** Match history stack, for use in rollback. In BasicPatternElements
038     * the objects on the stack are Integers giving the number of annots that
039     * were cached at that point in the history. In ComplexPatternElements
040     * the objects are Integers giving the number of times the component
041     * ConstraintGroup was successfully matched. In ConstraintGroups the
042     * elements are arrays representing conjunctions of PatternElement that
043     * succeeded at that point in the history.
044     */
045   protected Stack matchHistory;
046 
047   /** Anonymous construction. */
048   public PatternElement() {
049     matchHistory = new Stack();
050   // Anonymous constructor.
051 
052   /** Cloning for processing of macro references. Note that it doesn't
053     * really clone the match history, just set it to a new Stack. This is
054     * because a) JGL doesn't have real clone methods and b) we don't
055     * actually need it anywhere but during parsing the .jape, where there
056     * is no match history yet.
057     */
058   public Object clone() {
059     try {
060       PatternElement newPE = (PatternElementsuper.clone();
061       newPE.matchHistory = new Stack();
062       return newPE;
063     catch(CloneNotSupportedException e) {
064       throw(new InternalError(e.toString()));
065     }
066   // clone
067 
068 
069   /**
070    * Finishes the JAPE language parsing, building all the in-memory structures 
071    * required. 
072    */
073   public abstract void finish();
074   /** Create a string representation of the object with padding. */
075   abstract public String toString(String pad);
076 
077 // class PatternElement
078 
079 
080 // $Log$
081 // Revision 1.7  2005/01/11 13:51:36  ian
082 // Updating copyrights to 1998-2005 in preparation for v3.0
083 //
084 // Revision 1.6  2004/07/21 17:10:08  akshay
085 // Changed copyright from 1998-2001 to 1998-2004
086 //
087 // Revision 1.5  2004/03/25 13:01:14  valyt
088 // Imports optimisation throughout the Java sources
089 // (to get rid of annoying warnings in Eclipse)
090 //
091 // Revision 1.4  2000/11/08 16:35:03  hamish
092 // formatting
093 //
094 // Revision 1.3  2000/10/16 16:44:34  oana
095 // Changed the comment of DEBUG variable
096 //
097 // Revision 1.2  2000/10/10 15:36:36  oana
098 // Changed System.out in Out and System.err in Err;
099 // Added the DEBUG variable seted on false;
100 // Added in the header the licence;
101 //
102 // Revision 1.1  2000/02/23 13:46:09  hamish
103 // added
104 //
105 // Revision 1.1.1.1  1999/02/03 16:23:02  hamish
106 // added gate2
107 //
108 // Revision 1.8  1998/11/03 19:06:49  hamish
109 // java stack, not jgl stack for matchHistory
110 //
111 // Revision 1.7  1998/11/01 23:18:44  hamish
112 // use new instead of clear on containers
113 //
114 // Revision 1.6  1998/09/26 09:19:18  hamish
115 // added cloning of PE macros
116 //
117 // Revision 1.5  1998/08/12 15:39:41  hamish
118 // added padding toString methods
119 //
120 // Revision 1.4  1998/08/03 19:51:24  hamish
121 // rollback added
122 //
123 // Revision 1.3  1998/07/30 11:05:22  hamish
124 // more jape
125 //
126 // Revision 1.2  1998/07/29 11:07:06  hamish
127 // first compiling version
128 //
129 // Revision 1.1.1.1  1998/07/28 16:37:46  hamish
130 // gate2 lives