design.qbk 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. [section The design of the library]
  2. The purpose of the library is to provide tools to build template metaprograms
  3. being able to interpret the content of a string literal and generate code,
  4. display error messages, etc based on the content of the string literal. Such
  5. metaprograms are called [link parser parser]s. Metaparse is based on
  6. [@https://en.wikipedia.org/wiki/Parser_combinator parser combinators].
  7. The key components of the library:
  8. * [link ref-string Compile-time string representation]. These are tools for
  9. representing the content of a string literal in a way that makes it possible
  10. for template metaprograms to work on them. For this the library provides the
  11. [link string `string`] template class, which is a drop-in replacement of
  12. Boost.MPL's `string` implementation, and the [link BOOST_METAPARSE_STRING
  13. `BOOST_METAPARSE_STRING`] macro.
  14. * [link parsers Parsers]. These are template metafunction classes parsing a
  15. prefix of a string literal. These are simple [link parser parser]s providing
  16. the basic building blocks for more complicated ones doing some useful work.
  17. * [link combinators Parser combinators]. These are
  18. [link metafunction template metafunction]s taking [link parser parser]s as
  19. argument and/or returning [link parser parser]s as their result. They can be
  20. used to build more and more complex [link parser parser]s out of the simple
  21. ones.
  22. [section Design rationale]
  23. * [*Why template metaprogramming?]
  24. An alternative is using `constexpr` functions instead of template metaprograms.
  25. There are certain things that are difficult (if possible) using `constexpr`
  26. functions: building containers (at compile-time) the length of which depend on
  27. the parsed text (eg. parsing a JSON list), generating and validating types (eg.
  28. `printf`).
  29. * [*Why are there so many folding parsers?]
  30. Compilation speed and memory consumption is a critical part of template
  31. metaprogramming-based libraries. Users of the library interfaces built with
  32. Metaparse will have to pay for that every time they compile their code.
  33. Therefore it is important to provide the parser authors the ability to use the
  34. parser combinators with minimal overhead, while it is also important to provide
  35. convenient combinators for beginners and for the cases where that is the best
  36. option anyway.
  37. [link repeated `repeated`] combined with [link sequence `sequence`],
  38. [link accept_when `accept_when`] and [link transform `transform`] can replace
  39. any of the folding parsers, however, for the cost of constructing intermediate
  40. containers, that are (usually) processed sequentially after that.
  41. * [*Why external code generator for `BOOST_METAPARSE_STRING`?]
  42. To be able to support longer strings. It generates code using macros to reduce
  43. the size of the header files (the reducion is multiples of MBs).
  44. * [*Why defining a custom version of Boost.Preprocessor macros?]
  45. There are two reasons for the library defining its own set of preprocessor
  46. metaprogramming macros: to have control over the upper limit of iteration steps
  47. and to be able to clean the macros up once they have done their job (and avoid
  48. polluting the macros of the users).
  49. Note that these macros live in the `impl` directory, which means that they are
  50. an implementation detail of the library and should be used internally only.
  51. [endsect]
  52. [endsect]