basics.qbk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ===============================================================================/]
  7. [section:basics Generator Basics]
  8. [heading Lazy Argument]
  9. Some generators (e.g. primitives and non-terminals) may take in additional
  10. attributes. Such generators take the form:
  11. g(a1, a2,..., aN)
  12. where `g` is a generator. Each of the arguments (a1 ... aN) can either be an
  13. immediate value, or a function, `f`, with signature:
  14. T f(Unused, Context)
  15. where `T`, the function's return value, is compatible with the argument
  16. type expected and `Context` is the generator's __karma_context__ type (The
  17. first argument is __unused__ to make the `Context` the second argument. This
  18. is done for uniformity with __karma_actions__).
  19. [heading Character Encoding Namespace]
  20. Some generators need to know which character set a `char` or `wchar_t` is
  21. operating on. For example, the `alnum` generator works differently with
  22. ISO8859.1 and ASCII encodings. Where necessary, Spirit encodes (tags)
  23. the generator with the character set.
  24. We have a namespace for each character set Spirit will be supporting.
  25. That includes `ascii`, `iso8859_1`, `standard` and `standard_wide` (and
  26. in the future, `unicode`). In each of the character encoding namespaces,
  27. we place tagged versions of generators such as `alnum`, `space` etc.
  28. Example:
  29. using boost::spirit::ascii::space; // use the ASCII space generator
  30. Namespaces:
  31. * boost::spirit::ascii
  32. * boost::spirit::iso8859_1
  33. * boost::spirit::standard
  34. * boost::spirit::standard_wide
  35. For ease of use, the components in this namespaces are also brought into
  36. the karma sub-namespaces with the same names:
  37. * boost::spirit::karma::ascii
  38. * boost::spirit::karma::iso8859_1
  39. * boost::spirit::karma::standard
  40. * boost::spirit::karma::standard_wide
  41. [heading Examples]
  42. All sections in the reference present some real world examples. The
  43. examples use a common test harness to keep the example code as minimal
  44. and direct to the point as possible. The test harness is presented
  45. below.
  46. Some includes:
  47. [reference_karma_includes]
  48. The used output iterator:
  49. [reference_karma_output_iterator]
  50. Our test functions:
  51. This one tests the generators without attributes.
  52. [reference_karma_test]
  53. These test the generators with one or more user supplied attributes.
  54. [reference_karma_test_attr]
  55. [reference_karma_test_attr2]
  56. This tests the generators with one attribute and while using delimited output.
  57. [reference_karma_test_attr_delim]
  58. The examples of the binary generators use one or more of the following tests.
  59. [reference_karma_binary_test]
  60. [reference_karma_binary_test_attr]
  61. [heading Models]
  62. Predefined models include:
  63. * any literal string, e.g. "Hello, World",
  64. * a pointer/reference to a null-terminated array of characters
  65. * a `std::basic_string<Char>`
  66. The namespace `boost::spirit::traits` is open for users to provide their
  67. own specializations. The customization points implemented by __karma__ usable
  68. to customize the behavior of generators are described in the section
  69. __sec_customization_points__.
  70. [endsect]