| PatternElement |

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

| PatternElement |