num_list4.qbk 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 Number List Attribute - one more, with style]
  8. You've seen that the `double_` parser has a `double` attribute. All parsers have
  9. an attribute, even complex parsers. Those that are composed from primitives
  10. using operators, like the list parser, also have an attribute. It so happens that
  11. the attribute of a list parser:
  12. p % d
  13. is a `std::vector` of the attribute of `p`. So, for our parser:
  14. double_ % ','
  15. we'll have an attribute of:
  16. std::vector<double>
  17. So, what does this give us? Well, we can simply pass in a `std::vector<double>`
  18. to our number list parser and it will happily churn out our result in our
  19. vector. For that to happen, we'll use a variation of the `phrase_parse` with
  20. an additional argument: the parser's attribute. With the following arguments
  21. passed to `phrase_parse`
  22. # An iterator pointing to the start of the input
  23. # An iterator pointing to one past the end of the input
  24. # The parser object
  25. # Another parser called the skip parser
  26. # The parser's attribute
  27. our parser now is further simplified to:
  28. [import ../../example/qi/num_list4.cpp]
  29. [tutorial_numlist4]
  30. The full cpp file for this example can be found here: [@../../example/qi/num_list4.cpp]
  31. [*Hey, no more actions!!!] Now we're entering the realm of attribute grammars.
  32. Cool eh?
  33. [endsect]