<<< Lexeme begin(false) | Table Of Contents | Lexeme symbol(char) and entity(char) >>> |
Common Text Transformation Library http://cttl.sourceforge.net/
Category:
Format:
Algorithm:
The parseable substring is compared to a set of strings. Based on positive lookahead assertion algorithm, begin(std::set) lexeme does not change the boundaries of the parseable substring.
Successful grammar evaluation of begin(std::set) lexeme yields a zero-length symbol.
The implementation of the string set lexeme is reference-based. The lexer component stores only a reference to the std::set object. The set must stay in scope while string set lexeme remains in use.
The evaluation of begin(std::set) lexeme succeeds if one of the set elements matches the parseable substring exactly, including an empty substring:
#define CTTL_TRACE_EVERYTHING #include "cttl/cttl.h" using namespace cttl; int main() { std::string inp; const_edge<> substring( inp ); const_edge<> token = substring; // Prepare a set of keywords: std::set<std::string> str_set; str_set.insert( "" ); size_t result = token( begin( str_set ) ).match( substring ); assert( result != std::string::npos ); assert( token == "" ); return 0; }
Space sensitivity:
The space sensitivity of begin(std::set) lexeme is disabled. The space policy is ignored. Regardless of the space policy, the evaluation of begin(std::set) starts immediately at the position specified by the upper boundary of the parseable substring.
Searchability:
Usage example:
using namespace cttl; int main() { std::string inp = "double int bool"; const_edge< policy_space<> > substring( inp ); const_edge<> token = substring; // Prepare a set of keywords: std::set<std::string> data_type; data_type.insert( "int" ); data_type.insert( "bool" ); data_type.insert( "double" ); while ( ( token( entity( isalnum ) ) & data_type // shorthand for 'begin(data_type)' ).match( substring ) != std::string::npos ) { std::cout << token << std::endl; } return 0; }
Trace output format:
The trace symbol of begin(std::set) lexeme is uppercase 'S'.
The above code generates a trace like this:
---------@double int bool?{& 0-15
---------@double int bool? {e 0-15
:3:1
------------------double@| $ 6-15 isalnum
------------------@double| e 0-6
}
------------------------@| S 0-6
}
Note: CTTL tracing is not supported when the program is compiled in wide character mode.
Library sample string_set_lexeme.cpp demonstrates usage of the string set lexeme:
Keywords: string_set_lexeme.cpp, std::set, entity, begin
// sample code: string_set_lexeme.cpp // demonstrates begin( std::set< std::string > ) lexeme #include <iostream> #include "cttl/cttl.h" using namespace cttl; int main() { std::set< std::string > numbers; numbers.insert( "one" ); numbers.insert( "two" ); numbers.insert( "three" ); numbers.insert( "fourteen" ); std::string inp = "one two three four fourteen"; const_edge< policy_space<> > substring( inp ); const_edge<> data = substring; if ( data( +( entity( isalpha ) & begin( numbers ) ) ).match( substring ) != std::string::npos ) { std::cout << "data: /" << data << '/' << std::endl; } else { std::cout << "*** evaluation failed ***" << std::endl; return 1; } return 0; } /* program output: data: /one two three/ */
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 begin(false) | Table Of Contents | Lexeme symbol(char) and entity(char) >>> |