mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2025-01-22 13:25:30 +00:00
Added example/choice.cc
This commit is contained in:
parent
195746dedd
commit
4e305b423b
28
example/choice.cc
Normal file
28
example/choice.cc
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user