flush_multi_pass.qbk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Hartmut Kaiser
  3. Copyright (C) 2001-2011 Joel de Guzman
  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:flush_multi_pass Qi flush_multi_pass parser]
  8. [heading Description]
  9. The __qi__ `flush_multi_pass` parser is a primitive (pseudo) parser component
  10. allowing to clear the internal buffer of a `multi_pass` iterator. Clearing the
  11. buffer of a `multi_pass` might be beneficial for grammars where it is clear
  12. that no backtracking can occur.
  13. The general syntax for using the `flush_multi_pass` is:
  14. flush_multi_pass
  15. which will call the `clear_queue()` member function if the current iterators
  16. are of the type `multi_pass`. This will cause any buffered data to be erased.
  17. This also will invalidate all other copies of multi_pass and they should not
  18. be used. If they are, an `boost::illegal_backtracking` exception will be
  19. thrown. For all other iterator types this is a no-op. The `flush_multi_pass`
  20. generates a parser component which always succeeds and which does not consume
  21. any input (very much like `eps`).
  22. [heading Header]
  23. // forwards to <boost/spirit/repository/home/qi/primitive/flush_multi_pass.hpp>
  24. #include <boost/spirit/repository/include/qi_flush_multi_pass.hpp>
  25. [heading Synopsis]
  26. flush_multi_pass
  27. [heading Parameters]
  28. The `flush_multi_pass` does not require any parameters.
  29. [heading Attribute]
  30. The `flush_multi_pass` component exposes no attribute (the exposed attribute
  31. type is `unused_type`):
  32. flush_multi_pass --> unused
  33. [heading Example]
  34. The following example shows a simple use case of the `flush_multi_pass` parser.
  35. We will illustrate its usage by generating different comment styles and a
  36. function prototype (for the full example code see here:
  37. [@../../example/qi/flush_multi_pass.cpp flush_multi_pass.cpp])
  38. [import ../../example/qi/flush_multi_pass.cpp]
  39. [heading Prerequisites]
  40. In addition to the main header file needed to include the core components
  41. implemented in __qi__ we add the header file needed for the new
  42. `flush_multi_pass` parser.
  43. [qi_flush_multi_pass_includes]
  44. To make all the code below more readable we introduce the following namespaces.
  45. [qi_flush_multi_pass_namespace]
  46. [heading Clearing the internal buffer]
  47. The example grammar recognizes the (simplified) preprocessor commands `#define`
  48. and `#undef` both of which are constraint to a single line. This makes it
  49. possible to delete all internal iterator buffers on each detected line break.
  50. This is safe as no backtracking will occur after any line end. The following
  51. code snippet shows the usage of `flush_multi_pass` for this purpose.
  52. [qi_flush_multi_pass_clear_buffer]
  53. [note Using the `flush_multi_pass` parser component with iterators other than
  54. `multi_pass` is safe as it has no effect on the parsing.]
  55. [endsect]