<<< Lexeme symbol() | Table Of Contents | Lexeme begin() >>> |
Common Text Transformation Library http://cttl.sourceforge.net/
Category:
Format:
Algorithm:
Matches sequence of characters specified by the boundaries of parseable substring.
The entity() lexeme is defined as a leximatic metaphor: the expressions
entity() begin( true ) + !end()
are equivalent.
The entity() lexeme always succeeds, including a case when the parseable substring is empty:
#define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" using namespace cttl; int main() { std::string inp; // empty string const_edge<> substring( inp ); const_edge<> token = substring; size_t result = token( entity() ).match( substring ); assert( result != std::string::npos ); assert( token.length() == 0 ); return 0; }
The entity() lexeme also succeeds when the parseable substring is an invalid substring:
#define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" using namespace cttl; int main() { std::string inp = "ABC"; const_edge<> substring( inp ); const_edge<> token = substring; // Make invalid substring: std::swap( substring.first, substring.second ); size_t result = token( entity() ).match( substring ); assert( result != std::string::npos ); assert( token.length() == std::string::npos ); return 0; }
The trace output from the above sample is:
------------***INVALID***?{e 3-0 :3:1 ------------***INVALID***? {; 3-0 ------------***INVALID***| 1 3-0 ------------***INVALID***? {! 3-0 ------------------------@| Z 0-0 EOF } } ------------***INVALID***| e 3-0 }
Space sensitivity:
The space sensitivity of entity() lexeme is disabled. The space policy is ignored. Regardless of the space policy, the evaluation of entity() begins immediately at the position specified by upper boundary of the parseable substring:
#define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" using namespace cttl; int main() { std::string inp( 5, ' ' ); // string with five spaces const_edge< policy_space<> > substring( inp ); const_edge<> token = substring; size_t result = token( entity() ).match( substring ); assert( result != std::string::npos ); assert( token.length() == 5 ); return 0; }
Searchability:
Search grammar evaluation algorithms
are syntactically enabled for entity() lexeme, but have no effect: in either case match() grammar evaluation algorithm is executed by the lexer, as demonstrated by the following fragment:
#define CTTL_TRACE_EVERYTHING
#include "cttl/cttl.h"
using namespace cttl;
int main()
{
std::string inp = " A B C ";
const_edge< policy_space<> > substring( inp );
const_edge<> token = substring;
size_t result = token( entity() ).find( substring );
assert( result != std::string::npos );
assert( token == " A B C " );
return 0;
}
Since search operators are enabled, but have no effect on the entity() lexeme, the expressions
entity().match( substring ) entity().find( substring ) entity().bang_find( substring )
are equivalent.
Trace output format:
The trace output of entity() lexeme is equivalent to the trace produced by the grammar expression
begin( true ) + !end()
For example,
---------------------@ABC?{; 0-3 ------------------------@| 1 0-3 ---------------------@ABC? {! 0-3 ---------------------ABC@| Z 3-3 EOF } }
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.
<<< Lexeme symbol() | Table Of Contents | Lexeme begin() >>> |