1 // Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
2 // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3 
4 #include <iostream>
5 #include <string>
6 
7 #include <tao/pegtl.hpp>
8 
9 namespace pegtl = TAO_PEGTL_NAMESPACE;
10 
11 namespace hello
12 {
13    // clang-format off
14    struct prefix : pegtl::string< 'H', 'e', 'l', 'l', 'o', ',', ' ' > {};
15    struct name : pegtl::plus< pegtl::alpha > {};
16    struct grammar : pegtl::must< prefix, name, pegtl::one< '!' >, pegtl::eof > {};
17    // clang-format on
18 
19    template< typename Rule >
20    struct action
21    {};
22 
23    template<>
24    struct action< name >
25    {
26       template< typename ActionInput >
applyhello::action27       static void apply( const ActionInput& in, std::string& v )
28       {
29          v = in.string();
30       }
31    };
32 
33 }  // namespace hello
34 
main(int argc,char ** argv)35 int main( int argc, char** argv )  // NOLINT(bugprone-exception-escape)
36 {
37    if( argc > 1 ) {
38       std::string name;
39 
40       pegtl::argv_input in( argv, 1 );
41       pegtl::parse< hello::grammar, hello::action >( in, name );
42 
43       std::cout << "Good bye, " << name << "!" << std::endl;
44    }
45 }
46