From 4e305b423b06ef8442d540cc486dd158a71b000c Mon Sep 17 00:00:00 2001 From: yhirose Date: Wed, 17 Jan 2024 10:53:33 -0500 Subject: [PATCH] Added example/choice.cc --- example/choice.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 example/choice.cc diff --git a/example/choice.cc b/example/choice.cc new file mode 100644 index 0000000..a3445a2 --- /dev/null +++ b/example/choice.cc @@ -0,0 +1,28 @@ +// +// choice.cc +// +// Copyright (c) 2023 Yuji Hirose. All rights reserved. +// MIT License +// + +#include +#include +#include + +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; +}