debug_parsing_error.qbk 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. [#debug_parsing_error]
  2. [section debug_parsing_error]
  3. [h1 Synopsis]
  4. template <class P, class S>
  5. struct debug_parsing_error
  6. {
  7. debug_parsing_error();
  8. };
  9. This is a template class.
  10. [table Arguments
  11. [[Name] [Type]]
  12. [[`P`] [[link parser parser]]]
  13. [[`S`] [[link string string]]]
  14. ]
  15. [h1 Description]
  16. Utility to debug errors generated by a compile-time parser. An instance of the
  17. instantiated template class has to be created and initialised using the default
  18. constructor. When parsing the input string using the parser generates an error,
  19. the default constructor of `debug_parsing_error` prints the error message to the
  20. standard output at run-time and calls `exit`.
  21. [note
  22. Note that more powerful debugging utilities, like
  23. [@https://github.com/sabel83/metashell#metashell Metashell] are also
  24. available.
  25. ]
  26. [h1 Header]
  27. #include <boost/metaparse/debug_parsing_error.hpp>
  28. [h1 Expression semantics]
  29. For any `p` compile-time parser and `s` compile-time string
  30. debug_parsing_error<p, s>()
  31. Tries to parse `s` using `p` at compile-time. At run-time the constructor
  32. prints the result of parsing to the standard output and calls `exit`.
  33. [h1 Example]
  34. #include <boost/metaparse/debug_parsing_error.hpp>
  35. #include <boost/metaparse/int_.hpp>
  36. #include <boost/metaparse/string.hpp>
  37. #include <type_traits>
  38. using namespace boost::metaparse;
  39. debug_parsing_error<int_, BOOST_METAPARSE_STRING("not an int")> do_debugging;
  40. int main() {}
  41. By running the compiled executable you get the following:
  42. Compile-time parsing results
  43. ----------------------------
  44. Input text:
  45. not an int
  46. Parsing failed:
  47. line 1, col 1: Digit expected
  48. [endsect]