faq.qbk 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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:faq Spirit FAQ]
  8. [heading I'm getting multiple symbol definition errors while using Visual C++. Anything I could do about that?]
  9. Do you see strange multiple symbol definition linker errors mentioning
  10. `boost::mpl::failed` and `boost::spirit::qi::rule`? Then this FAQ entry might
  11. be for you.
  12. __mpl__ implements a macro `BOOST_MPL_ASSERT_MSG()` which essentially is a
  13. more powerful version of static_assert. Unfortunately under certain
  14. circumstances using this macro may lead to the aforementioned linker errors.
  15. __spirit__ allows you to define a preprocessor constant disabling the usage
  16. of `BOOST_MPL_ASSERT_MSG()`, while switching to `BOOST_STATIC_ASSERT()` instead.
  17. For that you need define BOOST_SPIRIT_DONT_USE_MPL_ASSERT_MSG=1. Do this by
  18. adding
  19. -DBOOST_SPIRIT_DONT_USE_MPL_ASSERT_MSG=1
  20. on the compiler command line or by inserting a
  21. #define BOOST_SPIRIT_DONT_USE_MPL_ASSERT_MSG 1
  22. into your code before any Spirit headers get included.
  23. Using this trick has no adverse effects on any of the functionality of
  24. __spirit__. The only change you might see while using this workaround is less
  25. verbose error messages generated from static_assert.
  26. [heading I'm very confused about the header hell in my boost/spirit directory. What's all this about?]
  27. The boost/spirit directory currently holds two versions of the Spirit library:
  28. __classic__ (former V1.8.x) and SpiritV2. Both are completely independent
  29. and usually not used at the same time. Do not mix these two in the same grammar.
  30. __classic__ evolved over years in a fairly complex directory structure:
  31. boost/spirit/actor
  32. boost/spirit/attribute
  33. boost/spirit/core
  34. boost/spirit/debug
  35. boost/spirit/dynamic
  36. boost/spirit/error_handling
  37. boost/spirit/iterator
  38. boost/spirit/meta
  39. boost/spirit/symbols
  40. boost/spirit/tree
  41. boost/spirit/utility
  42. While introducing Spirit V2 we restructured the directory structure in order to
  43. accommodate two versions at the same time. All of __classic__ now lives in
  44. the directory
  45. boost/spirit/home/classic
  46. where the directories above contain forwarding headers to the new location
  47. allowing to maintain application compatibility. The forwarding headers issue a
  48. warning (starting with Boost V1.38) telling the user to change their include
  49. paths. Please expect the above directories/forwarding headers to go away soon.
  50. This explains the need for the directory
  51. boost/spirit/include
  52. which contains forwarding headers as well. But this time the headers won't go
  53. away. We encourage application writers to use only the includes contained in
  54. this directory. This allows us to restructure the directories underneath if
  55. needed without worrying application compatibility. Please use those files in
  56. your application only. If it turns out that some forwarding file is missing,
  57. please report this as a bug.
  58. Spirit V2 is not about parsing only anymore (as __classic__). It now consists
  59. out of 3 parts (sub-libraries): __qi__, __karma__, and __lex__. The header
  60. files for those live in
  61. boost/spirit/home/qi
  62. boost/spirit/home/karma
  63. boost/spirit/home/lex
  64. and have forwarding headers in
  65. boost/spirit/include
  66. __qi__ is the direct successor to __classic__ as it implements a DSEL (domain
  67. specific embedded language) allowing to write parsers using the syntax of C++
  68. itself (parsers in the sense turning a sequence of bytes into an internal data
  69. structure). It is not compatible with __classic__, the main concepts are
  70. similar, though.
  71. __karma__ is the counterpart to __qi__. It implements a similar DSEL but for
  72. writing generators (i.e. the things turning internal data structures into a
  73. sequence of bytes, most of the time - strings). __karma__ is the Yang to
  74. __qi__'s Yin, it's almost like a mirrored picture.
  75. __lex__ is (as the name implies) a library allowing to write lexical analyzers.
  76. These are either usable stand alone or can be used as a front end for __qi__
  77. parsers. If you know flex you shouldn't have problems understanding __lex__.
  78. This library actually doesn't implement the lexer itself. All it does is to
  79. provide an interface to pre-existing lexical analyzers. Currently it's using
  80. Ben Hansons excellent __lexertl__ library (proposed for a Boost review, BTW) as
  81. its underlying workhorse.
  82. Again, don't use any of the header files underneath the boost/spirit/home
  83. directory directly, always include files from the boost/spirit/include
  84. directory.
  85. The last bit missing is __phoenix__ (which currently still lives under the
  86. Spirit umbrella, but already has been accepted as a Boost library, so it will
  87. move away). __phoenix__ is a library allowing to write functional style C++,
  88. which is interesting in itself, but as it initially has been developed for
  89. Spirit, it is nicely integrated and very useful when it comes to writing
  90. semantic actions. I think using the boost/spirit/include/phoenix_... headers
  91. will be safe in the future as well, as we will probably redirect to the
  92. Boost.Phoenix headers as soon as these are available.
  93. [heading Why doesn't my symbol table work in a `no_case` directive?]
  94. In order to perform case-insensitive parsing (using __qi_no_case__) with a
  95. symbol table (i.e. use a __qi_symbols__
  96. parser in a `no_case` directive), that symbol table needs to be filled with
  97. all-lowercase contents. Entries containing one or more uppercase characters
  98. will not match any input.
  99. [heading I'm getting a compilation error mentioning `boost::function` and/or
  100. `boost::function4`. What does this mean?]
  101. If you are using Visual C++ and have an error like:
  102. [pre
  103. error C2664: \'bool boost::function4<R,T0,T1,T2,T3>::operator ()(T0,T1,T2,T3) const\' :
  104. cannot convert parameter 4 from '...' to '...'
  105. ]
  106. or you are using GCC and have an error like:
  107. [pre
  108. error: no match for call to '(const boost::function<bool ()(...)>) (...)'
  109. note: candidates are: ... boost::function4<R,T1,T2,T3,T4>::operator()(T0,T1,T2,T3) const [with ...\]
  110. ]
  111. then this FAQ entry may help you.
  112. The definition of a __rule__ or __grammar__ may contain a skip parser type. If
  113. it does, it means that non-terminal can only be used with a skip parser of a
  114. compatible type. The error above arises when this is not the case, i.e.:
  115. * a non-terminal defined with a skip parser type is used without a skip parser;
  116. for example, a rule with a skip parser type is used inside a `lexeme`
  117. directive, or a grammar with a skip parser type is used in `parse` instead of
  118. `phrase_parse`,
  119. * or a non-terminal is used with a skip parser of an incompatible type;
  120. for example, a rule defined with one skip parser type calls a second rule
  121. defined with another, incompatible skip parser type.
  122. [note The same applies to __karma__, replacing 'skip parser' and `lexeme`
  123. by 'delimit generator' and `verbatim`. Similarily, corresponding error
  124. messages in __karma__ reference `boost::function3` and the 3rd
  125. parameter (instead of the 4th).]
  126. [endsect]