basics.qbk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. [/==============================================================================
  2. Copyright (C) 2001-2008 Joel de Guzman
  3. Copyright (C) 2001-2008 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 Parser Basics]
  8. [heading Lazy Argument]
  9. Some parsers (e.g. primitives and non-terminals) may take in additional
  10. attributes. Such parsers take the form:
  11. p(a1, a2,..., aN)
  12. where `p` is a parser. 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 parser's __context__ type (The first
  17. argument is __unused__ to make the `Context` the second argument. This
  18. is done for uniformity with __actions__).
  19. [heading Character Encoding Namespace]
  20. Some parsers need to know which character set a `char` or `wchar_t` is
  21. operating on. For example, the `alnum` parser works differently with
  22. ISO8859.1 and ASCII encodings. Where necessary, Spirit encodes (tags)
  23. the parser 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 parsers such as `alnum`, `space` etc.
  28. Example:
  29. using boost::spirit::ascii::space; // use the ASCII space parser
  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 qi sub-namespaces with the same names:
  37. * boost::spirit::qi::ascii
  38. * boost::spirit::qi::iso8859_1
  39. * boost::spirit::qi::standard
  40. * boost::spirit::qi::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_includes]
  48. Our test functions:
  49. These functions test the parsers without attributes.
  50. [reference_test]
  51. These functions test the parsers with user supplied attributes.
  52. [reference_test_attr]
  53. The `print_info` utility function prints information contained in the
  54. __info__ class.
  55. [reference_print_info]
  56. [heading String]
  57. [heading Header]
  58. // forwards to <boost/spirit/home/support/string_traits.hpp>
  59. #include <boost/spirit/support_string_traits.hpp>
  60. A string can be any object `s`, of type, `S`, that satisfies the
  61. following expression traits:
  62. [table
  63. [[Expression] [Semantics]]
  64. [[`boost::spirit::traits::is_string<S>`] [Metafunction that evaluates to `mpl::true_` if
  65. a certain type, `S` is a string, `mpl::false_`
  66. otherwise (See __mpl_boolean_constant__).]]
  67. [[`boost::spirit::traits::char_type_of<S>`] [Metafunction that returns the underlying
  68. char type of a string type, `S`.]]
  69. [[`boost::spirit::traits::get_c_string(s)`] [Function that returns the underlying
  70. raw C-string from `s`.]]
  71. [[`boost::spirit::traits::get_begin(s)`] [Function that returns an __stl__ iterator from `s`
  72. that points to the beginning the string.]]
  73. [[`boost::spirit::traits::get_end(s)`] [Function that returns an __stl__ iterator from `s`
  74. that points to the end of the string.]]
  75. ]
  76. [heading Models]
  77. Predefined models include:
  78. * any literal string, e.g. "Hello, World",
  79. * a pointer/reference to a null-terminated array of characters
  80. * a `std::basic_string<Char>`
  81. The namespace `boost::spirit::traits` is open for users to provide their
  82. own specializations. The customization points implemented by __qi__ usable
  83. to customize the behavior of parsers are described in the section
  84. __sec_customization_points__.
  85. [endsect]