27#include <pegtl/contrib/analyze.hpp>
28#include <pegtl/contrib/parse_tree.hpp>
29#include <pegtl/contrib/parse_tree_to_dot.hpp>
30#include <pegtl/contrib/trace.hpp>
35using namespace tao::pegtl;
44template <
typename... EXCLUSION_RULES>
50template <
typename... EXCLUSION_RULES>
51struct STRING_EXCLUDING : plus<STR_SEGMENT_EXCLUDING<EXCLUSION_RULES...>, opt<LINE_CONTINUATION>> {};
56template <
char... CHAR_TO_FIND>
57struct spaced_ch : seq<star<space>, one<CHAR_TO_FIND...>>{};
62struct FORMAT : seq<bol, TAO_PEGTL_STRING( "# FORMAT" ), star<space>, CURRENT_FORMAT_NUMBER>{};
84 opt<seq<spaced_ch<'('>, PART_NUMBER, one<')'>>>,
85 opt<seq<spaced_ch<':'>, PART_VERSION>>,
86 opt<seq<spaced_ch<';'>, PART_DESCRIPTION>>
96 sor<FORMAT, PART, UNMATCHED_CONTENT>,
123 template <
typename Node>
126 if( n->children.size() == 1 )
128 n->children.pop_back();
130 else if( n->children.size() != 0 )
138template <
typename PEGTL_RULE>
141 parse_tree::store_content::on<
149 parse_tree::remove_content::on<
153 parse_tree::apply< FOLD_CONTENT >::on<
162int main(
int argc,
char** argv )
168 printf(
"usage: %s <complex|simple> <filename>", argv[0] );
172 std::string chosen_selector = argv[1];
173 std::filesystem::path filepath( argv[2] );
175 file_input in( filepath );
177 const std::size_t issues = tao::pegtl::analyze<GRAMMAR>();
181 std::cout <<
"\n***ERROR***: " << issues <<
" issues found in the grammar!\n";
185 std::unique_ptr<parse_tree::node> root;
187 if( chosen_selector ==
"complex" )
189 root = parse_tree::parse<GRAMMAR, COMPLEX_SELECTOR>( in );
191 else if( chosen_selector ==
"simple" )
193 root = parse_tree::parse<GRAMMAR, SIMPLE_SELECTOR>( in );
197 printf(
"Invalid selector '%s' requested. Valid values are: complex or simple. \n",
199 printf(
"usage: %s <complex|simple> <filename>\n", argv[0] );
205 parse_tree::print_dot( std::cout, *root );
209 std::cout <<
"\n***ERROR***: No root tree node!\n";
212 standard_trace<GRAMMAR>( in );
parse_tree::selector< PEGTL_RULE, parse_tree::store_content::on< STR_SEGMENT_EXCLUDING< PART_NAME_FILTER >, STR_SEGMENT_EXCLUDING< PART_NUMBER_FILTER >, STR_SEGMENT_EXCLUDING< PART_VERSION_FILTER >, STR_SEGMENT_EXCLUDING<>, CURRENT_FORMAT_NUMBER, UNMATCHED_CONTENT >, parse_tree::remove_content::on< FORMAT, PART >, parse_tree::apply< FOLD_CONTENT >::on< PART_NAME, PART_NUMBER, PART_VERSION, PART_DESCRIPTION > > COMPLEX_SELECTOR
static void transform(Node &n)
Any text can span multiple lines using '&'.
String with optional line continuation and exclusion rules.
String segment( no line continuation ), with exclusion rules.
Control character with or without preceding whitespace.