mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
30 lines
522 B
C++
30 lines
522 B
C++
//
|
|
// sequence.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"(
|
|
START <- SEQUENCE_A
|
|
SEQUENCE_A <- SEQUENCE('A')
|
|
SEQUENCE(X) <- X (',' X)*
|
|
)");
|
|
|
|
parser["SEQUENCE_A"] = [](const SemanticValues & /*vs*/) {
|
|
std::cout << "SEQUENCE_A" << std::endl;
|
|
};
|
|
|
|
if (parser.parse("A,A")) { return 0; }
|
|
|
|
std::cout << "syntax error..." << std::endl;
|
|
return -1;
|
|
}
|