Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Jul 31, 2021
1 parent 4b152b1 commit 663a9f4
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 188 deletions.
4 changes: 3 additions & 1 deletion doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## 3.2.1

**Not yet released**
Released 2021-07-31

* Added an optional limiter to guard against infinite recursion.
* Fixed CMake export error.
* Improved compile time efficiency.

## 3.2.0

Expand Down
6 changes: 3 additions & 3 deletions include/tao/pegtl/contrib/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ namespace TAO_PEGTL_NAMESPACE::http
struct https_URI : if_must< istring< 'h', 't', 't', 'p', 's', ':', '/', '/' >, uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {};

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

// clang-format on

struct chunk_size
{
using rule_t = plus< abnf::HEXDIG >::rule_t;
Expand Down Expand Up @@ -170,13 +170,13 @@ namespace TAO_PEGTL_NAMESPACE::http
return i > 0;
}
};
// clang-format off

// clang-format off
struct chunk_ext_name : token {};
struct chunk_ext_val : sor< quoted_string, token > {};
struct chunk_ext : star_must< one< ';' >, chunk_ext_name, if_must< one< '=' >, chunk_ext_val > > {};

// clang-format on

struct chunk_data
{
using rule_t = star< abnf::OCTET >::rule_t;
Expand Down
220 changes: 108 additions & 112 deletions include/tao/pegtl/contrib/peg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,119 +7,115 @@

#include <tao/pegtl.hpp>

namespace TAO_PEGTL_NAMESPACE
namespace TAO_PEGTL_NAMESPACE::peg
{
namespace peg
// PEG grammar from https://pdos.csail.mit.edu/~baford/packrat/popl04/peg-popl04.pdf
namespace grammar
{
// PEG grammar from https://pdos.csail.mit.edu/~baford/packrat/popl04/peg-popl04.pdf
namespace grammar
{
// clang-format off
struct AND;
struct Char;
struct Class;
struct CLOSE;
struct Comment;
struct Definition;
struct DOT;
struct EndOfFile;
struct EndOfLine;
struct Expression;
struct QUESTION;
struct IdentCont;
struct Identifier;
struct IdentStart;
struct LEFTARROW;
struct Literal;
struct NOT;
struct OPEN;
struct PLUS;
struct Prefix;
struct Primary;
struct Range;
struct Sequence;
struct SLASH;
struct Space;
struct Spacing;
struct STAR;
struct Suffix;

struct Grammar : seq< Spacing, plus< Definition >, EndOfFile > {};

struct Definition : seq< Identifier, LEFTARROW, Expression > {};
struct Expression : list< Sequence, SLASH > {};
struct Sequence : star< Prefix > {};

struct Prefix : seq< opt< sor< AND, NOT > >, Suffix > {};
struct Suffix : seq< Primary, opt< sor< QUESTION, STAR, PLUS > > > {};

struct Primary : sor<
seq< Identifier, not_at< LEFTARROW > >,
seq< OPEN, Expression, CLOSE >,
Literal,
Class,
DOT
> {};

struct Identifier : seq< IdentStart, star< IdentCont >, Spacing > {};

struct IdentStart : identifier_first {};

struct IdentCont : identifier_other {};

struct Literal : sor<
seq< one< '\'' >, until< one< '\'' >, Char >, Spacing >,
seq< one< '"' >, until< one< '"' >, Char >, Spacing >
> {};

struct Class : seq< one< '[' >, until< one< ']' >, Range >, Spacing > {};

struct Range : sor<
seq< Char, one< '-' >, Char >,
Char
> {};

struct Char : sor<
seq<
one< '\\' >,
one< 'n', 'r', 't', '\'', '"', '[', ']', '\\' > >,
seq<
one< '\\' >,
range< '0', '2' >,
range< '0', '7' >,
range< '0', '7' > >,
seq<
one< '\\' >,
range< '0','7' >,
opt< range< '0','7' > > >,
seq<
not_at< one< '\\' > >,
any >
> {};

struct LEFTARROW : seq< string< '<','-' >, Spacing > {};
struct SLASH : seq< one< '/' >, Spacing > {};
struct AND : seq< one< '&' >, Spacing > {};
struct NOT : seq< one< '!' >, Spacing > {};
struct QUESTION : seq< one< '?' >, Spacing > {};
struct STAR : seq< one< '*' >, Spacing > {};
struct PLUS : seq< one< '+' >, Spacing > {};
struct OPEN : seq< one< '(' >, Spacing > {};
struct CLOSE : seq< one< ')' >, Spacing > {};
struct DOT : seq< one< '.' >, Spacing > {};

struct Spacing : star< sor< Space, Comment > > {};
struct Comment : seq< one< '#' >, until< EndOfLine > > {};

struct Space : sor< one< ' ', '\t' >, EndOfLine > {};
struct EndOfLine : sor< string< '\r', '\n' >, one< '\n' >, one< '\r' > > {};
struct EndOfFile : eof {};
// clang-format on

} // namespace grammar

} // namespace peg

} // namespace TAO_PEGTL_NAMESPACE
// clang-format off
struct AND;
struct Char;
struct Class;
struct CLOSE;
struct Comment;
struct Definition;
struct DOT;
struct EndOfFile;
struct EndOfLine;
struct Expression;
struct QUESTION;
struct IdentCont;
struct Identifier;
struct IdentStart;
struct LEFTARROW;
struct Literal;
struct NOT;
struct OPEN;
struct PLUS;
struct Prefix;
struct Primary;
struct Range;
struct Sequence;
struct SLASH;
struct Space;
struct Spacing;
struct STAR;
struct Suffix;

struct Grammar : seq< Spacing, plus< Definition >, EndOfFile > {};

struct Definition : seq< Identifier, LEFTARROW, Expression > {};
struct Expression : list< Sequence, SLASH > {};
struct Sequence : star< Prefix > {};

struct Prefix : seq< opt< sor< AND, NOT > >, Suffix > {};
struct Suffix : seq< Primary, opt< sor< QUESTION, STAR, PLUS > > > {};

struct Primary : sor<
seq< Identifier, not_at< LEFTARROW > >,
seq< OPEN, Expression, CLOSE >,
Literal,
Class,
DOT
> {};

struct Identifier : seq< IdentStart, star< IdentCont >, Spacing > {};

struct IdentStart : identifier_first {};

struct IdentCont : identifier_other {};

struct Literal : sor<
seq< one< '\'' >, until< one< '\'' >, Char >, Spacing >,
seq< one< '"' >, until< one< '"' >, Char >, Spacing >
> {};

struct Class : seq< one< '[' >, until< one< ']' >, Range >, Spacing > {};

struct Range : sor<
seq< Char, one< '-' >, Char >,
Char
> {};

struct Char : sor<
seq<
one< '\\' >,
one< 'n', 'r', 't', '\'', '"', '[', ']', '\\' > >,
seq<
one< '\\' >,
range< '0', '2' >,
range< '0', '7' >,
range< '0', '7' > >,
seq<
one< '\\' >,
range< '0','7' >,
opt< range< '0','7' > > >,
seq<
not_at< one< '\\' > >,
any >
> {};

struct LEFTARROW : seq< string< '<','-' >, Spacing > {};
struct SLASH : seq< one< '/' >, Spacing > {};
struct AND : seq< one< '&' >, Spacing > {};
struct NOT : seq< one< '!' >, Spacing > {};
struct QUESTION : seq< one< '?' >, Spacing > {};
struct STAR : seq< one< '*' >, Spacing > {};
struct PLUS : seq< one< '+' >, Spacing > {};
struct OPEN : seq< one< '(' >, Spacing > {};
struct CLOSE : seq< one< ')' >, Spacing > {};
struct DOT : seq< one< '.' >, Spacing > {};

struct Spacing : star< sor< Space, Comment > > {};
struct Comment : seq< one< '#' >, until< EndOfLine > > {};

struct Space : sor< one< ' ', '\t' >, EndOfLine > {};
struct EndOfLine : sor< string< '\r', '\n' >, one< '\n' >, one< '\r' > > {};
struct EndOfFile : eof {};
// clang-format on

} // namespace grammar

} // namespace TAO_PEGTL_NAMESPACE::peg

#endif // TAO_PEGTL_CONTRIB_PEG_HPP
12 changes: 9 additions & 3 deletions src/example/pegtl/abnf2pegtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,16 @@ namespace TAO_PEGTL_NAMESPACE
template<> inline constexpr auto error_message< abnf::grammar::defined_as > = "expected '=' or '=/'";
template<> inline constexpr auto error_message< abnf::grammar::req_c_nl > = "unterminated rule";
template<> inline constexpr auto error_message< abnf::grammar::rule > = "expected rule";

struct error { template< typename Rule > static constexpr auto message = error_message< Rule >; };
template< typename Rule > using control = must_if< error >::control< Rule >;
// clang-format on

struct error
{
template< typename Rule >
static constexpr auto message = error_message< Rule >;
};

template< typename Rule >
using control = must_if< error >::control< Rule >;
#else
template< typename Rule >
using control = normal< Rule >;
Expand Down
Loading

0 comments on commit 663a9f4

Please sign in to comment.