xtc.util
Interface State


public interface State

The interface for a global parser state object.

To correctly integrate with a memoizing parser, global state for parsers generated by Rats! is modified through light-weight, nested transactions, as expressed through this interface.

A grammar utilizing global state needs to have a global stateful attribute, whose value is the name of the class implementing this interface. The class, in turn, must have a no-argument constructor, which is used to create the global state object.

Each production that resets the global state (i.e., serves as a top-level entry point) needs to be marked with the resetting attribute. At the beginning of the method representing such a production, the global state is reset by calling reset(String).

Each production that might modify the global state (or that depends on other productions that modify the global state) needs to be marked with the stateful attribute. At the beginning of the method representing such a production, a new transaction is started by calling start(). This transaction is completed on a successful parse by calling commit() and on an erroneous parse by calling abort().

Version:
$Revision: 1.9 $
Author:
Robert Grimm

Method Summary
 void abort()
          Abort a state-modifying transaction.
 void commit()
          Commit a state-modifying transaction.
 void reset(java.lang.String file)
          Reset the global state object.
 void start()
          Start a new state-modifying transaction.
 

Method Detail

reset

void reset(java.lang.String file)
Reset the global state object. This method is called at the beginning of each method representing a production with the resetting attribute.

Parameters:
file - The file name.

start

void start()
Start a new state-modifying transaction. This method is called at the beginning of each method representing a production with the stateful attribute.


commit

void commit()
Commit a state-modifying transaction. This method is called on a successful parse before returning from a method representing a production with the stateful attribute.


abort

void abort()
Abort a state-modifying transaction. This method is called on an erroneous parse before returning from a method representing a production with the stateful attribute.



Copyright © 2012. All Rights Reserved.