<<< CTTL_STATIC_RULE() function adaptor | Table Of Contents | CTTL_RULE() function adaptor >>> |
Common Text Transformation Library http://cttl.sourceforge.net/
Category:
Format:
CTTL_MEMBER_RULE() is a debugging macro:
CTTL_MEMBER_RULE( x, &C::mf ) // invokes class member function
where
and SubstrT is a typename of the CTTL substring class.
To formulate an instance of the pointer to a member function, the address-of operator '&' is required in front of the member function name. Additional syntax-related considerations are covered in member function pointers section of the documentation.
Algorithm:
Traceable member function adaptor implements a delayed function call. The adapted member function is invoked when lexer's algorithm reaches the function adaptor in its path of the grammar expression evaluation.
When grammar tracing mode is enabled, traceable member function adaptor captures and displays additional information, including
Space sensitivity:
The space sensitivity of a traceable member function adaptor is transparent; the encapsulated grammar rule controls the evaluation of the space grammar:
#include "cttl/cttl.h" using namespace cttl; template < typename SubstrT > struct Parser { size_t white_space( SubstrT& substr_ ) const { return ( begin( true ) ^ *entity( isspace ) ).match( substr_ ); } }; int main() { std::string inp = "123\t\t\tabc ???\n\n\n\nxyz"; const_edge< policy_space<> > substring( inp ); const_edge<> delimiter = substring; const_edge<> token = substring; typedef Parser< const_edge< policy_space<> > > parser_T; parser_T space_checker; while( ( token( entity( isgraph ) ) + delimiter( CTTL_MEMBER_RULE( space_checker, &parser_T::white_space ) ) ).match( substring ) != std::string::npos ) { std::cout << "Matched " << '[' << token << ']' << ", followed by " << delimiter.length() << " white space character(s)" << std::endl ; } return 0; } /*Output: Matched [123], followed by 3 white space character(s) Matched [abc], followed by 1 white space character(s) Matched [???], followed by 4 white space character(s) Matched [xyz], followed by 0 white space character(s) */
Searchability:
Example:
Usage of various C++ function formats is illustrated in production rule function documentation. The following sample demonstrates a simple call to the member function of the Parser struct, namely Parser<>::grab_all_input():
#define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" using namespace cttl; template < typename SubstrT = const_edge<> > struct Parser { size_t grab_all_input( SubstrT& substr_ ) const { size_t result = substr_.first.offset(); substr_.first = substr_.second; return result; } }; int main() { std::string inp = "ABC"; const_edge<> substring( inp ); const_edge<> everything = substring; Parser<> total_ravage; size_t result = everything( CTTL_MEMBER_RULE( total_ravage, &Parser<>::grab_all_input ) ).match( substring ); assert( result != std::string::npos ); assert( everything == inp ); return 0; }
Trace output format:
The trace generated by CTTL_MEMBER_RULE() function adaptor shows events of getting in and out of the C++ function call. A balanced pair of in/out traces includes C++ source line number where the call originated, and the result of grammar evaluation. Refer to CTTL_TRACE_RULES documentation for detailed description of the function adaptor trace output format. The above example generates the following trace:
---------------------@ABC?{e 0-3 :3:1 ---------------------@ABC--25->&Parser<>::grab_all_input@0-3 ------------------------@++25<-&Parser<>::grab_all_input@0-3 'ABC' ---------------------@ABC| e 0-3 }
Copyright © 1997-2009 Igor Kholodov mailto:cttl@users.sourceforge.net.
Permission to copy and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
<<< CTTL_STATIC_RULE() function adaptor | Table Of Contents | CTTL_RULE() function adaptor >>> |