-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathproto3_parse.cpp
More file actions
40 lines (34 loc) · 1.08 KB
/
proto3_parse.cpp
File metadata and controls
40 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2017-2026 Dr. Colin Hirsch and Daniel Frey
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#if !defined( __cpp_exceptions )
#include <iostream>
int main()
{
std::cerr << "Exception support required, example unavailable." << std::endl;
return 1;
}
#else
#include <iomanip>
#include <iostream>
#include <tao/pegtl.hpp>
#include <tao/pegtl/example/proto3.hpp>
namespace pegtl = TAO_PEGTL_NAMESPACE;
int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
{
using input_t = pegtl::text_file_input< pegtl::scan::lf_crlf >;
for( int i = 1; i < argc; ++i ) {
input_t in( argv[ i ] );
try {
pegtl::parse< pegtl::proto3::proto >( in );
}
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_at( p ) << '\n'
<< std::setw( int( p.column ) ) << '^' << '\n';
}
}
return 0;
}
#endif