fork download
  1. What is the canonical way to declare parsers using X3?
  2.  
  3. The [documentation for X3][1] creates parsers similar to this:
  4.  
  5. namespace parser
  6. {
  7. namespace x3 = boost::spirit::x3;
  8.  
  9. using parser_type = x3::rule<class parser_class, attribute>;
  10. parser_type const parser = "parser";
  11. auto const parser_def = x3::lit("my parser");
  12. BOOST_SPIRIT_DEFINE(parser);
  13. }
  14.  
  15. I've also seen `parser_def` changed to look like this:
  16.  
  17. auto const parser_def = parser_type{"parser"}
  18. = x3::lit("my parser");
  19.  
  20. But this seems like it would have ODR violations if it was in a header. I definitely want my parsers in headers to make for easier parsing. I could simply add `inline` to the variables (C++17):
  21.  
  22. namespace parser
  23. {
  24. namespace x3 = boost::spirit::x3;
  25.  
  26. using parser_type = x3::rule<class parser_class, attribute>;
  27. inline parser_type const parser = "parser";
  28. inline auto const parser_def = x3::lit("my parser");
  29. BOOST_SPIRIT_DEFINE(parser);
  30. }
  31.  
  32. But X3 is designed to work prior to C++17, so I feel like I'm doing something wrong.
  33.  
  34.  
  35. [1]: http://c...content-available-to-author-only...e.com/cppnow15/x3_docs/spirit/tutorials/rexpr.html
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty