cttl::guard_node_stack< NodeT > Class Template Reference

Utility class to track positions of parseable substrings. More...

#include <guard_node_stack.h>

List of all members.

Public Member Functions

 guard_node_stack (std::stack< NodeT > &node_stack_, NodeT const &node_)
 Constructs and initializes the object.
 ~guard_node_stack ()
 Destructor removes stack identity of the offset managed by this object.

Protected Attributes

std::stack< NodeT > & m_node_stack
 Reference to the stack of nodes.


Detailed Description

template<typename NodeT>
class cttl::guard_node_stack< NodeT >

Utility class to track positions of parseable substrings.

Template Parameters:
UniverseT specifies type of the parseable universe. Can be either cttl::const_edge or cttl::edge.
Remarks:
When 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 guard_node_stack utility class simplifies this task.
Class guard_node_stack uses CTTL position tracking mechanism to preserve significant logical positions of inside user input.
Usage

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

Definition at line 94 of file guard_node_stack.h.


Constructor & Destructor Documentation

template<typename NodeT>
cttl::guard_node_stack< NodeT >::guard_node_stack ( std::stack< NodeT > &  node_stack_,
NodeT const &  node_ 
)

Constructs and initializes the object.

Definition at line 105 of file guard_node_stack.h.

00106         :
00107     m_node_stack( node_stack_ )
00108     {
00109         m_node_stack.push( node_ );
00110     }

template<typename NodeT>
cttl::guard_node_stack< NodeT >::~guard_node_stack (  ) 

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

Definition at line 113 of file guard_node_stack.h.

00114     {
00115         m_node_stack.pop();
00116     }


Member Data Documentation

template<typename NodeT>
std::stack< NodeT >& cttl::guard_node_stack< NodeT >::m_node_stack [protected]

Reference to the stack of nodes.

Definition at line 98 of file guard_node_stack.h.


The documentation for this class was generated from the following file:

Generated on Sat Aug 22 22:33:54 2009 for Common Text Transformation Library by  doxygen 1.5.9