concepts.qbk 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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:lexer_concepts Lexer Concepts]
  8. __lex__ components fall into a couple of generalized __concepts__. The
  9. /Lexer/ is the most fundamental concept. All __lex__ components are
  10. models of the /Lexer/ concept. /PrimitiveLexer/, /UnaryLexer/,
  11. and /NaryLexer/ are all refinements of the /Lexer/ concept.
  12. The following sections provide details on these concepts.
  13. [/////////////////////////////////////////////////////////////////////////////]
  14. [section Lexer]
  15. [heading Description]
  16. The /Lexer/ is the most fundamental concept. A Lexer has a member
  17. function, `collect`, that accepts a token definition container `Def`, and a
  18. the name of the lexer state the token definitions of the lexer component need
  19. to be added to (a string). It doesn't return anything (return type is `void`).
  20. Each Lexer can represent a specific pattern or algorithm, or it
  21. can be a more complex lexer component formed as a composition of other Lexer's.
  22. Additionally, a Lexer exposes a member `add_actions`, that accepts the token
  23. definition container `Def`, while returning nothing (again, the returned type
  24. is `void`).
  25. [variablelist Notation
  26. [[`l`] [A `Lexer`.]]
  27. [[`L`] [A `Lexer` type.]]
  28. [[`Def`] [A token definition container type.]]
  29. [[`State`] [A type used to represent lexer state names.]]
  30. ]
  31. [heading Valid Expressions]
  32. In the expressions below, the behavior of the lexer component, `l`, is left
  33. unspecified in the base `Lexer` concept. These are specified in subsequent,
  34. more refined concepts and by the actual models thereof.
  35. For any Lexer the following expressions must be valid:
  36. [table
  37. [[Expression] [Semantics] [Return type]]
  38. [[`l.collect(def, state, targetstate)`]
  39. [Add all token definitions provided
  40. by this Lexer instance to the lexer
  41. state `state` of the token definition
  42. container `def`. After matching this token, the
  43. lexer should be switched into the state
  44. `targetstate` (optional)] [`void`]]
  45. [[`l.add_actions(def)`] [Add all semantic actions provided
  46. by this Lexer instance to the token
  47. definition container `def`.] [`void`]]
  48. ]
  49. [heading Type Expressions]
  50. [table
  51. [[Expression] [Description]]
  52. [[`traits::is_lexer<L>::type`] [Metafunction that evaluates to `mpl::true_` if
  53. a certain type, `L` is a Lexer, `mpl::false_`
  54. otherwise (See __mpl_boolean_constant__).]]
  55. ]
  56. [heading Postcondition]
  57. Upon return from `l.collect` the following post conditions should hold:
  58. * On return, `def` holds all token definitions defined in the Lexer, `l`. This
  59. includes all Lexer's contained inside `l`.
  60. Upon return from `l.add_actions` the following post conditions should hold:
  61. * On return, `def` holds all semantic actions correctly associated with the
  62. corresponding token definitions as defined in the Lexer, `l`. This
  63. includes all semantic actions defined by the Lexer's contained inside `l`.
  64. [heading Models]
  65. All lexer components in __lex__ are models of the /Lexer/ concept.
  66. [endsect] [/ Lexer Concept]
  67. [/////////////////////////////////////////////////////////////////////////////]
  68. [section PrimitiveLexer]
  69. [heading Description]
  70. /PrimitiveLexer/ is the most basic building block that the client uses
  71. to build more complex lexer components.
  72. [heading Refinement of]
  73. [:__lexer_concept__]
  74. [heading Type Expressions]
  75. [table
  76. [[Expression] [Description]]
  77. [[`traits::is_primitive_lexer<L>::type`] [Metafunction that evaluates to `mpl::true_` if
  78. a certain type, `L`, is a PrimitiveLexer, `mpl::false_`
  79. otherwise (See __mpl_boolean_constant__).]]
  80. ]
  81. [heading Models]
  82. The following lexer components conform to this model:
  83. * character literals (i.e. `'x'`), `char_`,
  84. * string literals (`"abc"`), `std::basic_string<>`, `string`
  85. __fixme__ Add more links to /PrimitiveLexer/ models here.
  86. [endsect] [/ PrimitiveLexer Concept]
  87. [/////////////////////////////////////////////////////////////////////////////]
  88. [section UnaryLexer]
  89. [heading Description]
  90. /UnaryLexer/ is a composite lexer component that has a single subject. The
  91. UnaryLexer may change the behavior of its subject following the
  92. __delegate_pattern__.
  93. [heading Refinement of]
  94. [:__lexer_concept__]
  95. [variablelist Notation
  96. [[`l`] [A UnaryLexer.]]
  97. [[`L`] [A UnaryLexer type.]]
  98. ]
  99. [heading Valid Expressions]
  100. In addition to the requirements defined in __lexer_concept__, for any
  101. UnaryLexer the following must be met:
  102. [table
  103. [[Expression] [Semantics] [Return type]]
  104. [[`l.subject`] [Subject lexer component.] [__lexer_concept__]]
  105. ]
  106. [heading Type Expressions]
  107. [table
  108. [[Expression] [Description]]
  109. [[`L::subject_type`] [The subject lexer component type.]]
  110. [[`traits::is_unary_lexer<L>::type`] [Metafunction that evaluates to `mpl::true_` if
  111. a certain type, `L` is a UnaryLexer, `mpl::false_`
  112. otherwise (See __mpl_boolean_constant__).]]
  113. ]
  114. [heading Invariants]
  115. For any UnaryLexer, `L`, the following invariant always holds:
  116. * `traits::is_lexer<L::subject_type>::type` evaluates to `mpl::true_`
  117. [heading Models]
  118. The following lexer components conform to this model:
  119. * action lexer component (allowing to attach semantic actions)
  120. __fixme__ Add more links to models of UnaryLexer concept
  121. [endsect] [/ UnaryLexer Concept]
  122. [/////////////////////////////////////////////////////////////////////////////]
  123. [section NaryLexer]
  124. [heading Description]
  125. /NaryLexer/ is a composite lexer component that has one or more subjects. The
  126. NaryLexer allows its subjects to be treated in the same way as a single
  127. instance of a __lexer_concept__ following the __composite_pattern__.
  128. [heading Refinement of]
  129. [:__lexer_concept__]
  130. [variablelist Notation
  131. [[`l`] [A NaryLexer.]]
  132. [[`L`] [A NaryLexer type.]]
  133. ]
  134. [heading Valid Expressions]
  135. In addition to the requirements defined in __lexer_concept__, for any
  136. NaryLexer the following must be met:
  137. [table
  138. [[Expression] [Semantics] [Return type]]
  139. [[`l.elements`] [The tuple of elements.] [A __fusion__ Sequence of __lexer_concept__ types.]]
  140. ]
  141. [heading Type Expressions]
  142. [table
  143. [[Expression] [Description]]
  144. [[`l.elements_type`] [Elements tuple type.]]
  145. [[`traits::is_nary_lexer<L>::type`] [Metafunction that evaluates to `mpl::true_` if
  146. a certain type, `L` is a NaryLexer, `mpl::false_`
  147. otherwise (See __mpl_boolean_constant__).]]
  148. ]
  149. [heading Invariants]
  150. For each element, `E`, in any NaryLexer, `L`, the following
  151. invariant always holds:
  152. * `traits::is_lexer<E>::type` evaluates to `mpl::true_`
  153. [heading Models]
  154. The following lexer components conform to this model:
  155. * lexer sequence component
  156. __fixme__ Add more links to models of NaryLexer concept
  157. [endsect] [/ NaryLexer Concept]
  158. [endsect]