quick_reference.qbk 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. This quick reference section is provided for convenience. You can use
  8. this section as a sort of a "cheat-sheet" on the most commonly used Lex
  9. components. It is not intended to be complete, but should give you an
  10. easy way to recall a particular component without having to dig through
  11. pages and pages of reference documentation.
  12. [/////////////////////////////////////////////////////////////////////////////]
  13. [section Common Notation]
  14. [variablelist Notation
  15. [[`L`] [Lexer type]]
  16. [[`l, a, b, c, d`] [Lexer objects]]
  17. [[`Iterator`] [The type of an iterator referring to the underlying
  18. input sequence]]
  19. [[`IdType`] [The token id type]]
  20. [[`Context`] [The lexer components `Context` type]]
  21. [[`ch`] [Character-class specific character (See __char_class_types__)]]
  22. [[`Ch`] [Character-class specific character type (See __char_class_types__)]]
  23. [[`str`] [Character-class specific string (See __char_class_types__)]]
  24. [[`Str`] [Character-class specific string type (See __char_class_types__)]]
  25. [[`Attrib`] [An attribute type]]
  26. [[`fa`] [A semantic action function with a signature:
  27. `void f(Iterator&, Iterator&, pass_flag&, Idtype&, Context&)`.]]
  28. ]
  29. [endsect]
  30. [/////////////////////////////////////////////////////////////////////////////]
  31. [section:lexers Primitive Lexer Components]
  32. [table
  33. [[Expression] [Attribute] [Description]]
  34. [[`ch`] [n/a] [Matches `ch`]]
  35. [[`char_(ch)`] [n/a] [Matches `ch`]]
  36. [[`str`] [n/a] [Matches regular expression `str`]]
  37. [[`string(str)`] [n/a] [Matches regular expression `str`]]
  38. [[`token_def<Attrib>`] [`Attrib`] [Matches the immediate argument]]
  39. [[`a | b`] [n/a] [Matches any of the expressions `a` or `b`]]
  40. [[`l[fa]`] [Attribute of `l`] [Call semantic action `fa` (after matching `l`).]]
  41. ]
  42. [note The column /Attribute/ in the table above lists the parser attribute
  43. exposed by the lexer component if it is used as a parser (see
  44. __attribute__). A 'n/a' in this columns means the lexer component is not
  45. usable as a parser.]
  46. [endsect]
  47. [/////////////////////////////////////////////////////////////////////////////]
  48. [section Semantic Actions]
  49. Has the form:
  50. l[f]
  51. where `f` is a function with the signatures:
  52. void f();
  53. void f(Iterator&, Iterator&);
  54. void f(Iterator&, Iterator&, pass_flag&);
  55. void f(Iterator&, Iterator&, pass_flag&, Idtype&);
  56. void f(Iterator&, Iterator&, pass_flag&, Idtype&, Context&);
  57. You can use __boost_bind__ to bind member functions. For function
  58. objects, the allowed signatures are:
  59. void operator()(unused_type, unused_type, unused_type, unused_type, unused_type) const;
  60. void operator()(Iterator&, Iterator&, unused_type, unused_type, unused_type) const;
  61. void operator()(Iterator&, Iterator&, pass_flag&, unused_type, unused_type) const;
  62. void operator()(Iterator&, Iterator&, pass_flag&, Idtype&, unused_type) const;
  63. void operator()(Iterator&, Iterator&, pass_flag&, Idtype&, Context&) const;
  64. The `unused_type` is used in the signatures above to signify 'don't
  65. care'.
  66. For more information see __lex_actions__.
  67. [endsect]
  68. [/////////////////////////////////////////////////////////////////////////////]
  69. [section Phoenix]
  70. __phoenix__ makes it easier to attach semantic actions. You just
  71. inline your lambda expressions:
  72. l[phoenix-lambda-expression]
  73. __lex__ provides some __phoenix__ placeholders to access important
  74. information from the `Context` that are otherwise difficult to extract.
  75. [variablelist Spirit.Lex specific Phoenix placeholders
  76. [[`_start, _end`] [Iterators pointing to the begin and the end of the
  77. matched input sequence.]]
  78. [[`_pass`] [Assign `lex::pass_flags::pass_fail` to `_pass` to force the current match to fail.]]
  79. [[`_tokenid`] [The token id of the matched token.]]
  80. [[`_val`] [The token value of the matched token.]]
  81. [[`_state`] [The lexer state the token has been matched in.]]
  82. [[`_eoi`] [Iterator referring to the current end of the input sequence.]]
  83. ]
  84. [tip All of the placeholders in the list above (except `_eoi`) can be changed
  85. from the inside of the semantic action allowing to modify the lexer
  86. behavior. They are defined in the namespace `boost::spirit::lex`.]
  87. For more information see __lex_actions__.
  88. [endsect]