-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathjson_coverage.cpp
More file actions
52 lines (45 loc) · 1.56 KB
/
json_coverage.cpp
File metadata and controls
52 lines (45 loc) · 1.56 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
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2020-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)
#include <iomanip>
#include <iostream>
#include <tao/pegtl.hpp>
#include <tao/pegtl/debug/coverage.hpp>
#include <tao/pegtl/debug/print_coverage.hpp>
#include <tao/pegtl/example/json.hpp>
#include "json_errors.hpp"
namespace pegtl = TAO_PEGTL_NAMESPACE;
namespace example
{
using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >;
} // namespace example
int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
{
if( argc != 2 ) {
std::cerr << "Usage: " << argv[ 0 ] << " FILE\n"
<< "Print coverage of parsing FILE as JSON." << std::endl;
return 1;
}
using input_t = pegtl::text_file_input< pegtl::scan::lf >;
input_t in( argv[ 1 ] );
pegtl::coverage_result result;
#if defined( __cpp_exceptions )
try {
pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result );
}
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 ) ) << '^' << std::endl;
return 1;
}
#else
if( !pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result ) ) {
std::cerr << "Error occurred -- exceptions disabled" << std::endl;
return 1;
}
#endif
std::cout << result;
return 0;
}