XTL  0.1
eXtended Template Library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
example_parse1.cpp
#include <xtd/parse.hpp>
namespace command_line {
using namespace xtd::parse;
//termnals
STRING(red, "red");
STRING(green, "green");
STRING(blue, "blue");
STRING(one, "1");
STRING(three, "3");
STRING(five, "5");
STRING(dash_color, "--color=");
STRING(dash_prime, "--prime=");
//rules
using rgb = or_<red, green, blue>;
using prime_num = or_<one, three, five>;
using color_param = and_<dash_color, rgb>;
using prime_param = and_<dash_prime, prime_num>;
using parameter = or_<color_param, prime_param>;
}
int main(int, char * argv[]){
std::string sParam = argv[1];
auto oAST = xtd::parser<command_line::parameter>::parse(sParam.cbegin(), sParam.cend());
if (!oAST){
//parse failed, show usage or error
return 1;
}else{
//work with parsed parameters
return 0;
}
}