Skip to content

Commit 44db0ac

Browse files
committed
Update embedded PEGTL
1 parent d380c63 commit 44db0ac

File tree

22 files changed

+141
-139
lines changed

22 files changed

+141
-139
lines changed

include/tao/json/external/pegtl/analysis/analyze_cycles.hh

Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -49,101 +49,46 @@ namespace tao_json_pegtl
4949
if ( j != m_cache.end() ) {
5050
return j->second;
5151
}
52-
const auto g = make_insert_guard( m_stack, start->first );
53-
54-
if ( g ) {
52+
if ( const auto g = make_insert_guard( m_stack, start->first ) ) {
5553
switch ( start->second.type ) {
56-
case rule_type::PLUS:
57-
{
54+
case rule_type::ANY: {
5855
bool a = false;
59-
for ( std::size_t i = 0; i < start->second.rules.size(); ++i ) {
60-
a |= work( find( start->second.rules[ i ] ), accum || a );
61-
}
62-
if ( ! a ) {
63-
++m_problems;
64-
if ( m_verbose ) {
65-
std::cout << "problem: rules without progress detected in rule of type plus " << start->first << std::endl;
66-
}
56+
for ( const auto & r : start->second.rules ) {
57+
a |= work( find( r ), accum || a );
6758
}
68-
return m_cache[ start->first ] = a;
59+
return m_cache[ start->first ] = true;
6960
}
70-
case rule_type::STAR:
71-
{
61+
case rule_type::OPT: {
7262
bool a = false;
73-
for ( std::size_t i = 0; i < start->second.rules.size(); ++i ) {
74-
a |= work( find( start->second.rules[ i ] ), accum || a );
75-
}
76-
if ( ! a ) {
77-
++m_problems;
78-
if ( m_verbose ) {
79-
std::cout << "problem: rules without progress detected in rule of type star " << start->first << std::endl;
80-
}
63+
for ( const auto & r : start->second.rules ) {
64+
a |= work( find( r ), accum || a );
8165
}
8266
return m_cache[ start->first ] = false;
8367
}
84-
case rule_type::SEQ:
85-
{
68+
case rule_type::SEQ: {
8669
bool a = false;
87-
for ( std::size_t i = 0; i < start->second.rules.size(); ++i ) {
88-
a |= work( find( start->second.rules[ i ] ), accum || a );
70+
for ( const auto & r : start->second.rules ) {
71+
a |= work( find( r ), accum || a );
8972
}
9073
return m_cache[ start->first ] = a;
9174
}
92-
case rule_type::SOR:
93-
{
75+
case rule_type::SOR: {
9476
bool a = true;
95-
for ( std::size_t i = 0; i < start->second.rules.size(); ++i ) {
96-
a &= work( find( start->second.rules[ i ] ), accum );
77+
for ( const auto & r : start->second.rules ) {
78+
a &= work( find( r ), accum );
9779
}
9880
return m_cache[ start->first ] = a;
9981
}
100-
case rule_type::ANY:
101-
{
102-
for ( std::size_t i = 0; i < start->second.rules.size(); ++i ) {
103-
work( find( start->second.rules[ i ] ), accum );
104-
}
105-
return m_cache[ start->first ] = true;
106-
}
107-
case rule_type::OPT:
108-
{
109-
for ( std::size_t i = 0; i < start->second.rules.size(); ++i ) {
110-
work( find( start->second.rules[ i ] ), accum );
111-
}
112-
return m_cache[ start->first ] = false;
113-
}
114-
case rule_type::UNTIL:
115-
{
116-
bool a = false;
117-
for ( std::size_t i = 1; i < start->second.rules.size(); ++i ) {
118-
a |= work( find( start->second.rules[ i ] ), accum || a );
119-
}
120-
if ( ! a ) {
121-
++m_problems;
122-
if ( m_verbose ) {
123-
std::cout << "problem: rules without progress detected in until " << start->first << std::endl;
124-
}
125-
}
126-
return m_cache[ start->first ] = work( find( start->second.rules[ 0 ] ), accum );
127-
}
128-
case rule_type::IF:
129-
{
130-
assert( start->second.rules.size() == 3 );
131-
const bool c = work( find( start->second.rules[ 0 ] ), accum ); // Cond
132-
const bool t = work( find( start->second.rules[ 1 ] ), accum || c ); // Rule
133-
const bool e = work( find( start->second.rules[ 2 ] ), accum ); // Else
134-
return m_cache[ start->first ] = ( c || t ) && e;
135-
}
13682
}
13783
assert( false ); // LCOV_EXCL_LINE
13884
}
13985
if ( ! accum ) {
14086
++m_problems;
14187
if ( m_verbose ) {
142-
std::cout << "problem: cycle without progress detected at class " << start->first << std::endl;
88+
std::cout << "problem: cycle without progress detected at rule class " << start->first << std::endl;
14389
}
144-
return m_cache[ start->first ] = false;
14590
}
146-
return m_cache[ start->first ] = accum; // Cycle with progress.
91+
return m_cache[ start->first ] = accum;
14792
}
14893
};
14994

include/tao/json/external/pegtl/analysis/rule_type.hh

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,10 @@ namespace tao_json_pegtl
1010
{
1111
enum class rule_type : char
1212
{
13-
ANY, // "Success implies consumption" is true; assumes bounded repetition of conjunction of sub-rules.
14-
OPT, // "Success implies consumption" is false; assumes bounded repetition of conjunction of sub-rules.
15-
16-
SEQ, // Consumption on success depends on non-zero bounded repetition of conjunction of sub-rules.
17-
SOR, // Consumption on success depends on non-zero bounded repetition of disjunction of sub-rules.
18-
19-
PLUS, // Similar to seq but for non-zero unbounded repetition of conjunction of sub-rules.
20-
STAR, // Similar to seq but for optional unbounded repetition of conjunction of sub-rules.
21-
22-
UNTIL, // Specific handling of until<> rules.
23-
IF // Specific handling of if_then_else<> rule.
13+
ANY, // Consumption-on-success is always true; assumes bounded repetition of conjunction of sub-rules.
14+
OPT, // Consumption-on-success not necessarily true; assumes bounded repetition of conjunction of sub-rules.
15+
SEQ, // Consumption-on-success depends on consumption of (non-zero bounded repetition of) conjunction of sub-rules.
16+
SOR // Consumption-on-success depends on consumption of (non-zero bounded repetition of) disjunction of sub-rules.
2417
};
2518

2619
} // analysis

include/tao/json/external/pegtl/ascii.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
1+
// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey
22
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/
33

44
#ifndef TAOCPP_JSON_EMBEDDED_PEGTL_ASCII_HH
@@ -16,7 +16,7 @@ namespace tao_json_pegtl
1616
struct any : internal::any< internal::peek_char > {};
1717
struct blank : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, ' ', '\t' > {};
1818
struct digit : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, '0', '9' > {};
19-
struct eol : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, '\n' > {};
19+
struct eol : internal::eol {};
2020
struct eolf : internal::eolf {};
2121
struct identifier_first : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z', '_' > {};
2222
struct identifier_other : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z', '0', '9', '_' > {};

include/tao/json/external/pegtl/contrib/http.hh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace tao_json_pegtl
5454
struct status_code : rep< 3, DIGIT > {};
5555
struct reason_phrase : star< sor< VCHAR, obs_text, WSP > > {};
5656

57-
struct HTTP_version : if_must< pegtl_string_t( "HTTP/" ), DIGIT, one< '.' >, DIGIT > {};
57+
struct HTTP_version : if_must< tao_json_pegtl_string_t( "HTTP/" ), DIGIT, one< '.' >, DIGIT > {};
5858

5959
struct request_line : if_must< method, SP, request_target, SP, HTTP_version, CRLF > {};
6060
struct status_line : if_must< HTTP_version, SP, status_code, SP, reason_phrase, CRLF > {};
@@ -78,17 +78,17 @@ namespace tao_json_pegtl
7878

7979
struct transfer_parameter : seq< token, BWS, one< '=' >, BWS, sor< token, quoted_string > > {};
8080
struct transfer_extension : seq< token, star< OWS, one< ';' >, OWS, transfer_parameter > > {};
81-
struct transfer_coding : sor< pegtl_istring_t( "chunked" ),
82-
pegtl_istring_t( "compress" ),
83-
pegtl_istring_t( "deflate" ),
84-
pegtl_istring_t( "gzip" ),
81+
struct transfer_coding : sor< tao_json_pegtl_istring_t( "chunked" ),
82+
tao_json_pegtl_istring_t( "compress" ),
83+
tao_json_pegtl_istring_t( "deflate" ),
84+
tao_json_pegtl_istring_t( "gzip" ),
8585
transfer_extension > {};
8686

8787
struct rank : sor< seq< one< '0' >, opt< one< '.' >, rep_opt< 3, DIGIT > > >,
8888
seq< one< '1' >, opt< one< '.' >, rep_opt< 3, one< '0' > > > > > {};
8989

9090
struct t_ranking : seq< OWS, one< ';' >, OWS, one< 'q', 'Q' >, one< '=' >, rank > {};
91-
struct t_codings : sor< pegtl_istring_t( "trailers" ), seq< transfer_coding, opt< t_ranking > > > {};
91+
struct t_codings : sor< tao_json_pegtl_istring_t( "trailers" ), seq< transfer_coding, opt< t_ranking > > > {};
9292

9393
struct TE : opt< sor< one< ',' >, t_codings >, star< OWS, one< ',' >, opt< OWS, t_codings > > > {};
9494

@@ -116,8 +116,8 @@ namespace tao_json_pegtl
116116

117117
struct Via : make_comma_list< seq< received_protocol, RWS, received_by, opt< RWS, comment > > > {};
118118

119-
struct http_URI : if_must< pegtl_istring_t( "http://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {};
120-
struct https_URI : if_must< pegtl_istring_t( "https://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {};
119+
struct http_URI : if_must< tao_json_pegtl_istring_t( "http://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {};
120+
struct https_URI : if_must< tao_json_pegtl_istring_t( "https://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {};
121121

122122
struct partial_URI : seq< uri::relative_part, uri::opt_query > {};
123123

include/tao/json/external/pegtl/contrib/json.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ namespace tao_json_pegtl
2626
struct name_separator : pad< one< ':' >, ws > {};
2727
struct value_separator : padr< one< ',' > > {};
2828

29-
struct false_ : pegtl_string_t( "false" ) {};
30-
struct null : pegtl_string_t( "null" ) {};
31-
struct true_ : pegtl_string_t( "true" ) {};
29+
struct false_ : tao_json_pegtl_string_t( "false" ) {};
30+
struct null : tao_json_pegtl_string_t( "null" ) {};
31+
struct true_ : tao_json_pegtl_string_t( "true" ) {};
3232

3333
struct digits : plus< abnf::DIGIT > {};
3434
struct exp : seq< one< 'e', 'E' >, opt< one< '-', '+'> >, must< digits > > {};

include/tao/json/external/pegtl/input.hh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
1+
// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey
22
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/
33

44
#ifndef TAOCPP_JSON_EMBEDDED_PEGTL_INPUT_HH
@@ -91,13 +91,11 @@ namespace tao_json_pegtl
9191
m_data.column += count;
9292
}
9393

94-
bool bump_if()
94+
void bump_next_line( const std::size_t count = 1 )
9595
{
96-
if ( ! empty() ) {
97-
bump_unsafe();
98-
return true;
99-
}
100-
return false;
96+
++m_data.line;
97+
m_data.begin += count;
98+
m_data.column = 0;
10199
}
102100

103101
internal::input_mark mark()

include/tao/json/external/pegtl/input_error.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
1+
// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey
22
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/
33

44
#ifndef TAOCPP_JSON_EMBEDDED_PEGTL_INPUT_ERROR_HH
55
#define TAOCPP_JSON_EMBEDDED_PEGTL_INPUT_ERROR_HH
66

77
#include <sstream>
88
#include <stdexcept>
9+
#include <cerrno>
910

1011
namespace tao_json_pegtl
1112
{

include/tao/json/external/pegtl/internal/any.hh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
1+
// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey
22
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/
33

44
#ifndef TAOCPP_JSON_EMBEDDED_PEGTL_INTERNAL_ANY_HH
@@ -26,7 +26,11 @@ namespace tao_json_pegtl
2626
template< typename Input >
2727
static bool match( Input & in )
2828
{
29-
return in.bump_if();
29+
if ( ! in.empty() ) {
30+
in.bump();
31+
return true;
32+
}
33+
return false;
3034
}
3135
};
3236

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2016 Dr. Colin Hirsch and Daniel Frey
2+
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/
3+
4+
#ifndef TAOCPP_JSON_EMBEDDED_PEGTL_INTERNAL_EOL_HH
5+
#define TAOCPP_JSON_EMBEDDED_PEGTL_INTERNAL_EOL_HH
6+
7+
#include "skip_control.hh"
8+
9+
#include "../analysis/generic.hh"
10+
11+
namespace tao_json_pegtl
12+
{
13+
namespace internal
14+
{
15+
struct eol
16+
{
17+
using analyze_t = analysis::generic< analysis::rule_type::ANY >;
18+
19+
template< typename Input >
20+
static bool match( Input & in )
21+
{
22+
if ( const auto s = in.size() ) {
23+
return match_impl( in, s );
24+
}
25+
return false;
26+
}
27+
28+
template< typename Input >
29+
static bool match_impl( Input & in, const std::size_t s )
30+
{
31+
const auto a = in.peek_char();
32+
if ( a == '\n' ) {
33+
in.bump_next_line();
34+
return true;
35+
}
36+
if ( ( a == '\r' ) && ( s > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) {
37+
in.bump_next_line( 2 );
38+
return true;
39+
}
40+
return false;
41+
}
42+
};
43+
44+
template<>
45+
struct skip_control< eol > : std::true_type {};
46+
47+
} // internal
48+
49+
} // tao_json_pegtl
50+
51+
#endif

include/tao/json/external/pegtl/internal/eolf.hh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
1+
// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey
22
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/
33

44
#ifndef TAOCPP_JSON_EMBEDDED_PEGTL_INTERNAL_EOLF_HH
@@ -8,6 +8,8 @@
88

99
#include "../analysis/generic.hh"
1010

11+
#include "eol.hh"
12+
1113
namespace tao_json_pegtl
1214
{
1315
namespace internal
@@ -19,14 +21,10 @@ namespace tao_json_pegtl
1921
template< typename Input >
2022
static bool match( Input & in )
2123
{
22-
if ( in.empty() ) {
23-
return true;
24-
}
25-
else if ( in.peek_char() == '\n' ) {
26-
in.bump();
27-
return true;
24+
if ( const auto s = in.size() ) {
25+
return eol::match_impl( in, s );
2826
}
29-
return false;
27+
return true;
3028
}
3129
};
3230

0 commit comments

Comments
 (0)