You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
cpp-peglib/example/choice.cc

28 lines
489 B

//
// choice.cc
//
// Copyright (c) 2023 Yuji Hirose. All rights reserved.
// MIT License
//
#include <cstdlib>
#include <iostream>
#include <peglib.h>
using namespace peg;
int main(void) {
parser parser(R"(
type <- 'string' / 'int' / 'double'
%whitespace <- [ \t\r\n]*
)");
parser["type"] = [](const SemanticValues &vs) {
std::cout << vs.choice() << std::endl;
};
if (parser.parse("int")) { return 0; }
std::cout << "syntax error..." << std::endl;
return -1;
}