Main Page | Namespace List | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

offset_stack_guard Class Template Reference

#include <offset_stack_guard.h>

List of all members.


Detailed Description

template<typename UniverseT>
class cttl::offset_stack_guard< UniverseT >

Utility class to track cttl::input positions.

UniverseT
Template parameter specifying type of the parseable universe. Can be either cttl::const_edge or cttl::edge.
If content of the CTTL input mutates at run time, the parser must rely on guarded logical positions of input symbols. For example, stream parsers routinely discard parts of already consumed input. In such case tracking input positions for error reporting may become problematic, especially when dealing with nested grammar constructs. Using offset_stack_guard utility class simplifies this task.


Class offset_stack_guard uses CTTL offset management mechanism to keep track of input positions which represent significant logical positions of the input language constructs.

Usage
To use the guard, user program creates a stack of offsets variable:
    std::stack< size_t > xml_offset_stack;
Any grammar rule which has to keep track of original input position, can create an instance of offset guard object as follows:
    size_t xml_grammar( universe_T& universe_ )
    {
        offset_stack_guard< universe_T > error_info( this->xml_offset_stack, universe_.first );
        // ...
    }
Constructor of the guard class takes two arguments: an instance of the user stack, and logical input position pointed by CTTL node object. If parser detects an error, it can obtain guarded offset as follows:
    void show_error( universe_T& universe_ )
    {
        size_t offset = offset_stack_guard< universe_T >::offset( universe_, xml_offset_stack.top() );
        // ...
    }
Note that in case of nested grammars, implementation of show_error() function remains generic enough to report correct offsets, since the stack is properly unwound by destructors of each offset guard object when nested grammar rule calls return.

Definition at line 93 of file offset_stack_guard.h.

Public Member Functions

 offset_stack_guard (std::stack< size_t > &offset_stack_, node_T &node_)
 Constructs and initializes the object.
 ~offset_stack_guard ()
 Destructor removes stack identity of the offset managed by this object.
void operator= (offset_stack_guard< UniverseT > const &) const
 Assignment does nothing.

Static Public Member Functions

size_t offset (UniverseT const &universe_, size_t stack_identity_)
 Returns curent offset for the specified stack identity.

Protected Types

typedef UniverseT::offset_manager_T offset_guard_T
 Defines type of offset management class provided by the universe.
typedef UniverseT::node_T node_T
 Defines node type of the universe.

Protected Attributes

offset_guard_T m_offset_manager
 Instance of offset manager.
std::stack< size_t > & m_offset_stack
 Reference to the stack of managed identities, maintained by this guard.


Member Typedef Documentation

typedef UniverseT::node_T node_T [protected]
 

Defines node type of the universe.

Definition at line 100 of file offset_stack_guard.h.

typedef UniverseT::offset_manager_T offset_guard_T [protected]
 

Defines type of offset management class provided by the universe.

Definition at line 97 of file offset_stack_guard.h.


Constructor & Destructor Documentation

offset_stack_guard std::stack< size_t > &  offset_stack_,
node_T node_
[inline]
 

Constructs and initializes the object.

Definition at line 114 of file offset_stack_guard.h.

~offset_stack_guard  )  [inline]
 

Destructor removes stack identity of the offset managed by this object.

Definition at line 123 of file offset_stack_guard.h.


Member Function Documentation

size_t offset UniverseT const &  universe_,
size_t  stack_identity_
[inline, static]
 

Returns curent offset for the specified stack identity.

Definition at line 129 of file offset_stack_guard.h.

void operator= offset_stack_guard< UniverseT > const &   )  const [inline]
 

Assignment does nothing.

Definition at line 135 of file offset_stack_guard.h.


Member Data Documentation

offset_guard_T m_offset_manager [protected]
 

Instance of offset manager.

Definition at line 104 of file offset_stack_guard.h.

std::stack< size_t >& m_offset_stack [protected]
 

Reference to the stack of managed identities, maintained by this guard.

Definition at line 107 of file offset_stack_guard.h.


The documentation for this class was generated from the following file:
Generated on Thu Nov 2 17:43:48 2006 for CTTL Utility Classes and Functions by  doxygen 1.3.9.1