3 #include <tao/pegtl.hpp>
4 #include <tao/pegtl/contrib/abnf.hpp>
5 #include <tao/pegtl/contrib/alphabet.hpp>
7 using namespace tao::pegtl
;
8 using namespace tao::pegtl::abnf
;
9 using namespace tao::pegtl::alphabet
;
11 #include <glog/logging.h>
18 struct String
: plus
<sor
<ALPHA
, DIGIT
>> {
21 struct foo
: seq
<TAOCPP_PEGTL_ISTRING("FOO"), opt
<SP
, String
>, CRLF
> {
24 struct bar
: seq
<TAOCPP_PEGTL_ISTRING("BAR "), String
, CRLF
> {
27 struct baz
: seq
<TAOCPP_PEGTL_ISTRING("BAZ"), CRLF
> {
30 struct quit
: seq
<TAOCPP_PEGTL_ISTRING("QUIT"), CRLF
> {
33 struct lng
: seq
<TAOCPP_PEGTL_ISTRING("SUPERLONGTHING"), CRLF
> {
36 struct any_cmd
: seq
<sor
<baz
, foo
, bar
, quit
, lng
>, discard
> {
39 struct cmds
: plus
<any_cmd
> {
42 struct grammar
: seq
<cmds
, eof
> {
45 template <typename Rule
>
46 struct action
: nothing
<Rule
> {
51 template <typename Input
>
52 static void apply(const Input
& in
, Ctx
& ctx
)
55 if (in
.string().length())
56 std::cout
<< " " << in
.string();
63 template <typename Input
>
64 static void apply(const Input
& in
, Ctx
& ctx
)
66 std::cout
<< "bar " << in
.string() << '\n';
72 static void apply0(Ctx
& ctx
) { std::cout
<< "baz\n"; }
77 static void apply0(Ctx
& ctx
) { std::cout
<< "quit\n"; }
81 int main(int argc
, char const* argv
[])
83 std::ios::sync_with_stdio(false);
84 google::InitGoogleLogging(argv
[0]);
87 istream_input
<eol::crlf
> in(std::cin
, 20, "cin");
89 std::cout
<< "250 start\n";
92 LOG(INFO
) << "calling parse";
93 parse
<smtp::grammar
, smtp::action
>(in
, ctx
);
94 LOG(INFO
) << "parse return";
96 catch (parse_error
const& e
) {
97 std::cout
<< e
.what() << '\n';