<<< Lexeme end() | Table Of Contents | Lexeme symbol(false) >>> |
Common Text Transformation Library http://cttl.sourceforge.net/
Category:
Format:
Algorithm:
The symbol(true) lexeme matches an empty symbol in the input language, called epsilon symbol, or empty match.
The symbol(true) lexeme succeeds, unless parseable substring is empty.
If parseable substring is empty, the symbol(true) lexeme always fails.
The symbol(true) validates that at least one character is available from the character sequence specified by the parseable substring.
Space sensitivity:
The space sensitivity of symbol(true) lexeme is disabled. The space policy is ignored. Regardless of the space policy, the evaluation of symbol(true) lexeme starts immediately at the position specified by the upper boundary of the parseable substring.
Searchability:
Search grammar evaluation algorithms
are enabled for symbol(true) lexeme. The grammar evaluation
symbol( true ).find( substring )
always succeeds. The search algorithm of symbol(true) lexeme matches empty symbol at the upper boundary of the parseable substring:
#define CTTL_TRACE_EVERYTHING
#include "cttl/cttl.h"
using namespace cttl;
int main()
{
std::string inp; // empty string
const_edge<> substring( inp );
node<> start = substring.first;
size_t result = start( symbol( true ) ).find( substring );
assert( result == 0 );
assert( start.offset() == 0 );
return 0;
}
The implementation of the symbol(true) search algorithm is identical to the behavior of begin(true) search algorithm.
Usage:
symbol( true ) ^ R
where R is a valid CTTL grammar expression, and operator^ is the binary concatenation operator.
Overloaded binary concatenation operator^ allows shorthand notation when used with symbol(true) lexeme:
true ^ R
Example:
#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 = ( // 'true' is shorthand for 'symbol(true)' lexeme: true ^ token( entity( isspace ) ) ).match( substring ); assert( result != std::string::npos ); assert( token.length() == 5 ); return 0; }
Trace output format:
The trace output of symbol(true) lexeme is digit '1'. Grammar evaluation
symbol( true ).match( substring )
generates a trace line
------------------------@|1 0-3
If symbol(true) lexeme fails, the trace is annotated by informative message.
#define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" using namespace cttl; int main() { std::string inp; // empty input const_edge< policy_space<> > substring( inp ); const_edge<> token = substring; size_t result = ( symbol( true )^token( entity() ) ).match( substring ); assert( result == std::string::npos ); return 0; }
Trace output:
------------------------@?{^ 0-0 ~~~~~~~~~~~~~~~~~~~~~~~~@~ 1 0-0 FAIL epsilon match: empty substring ~~~~~~~~~~~~~~~~~~~~~~~~@~ ^ 0-0 FAIL }
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 end() | Table Of Contents | Lexeme symbol(false) >>> |