Skip to content

Commit

Permalink
Added example/choice.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Jan 17, 2024
1 parent 195746d commit 4e305b4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions example/choice.cc
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 4e305b4

Please sign in to comment.