matches.xml 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. Copyright 2012 Eric Niebler
  4. Distributed under the Boost
  5. Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <header name="boost/proto/matches.hpp">
  9. <para>
  10. Contains definition of the
  11. <computeroutput>
  12. <classname alt="boost::proto::matches">proto::matches&lt;&gt;</classname>
  13. </computeroutput>
  14. metafunction for determining if a given expression matches a given pattern.
  15. </para>
  16. <namespace name="boost">
  17. <namespace name="proto">
  18. <struct name="_">
  19. <inherit><type><classname>proto::transform</classname>&lt;_&gt;</type></inherit>
  20. <purpose>A wildcard grammar element that matches any expression, and a transform that returns
  21. the current expression unchanged.</purpose>
  22. <description>
  23. <para>
  24. The wildcard type, <computeroutput>proto::_</computeroutput>, is a grammar element such
  25. that <computeroutput><classname>proto::matches</classname>&lt;E, proto::_&gt;::value</computeroutput>
  26. is <computeroutput>true</computeroutput> for any expression type <computeroutput>E</computeroutput>.
  27. </para>
  28. <para>
  29. The wildcard can also be used as a stand-in for a template argument when matching terminals.
  30. For instance, the following is a grammar that will match any
  31. <computeroutput>std::complex&lt;&gt;</computeroutput> terminal:<programlisting>BOOST_MPL_ASSERT((
  32. <classname>proto::matches</classname>&lt;
  33. <classname>proto::terminal</classname>&lt;std::complex&lt;double&gt; &gt;::type,
  34. <emphasis role="bold"><classname>proto::terminal</classname>&lt;std::complex&lt; proto::_ &gt; &gt;</emphasis>
  35. &gt;
  36. ));</programlisting>
  37. </para>
  38. <para>
  39. When used as a transform, <computeroutput>proto::_</computeroutput> returns the current expression
  40. unchanged. For instance, in the following, <computeroutput>proto::_</computeroutput> is used with
  41. the <computeroutput><classname alt="proto::fold">proto::fold&lt;&gt;</classname></computeroutput>
  42. transform to fold the children of a node:<programlisting>struct CountChildren :
  43. <classname>proto::or_</classname>&lt;
  44. // Terminals have no children
  45. <classname>proto::when</classname>&lt;<classname>proto::terminal</classname>&lt;proto::_&gt;, mpl::int_&lt;0&gt;()&gt;,
  46. // Use proto::fold&lt;&gt; to count the children of non-terminals
  47. <classname>proto::otherwise</classname>&lt;
  48. <classname>proto::fold</classname>&lt;
  49. proto::_, // &lt;-- fold the current expression
  50. mpl::int_&lt;0&gt;(),
  51. mpl::plus&lt;<classname>proto::_state</classname>, mpl::int_&lt;1&gt; &gt;()
  52. &gt;
  53. &gt;
  54. &gt;
  55. {};</programlisting>
  56. </para>
  57. </description>
  58. <struct name="impl">
  59. <template>
  60. <template-type-parameter name="Expr"/>
  61. <template-type-parameter name="State"/>
  62. <template-type-parameter name="Data"/>
  63. </template>
  64. <inherit><type><classname>proto::transform_impl</classname>&lt;Expr, State, Data&gt;</type></inherit>
  65. <typedef name="result_type">
  66. <type>Expr</type>
  67. </typedef>
  68. <method-group name="public member functions">
  69. <method name="operator()" cv="const">
  70. <type>Expr</type>
  71. <parameter name="expr">
  72. <paramtype>typename impl::expr_param</paramtype>
  73. <description>
  74. <para>An expression </para>
  75. </description>
  76. </parameter>
  77. <parameter name="">
  78. <paramtype>typename impl::state_param</paramtype>
  79. </parameter>
  80. <parameter name="">
  81. <paramtype>typename impl::data_param</paramtype>
  82. </parameter>
  83. <returns>
  84. <para>
  85. <computeroutput>expr</computeroutput>
  86. </para>
  87. </returns>
  88. </method>
  89. </method-group>
  90. </struct>
  91. <typedef name="proto_grammar">
  92. <type>_</type>
  93. </typedef>
  94. </struct>
  95. <!-- proto::not_ -->
  96. <struct name="not_">
  97. <template>
  98. <template-type-parameter name="Grammar"/>
  99. </template>
  100. <inherit><type><classname>proto::transform</classname>&lt;not_&lt;Grammar&gt; &gt;</type></inherit>
  101. <purpose>Inverts the set of expressions matched by a grammar. When used as a transform,
  102. <computeroutput>proto::not_&lt;&gt;</computeroutput> returns the current expression unchanged.
  103. </purpose>
  104. <description>
  105. <para>
  106. If an expression type <computeroutput>E</computeroutput> does not match a grammar
  107. <computeroutput>G</computeroutput>, then <computeroutput>E</computeroutput> <emphasis>does</emphasis>
  108. match <computeroutput>proto::not_&lt;G&gt;</computeroutput>. For example,
  109. <computeroutput><classname>proto::not_</classname>&lt;<classname>proto::terminal</classname>&lt;<classname>proto::_</classname>&gt; &gt;</computeroutput>
  110. will match any non-terminal.
  111. </para>
  112. </description>
  113. <struct name="impl">
  114. <template>
  115. <template-type-parameter name="Expr"/>
  116. <template-type-parameter name="State"/>
  117. <template-type-parameter name="Data"/>
  118. </template>
  119. <inherit><type><classname>proto::transform_impl</classname>&lt;Expr, State, Data&gt;</type></inherit>
  120. <typedef name="result_type">
  121. <type>Expr</type>
  122. </typedef>
  123. <method-group name="public member functions">
  124. <method name="operator()" cv="const">
  125. <type>Expr</type>
  126. <parameter name="expr">
  127. <paramtype>typename impl::expr_param</paramtype>
  128. <description>
  129. <para>An expression </para>
  130. </description>
  131. </parameter>
  132. <parameter name="">
  133. <paramtype>typename impl::state_param</paramtype>
  134. </parameter>
  135. <parameter name="">
  136. <paramtype>typename impl::data_param</paramtype>
  137. </parameter>
  138. <requires>
  139. <para>
  140. <computeroutput><classname>proto::matches</classname>&lt;Expr, proto::not_&gt;::value</computeroutput>
  141. is <computeroutput>true</computeroutput>.
  142. </para>
  143. </requires>
  144. <returns>
  145. <para>
  146. <computeroutput>expr</computeroutput>
  147. </para>
  148. </returns>
  149. </method>
  150. </method-group>
  151. </struct>
  152. <typedef name="proto_grammar">
  153. <type>not_</type>
  154. </typedef>
  155. </struct>
  156. <!-- proto::if_ -->
  157. <struct name="if_">
  158. <template>
  159. <template-type-parameter name="If"/>
  160. <template-type-parameter name="Then">
  161. <default><type><classname>proto::_</classname></type></default>
  162. </template-type-parameter>
  163. <template-type-parameter name="Else">
  164. <default><type><classname>proto::not_</classname>&lt;<classname>proto::_</classname>&gt;</type></default>
  165. </template-type-parameter>
  166. </template>
  167. <inherit><classname>proto::transform</classname>&lt;if_&lt;If, Then, Else&gt; &gt;</inherit>
  168. <purpose>Used to select one grammar or another based on the result of a compile-time Boolean.
  169. When used as a transform, <computeroutput>proto::if_&lt;&gt;</computeroutput> selects between two
  170. transforms based on a compile-time Boolean.</purpose>
  171. <description>
  172. <para>
  173. When <computeroutput>proto::if_&lt;If, Then, Else&gt;</computeroutput> is used as a grammar,
  174. <computeroutput>If</computeroutput> must be a Proto transform and
  175. <computeroutput>Then</computeroutput> and <computeroutput>Else</computeroutput> must be grammars.
  176. An expression type <computeroutput>E</computeroutput> matches
  177. <computeroutput>proto::if_&lt;If, Then, Else&gt;</computeroutput> if
  178. <computeroutput>boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>, If&gt;(E)&gt;::type::value</computeroutput>
  179. is <computeroutput>true</computeroutput> and
  180. <computeroutput>E</computeroutput> matches <computeroutput>Then</computeroutput>; or, if
  181. <computeroutput>boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>, If&gt;(E)&gt;::type::value</computeroutput>
  182. is <computeroutput>false</computeroutput> and <computeroutput>E</computeroutput> matches <computeroutput>Else</computeroutput>.
  183. </para>
  184. <para>
  185. The template parameter <computeroutput>Then</computeroutput> defaults to <computeroutput><classname>proto::_</classname></computeroutput>
  186. and <computeroutput>Else</computeroutput> defaults to
  187. <computeroutput><classname>proto::not_</classname>&lt;<classname>proto::_</classname>&gt;</computeroutput>,
  188. so an expression type <computeroutput>E</computeroutput> will match
  189. <computeroutput>proto::if_&lt;If&gt;</computeroutput> if and only if
  190. <computeroutput>boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>, If&gt;(E)&gt;::type::value</computeroutput>
  191. is <computeroutput>true</computeroutput>.
  192. </para>
  193. <para>
  194. <programlisting>// A grammar that only matches integral terminals,
  195. // using is_integral&lt;&gt; from Boost.Type_traits.
  196. struct IsIntegral :
  197. <classname>proto::and_</classname>&lt;
  198. <classname>proto::terminal</classname>&lt;<classname>proto::_</classname>&gt;,
  199. <classname>proto::if_</classname>&lt; boost::is_integral&lt;<classname>proto::_value</classname>&gt;()&gt;
  200. &gt;
  201. {};</programlisting>
  202. </para>
  203. <para>
  204. When <computeroutput>proto::if_&lt;If, Then, Else&gt;</computeroutput> is used as a transform,
  205. <computeroutput>If</computeroutput>, <computeroutput>Then</computeroutput> and
  206. <computeroutput>Else</computeroutput> must be Proto transforms. When applying the transform to
  207. an expression <computeroutput>E</computeroutput>, state <computeroutput>S</computeroutput> and
  208. data <computeroutput>V</computeroutput>, if
  209. <computeroutput>boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>, If&gt;(E,S,V)&gt;::type::value</computeroutput>
  210. is <computeroutput>true</computeroutput> then the <computeroutput>Then</computeroutput> transform
  211. is applied; otherwise the <computeroutput>Else</computeroutput> transform is applied.
  212. <programlisting>// Match a terminal. If the terminal is integral, return
  213. // mpl::true_; otherwise, return mpl::false_.
  214. struct IsIntegral2 :
  215. <classname>proto::when</classname>&lt;
  216. <classname>proto::terminal</classname>&lt;_&gt;,
  217. proto::if_&lt;
  218. boost::is_integral&lt;<classname>proto::_value</classname>&gt;(),
  219. mpl::true_(),
  220. mpl::false_()
  221. &gt;
  222. &gt;
  223. {};</programlisting>
  224. </para>
  225. </description>
  226. <struct name="impl">
  227. <template>
  228. <template-type-parameter name="Expr"/>
  229. <template-type-parameter name="State"/>
  230. <template-type-parameter name="Data"/>
  231. </template>
  232. <inherit><type><classname>proto::transform_impl</classname>&lt; Expr, State, Data &gt;</type></inherit>
  233. <typedef name="result_type">
  234. <type>typename mpl::if_&lt;
  235. typename boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>, If&gt;(Expr, State, Data)&gt;::type,
  236. typename boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>, Then&gt;(Expr, State, Data)&gt;::type,
  237. typename boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>, Else&gt;(Expr, State, Data)&gt;::type
  238. &gt;::type</type>
  239. </typedef>
  240. <method-group name="public member functions">
  241. <method name="operator()" cv="const">
  242. <type>result_type</type>
  243. <parameter name="expr">
  244. <paramtype>typename impl::expr_param</paramtype>
  245. <description>
  246. <para>An expression </para>
  247. </description>
  248. </parameter>
  249. <parameter name="state">
  250. <paramtype>typename impl::state_param</paramtype>
  251. <description>
  252. <para>The current state </para>
  253. </description>
  254. </parameter>
  255. <parameter name="data">
  256. <paramtype>typename impl::data_param</paramtype>
  257. <description>
  258. <para>A data of arbitrary type </para>
  259. </description>
  260. </parameter>
  261. <returns>
  262. <para>
  263. <computeroutput><classname>proto::when</classname>&lt;<classname>proto::_</classname>, <replaceable>Then-or-Else</replaceable>&gt;()(expr, state, data)</computeroutput>
  264. </para>
  265. </returns>
  266. </method>
  267. </method-group>
  268. </struct>
  269. <typedef name="proto_grammar">
  270. <type>if_</type>
  271. </typedef>
  272. </struct>
  273. <!-- proto::or_ -->
  274. <struct name="or_">
  275. <template>
  276. <template-type-parameter name="G" pack="1"/>
  277. </template>
  278. <inherit><type><classname>proto::transform</classname>&lt;or_&lt;G...&gt; &gt;</type></inherit>
  279. <purpose>For matching one of a set of alternate grammars. Alternates are tried in order to avoid ambiguity.
  280. When used as a transform, <computeroutput>proto::or_&lt;&gt;</computeroutput> applies the transform
  281. associated with the first grammar that matches the expression.</purpose>
  282. <description>
  283. <para>
  284. An expression type <computeroutput>E</computeroutput> matches
  285. <computeroutput>proto::or_&lt;G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>&gt;</computeroutput>
  286. if <computeroutput>E</computeroutput> matches any <computeroutput>G<subscript>x</subscript></computeroutput> for
  287. <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
  288. </para>
  289. <para>
  290. When applying
  291. <computeroutput>proto::or_&lt;G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>&gt;</computeroutput>
  292. as a transform with an expression <computeroutput>e</computeroutput> of type <computeroutput>E</computeroutput>,
  293. state <computeroutput>s</computeroutput> and data <computeroutput>d</computeroutput>, it is equivalent to
  294. <computeroutput>G<subscript>x</subscript>()(e, s, d)</computeroutput>, where
  295. <computeroutput>x</computeroutput> is the lowest number such that
  296. <computeroutput><classname>proto::matches</classname>&lt;E, G<subscript>x</subscript>&gt;::value</computeroutput>
  297. is <computeroutput>true</computeroutput>.
  298. </para>
  299. <para>
  300. The maximun number of template arguments <computeroutput>proto::or_&lt;&gt;</computeroutput> accepts
  301. is controlled by the <computeroutput><macroname>BOOST_PROTO_MAX_LOGICAL_ARITY</macroname></computeroutput>
  302. macro.
  303. </para>
  304. </description>
  305. <struct name="impl">
  306. <template>
  307. <template-type-parameter name="Expr"/>
  308. <template-type-parameter name="State"/>
  309. <template-type-parameter name="Data"/>
  310. </template>
  311. <inherit><type><classname>proto::transform_impl</classname>&lt; Expr, State, Data &gt;</type></inherit>
  312. <typedef name="result_type">
  313. <type><replaceable>unspecified</replaceable></type>
  314. </typedef>
  315. <method-group name="public member functions">
  316. <method name="operator()" cv="const">
  317. <type>result_type</type>
  318. <parameter name="expr">
  319. <paramtype>typename impl::expr_param</paramtype>
  320. <description>
  321. <para>An expression </para>
  322. </description>
  323. </parameter>
  324. <parameter name="state">
  325. <paramtype>typename impl::state_param</paramtype>
  326. <description>
  327. <para>The current state </para>
  328. </description>
  329. </parameter>
  330. <parameter name="data">
  331. <paramtype>typename impl::data_param</paramtype>
  332. <description>
  333. <para>A data of arbitrary type </para>
  334. </description>
  335. </parameter>
  336. <returns>
  337. <para>
  338. <computeroutput>
  339. G<subscript>x</subscript>()(expr, state, data)
  340. </computeroutput>, where
  341. <computeroutput>x</computeroutput> is the lowest number such that
  342. <computeroutput>
  343. <classname>proto::matches</classname>&lt;Expr, G<subscript>x</subscript>&gt;::value
  344. </computeroutput>
  345. is <computeroutput>true</computeroutput>.
  346. </para>
  347. </returns>
  348. </method>
  349. </method-group>
  350. </struct>
  351. <typedef name="proto_grammar">
  352. <type>or_</type>
  353. </typedef>
  354. </struct>
  355. <!-- proto::and_ -->
  356. <struct name="and_">
  357. <template>
  358. <template-type-parameter name="G" pack="1"/>
  359. </template>
  360. <inherit><type><classname>proto::transform</classname>&lt;and_&lt;G...&gt; &gt;</type></inherit>
  361. <purpose>For matching all of a set of grammars. When used as a transform,
  362. <computeroutput>proto::and_&lt;&gt;</computeroutput> applies the transform associated
  363. with each grammar in the set and returns the result of the last.</purpose>
  364. <description>
  365. <para>
  366. An expression type <computeroutput>E</computeroutput> matches
  367. <computeroutput>proto::and_&lt;G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>&gt;</computeroutput>
  368. if <computeroutput>E</computeroutput> matches all <computeroutput>G<subscript>x</subscript></computeroutput>
  369. for <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
  370. </para>
  371. <para>
  372. When applying
  373. <computeroutput>proto::and_&lt;G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>&gt;</computeroutput>
  374. as a transform with an expression <computeroutput>e</computeroutput>, state
  375. <computeroutput>s</computeroutput> and data <computeroutput>d</computeroutput>, it is equivalent
  376. to <computeroutput>(G<subscript>0</subscript>()(e, s, d),G<subscript>1</subscript>()(e, s, d),...G<subscript>n</subscript>()(e, s, d))</computeroutput>.
  377. </para>
  378. <para>
  379. The maximun number of template arguments <computeroutput>proto::and_&lt;&gt;</computeroutput> accepts
  380. is controlled by the <computeroutput><macroname>BOOST_PROTO_MAX_LOGICAL_ARITY</macroname></computeroutput>
  381. macro.
  382. </para>
  383. </description>
  384. <struct name="impl">
  385. <template>
  386. <template-type-parameter name="Expr"/>
  387. <template-type-parameter name="State"/>
  388. <template-type-parameter name="Data"/>
  389. </template>
  390. <inherit><type><classname>proto::transform_impl</classname>&lt; Expr, State, Data &gt;</type></inherit>
  391. <typedef name="result_type">
  392. <type>typename boost::result_of&lt;G<subscript>n</subscript>(Expr, State, Data)&gt;::type</type>
  393. </typedef>
  394. <method-group name="public member functions">
  395. <method name="operator()" cv="const">
  396. <type>result_type</type>
  397. <parameter name="expr">
  398. <paramtype>typename impl::expr_param</paramtype>
  399. <description>
  400. <para>An expression </para>
  401. </description>
  402. </parameter>
  403. <parameter name="state">
  404. <paramtype>typename impl::state_param</paramtype>
  405. <description>
  406. <para>The current state </para>
  407. </description>
  408. </parameter>
  409. <parameter name="data">
  410. <paramtype>typename impl::data_param</paramtype>
  411. <description>
  412. <para>A data of arbitrary type </para>
  413. </description>
  414. </parameter>
  415. <returns>
  416. <para>
  417. <computeroutput>(G<subscript>0</subscript>()(expr, state, data),G<subscript>1</subscript>()(expr, state, data),...G<subscript>n</subscript>()(expr, state, data))</computeroutput>
  418. </para>
  419. </returns>
  420. </method>
  421. </method-group>
  422. </struct>
  423. <typedef name="proto_grammar">
  424. <type>and_</type>
  425. </typedef>
  426. </struct>
  427. <!-- proto::switch_ -->
  428. <struct name="switch_">
  429. <template>
  430. <template-type-parameter name="Cases"/>
  431. <template-type-parameter name="Transform"/>
  432. </template>
  433. <inherit><classname>proto::transform</classname>&lt;switch_&lt;Cases, Transform&gt; &gt;</inherit>
  434. <purpose>For matching one of a set of alternate grammars, which are looked up based on
  435. the result type of the transform passed in second template parameter.
  436. If no transform is passed, the default one is <computeroutput><classname>proto::tag_of</classname>&lt;<classname>proto::_</classname>&gt;()</computeroutput>
  437. so the default matching is based on the expression's tag type. When used as a transform,
  438. <computeroutput>proto::switch_&lt;&gt;</computeroutput> applies the transform associated
  439. with the sub-grammar that matches the expression.</purpose>
  440. <description>
  441. <para>
  442. An expression type <computeroutput>E</computeroutput> matches
  443. <computeroutput>proto::switch_&lt;C,T&gt;</computeroutput> if
  444. <computeroutput>E</computeroutput> matches
  445. <computeroutput>C::case_&lt;boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>,T&gt;(E)&gt;::type&gt;</computeroutput>.
  446. </para>
  447. <para>
  448. When applying <computeroutput>proto::switch_&lt;C,T&gt;</computeroutput> as a
  449. transform with an expression <computeroutput>e</computeroutput> of type
  450. <computeroutput>E</computeroutput>, state <computeroutput>s</computeroutput> of
  451. type <computeroutput>S</computeroutput> and data <computeroutput>d</computeroutput>
  452. of type <computeroutput>D</computeroutput>, it is equivalent to
  453. <computeroutput>C::case_&lt;boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>,T&gt;(E,S,D)&gt;::type&gt;()(e, s, d)</computeroutput>.
  454. </para>
  455. </description>
  456. <struct name="impl">
  457. <template>
  458. <template-type-parameter name="Expr"/>
  459. <template-type-parameter name="State"/>
  460. <template-type-parameter name="Data"/>
  461. </template>
  462. <inherit><type>
  463. Cases::template case_&lt;
  464. typename <classname>when</classname>&lt;_, Transform&gt;::template impl&lt;Expr, State, Data&gt;::result_type
  465. &gt;::template impl&lt;Expr, State, Data&gt;</type>
  466. </inherit>
  467. </struct>
  468. <typedef name="proto_grammar">
  469. <type>switch_</type>
  470. </typedef>
  471. </struct>
  472. <!-- proto::exact -->
  473. <struct name="exact">
  474. <template>
  475. <template-type-parameter name="T"/>
  476. </template>
  477. <purpose>For forcing exact matches of terminal types.</purpose>
  478. <description>
  479. <para>By default, matching terminals ignores references and cv-qualifiers. For instance,
  480. a terminal expression of type
  481. <computeroutput><classname>proto::terminal</classname>&lt;int const &amp;&gt;::type</computeroutput>
  482. will match the grammar <computeroutput><classname>proto::terminal</classname>&lt;int&gt;</computeroutput>.
  483. If that is not desired, you can force an exact match with
  484. <computeroutput><classname>proto::terminal</classname>&lt;proto::exact&lt;int&gt; &gt;</computeroutput>.
  485. This will only match integer terminals where the terminal is held by value.</para>
  486. </description>
  487. </struct>
  488. <!-- proto::convertible_to -->
  489. <struct name="convertible_to">
  490. <template>
  491. <template-type-parameter name="T"/>
  492. </template>
  493. <purpose>For matching terminals that are convertible to a type.</purpose>
  494. <description>
  495. <para>
  496. Use <computeroutput>proto::convertible_to&lt;&gt;</computeroutput> to match a terminal that is
  497. convertible to some type. For example, the grammar
  498. <computeroutput><classname>proto::terminal</classname>&lt;proto::convertible_to&lt;int&gt; &gt;</computeroutput>
  499. will match any terminal whose argument is convertible to an integer.
  500. </para>
  501. </description>
  502. </struct>
  503. <!-- proto::vararg -->
  504. <struct name="vararg">
  505. <template>
  506. <template-type-parameter name="Grammar"/>
  507. </template>
  508. <purpose>For matching a Grammar to a variable number of sub-expressions.</purpose>
  509. <description>
  510. <para>
  511. An expression type <computeroutput><classname>proto::basic_expr</classname>&lt;AT,
  512. <classname alt="proto::listN">proto::list<replaceable>N</replaceable></classname>&lt;A<subscript>0</subscript>,...A<subscript>n</subscript>,U<subscript>0</subscript>,...U<subscript>m</subscript>&gt; &gt;</computeroutput>
  513. matches a grammar <computeroutput><classname>proto::basic_expr</classname>&lt;BT,
  514. <classname alt="proto::listN">proto::list<replaceable>M</replaceable></classname>&lt;B<subscript>0</subscript>,...B<subscript>n</subscript>,proto::vararg&lt;V&gt; &gt; &gt;</computeroutput>
  515. if <computeroutput>BT</computeroutput> is <computeroutput><classname>proto::_</classname></computeroutput>
  516. or <computeroutput>AT</computeroutput>, and if
  517. <computeroutput>A<subscript>x</subscript></computeroutput> matches
  518. <computeroutput>B<subscript>x</subscript></computeroutput>
  519. for each <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>
  520. and if <computeroutput>U<subscript>x</subscript></computeroutput> matches
  521. <computeroutput>V</computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,m]</computeroutput>.
  522. </para>
  523. <para>For example:</para>
  524. <para>
  525. <programlisting>// Match any function call expression, regardless
  526. // of the number of function arguments:
  527. struct Function :
  528. <classname>proto::function</classname>&lt; proto::vararg&lt;proto::_&gt; &gt;
  529. {};</programlisting>
  530. </para>
  531. <para>
  532. When used as a transform, <computeroutput>proto::vararg&lt;G&gt;</computeroutput>
  533. applies <computeroutput>G</computeroutput>'s transform.
  534. </para>
  535. </description>
  536. </struct>
  537. <!-- proto::matches -->
  538. <struct name="matches">
  539. <template>
  540. <template-type-parameter name="Expr"/>
  541. <template-type-parameter name="Grammar"/>
  542. </template>
  543. <purpose>A Boolean metafunction that evaluates whether a given expression type matches a grammar.</purpose>
  544. <description>
  545. <para>
  546. <computeroutput>proto::matches&lt;Expr, Grammar&gt;</computeroutput> inherits from
  547. <computeroutput>mpl::true_</computeroutput> if
  548. <computeroutput>Expr::proto_grammar</computeroutput> matches
  549. <computeroutput>Grammar::proto_grammar</computeroutput>, and from
  550. <computeroutput>mpl::false_</computeroutput> otherwise.
  551. </para>
  552. <para>
  553. Non-terminal expressions are matched against a grammar according to the following rules:
  554. <itemizedlist>
  555. <listitem>
  556. <para>
  557. The wildcard pattern, <computeroutput>
  558. <classname>proto::_</classname>
  559. </computeroutput>, matches any expression.
  560. </para>
  561. </listitem>
  562. <listitem>
  563. <para>
  564. An expression
  565. <computeroutput>
  566. <classname>proto::basic_expr</classname>&lt;AT,
  567. <classname alt="proto::listN">
  568. proto::list<replaceable>N</replaceable>
  569. </classname>&lt;A<subscript>0</subscript>,...A<subscript>n</subscript>&gt;
  570. &gt;
  571. </computeroutput>
  572. matches a grammar
  573. <computeroutput>
  574. <classname>proto::basic_expr</classname>&lt;BT,
  575. <classname alt="proto::listN">
  576. proto::list<replaceable>N</replaceable>
  577. </classname>&lt;B<subscript>0</subscript>,...B<subscript>n</subscript>&gt;
  578. &gt;
  579. </computeroutput> if
  580. <computeroutput>BT</computeroutput> is <computeroutput>
  581. <classname>proto::_</classname>
  582. </computeroutput> or
  583. <computeroutput>AT</computeroutput>, and if <computeroutput>
  584. A<subscript>x</subscript>
  585. </computeroutput> matches
  586. <computeroutput>
  587. B<subscript>x</subscript>
  588. </computeroutput> for each <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
  589. </para>
  590. </listitem>
  591. <listitem>
  592. <para>
  593. An expression
  594. <computeroutput>
  595. <classname>proto::basic_expr</classname>&lt;AT,
  596. <classname alt="proto::listN">
  597. proto::list<replaceable>N</replaceable>
  598. </classname>&lt;A<subscript>0</subscript>,...A<subscript>n</subscript>,U<subscript>0</subscript>,...U<subscript>m</subscript>&gt;
  599. &gt;
  600. </computeroutput> matches a grammar
  601. <computeroutput>
  602. <classname>proto::basic_expr</classname>&lt;BT,
  603. <classname alt="proto::listN">
  604. proto::list<replaceable>M</replaceable>
  605. </classname>&lt;B<subscript>0</subscript>,...B<subscript>n</subscript>,<classname>proto::vararg</classname>&lt;V&gt;
  606. &gt; &gt;
  607. </computeroutput> if
  608. <computeroutput>BT</computeroutput> is <computeroutput>
  609. <classname>proto::_</classname>
  610. </computeroutput> or
  611. <computeroutput>AT</computeroutput>, and if
  612. <computeroutput>
  613. A<subscript>x</subscript>
  614. </computeroutput> matches
  615. <computeroutput>
  616. B<subscript>x</subscript>
  617. </computeroutput> for each
  618. <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput> and if
  619. <computeroutput>
  620. U<subscript>x</subscript>
  621. </computeroutput> matches
  622. <computeroutput>V</computeroutput> for each <computeroutput>x</computeroutput> in
  623. <computeroutput>[0,m]</computeroutput>.
  624. </para>
  625. </listitem>
  626. <listitem>
  627. <para>
  628. An expression <computeroutput>E</computeroutput> matches
  629. <computeroutput>
  630. <classname>proto::or_</classname>&lt;B<subscript>0</subscript>,...B<subscript>n</subscript>&gt;
  631. </computeroutput> if
  632. <computeroutput>E</computeroutput> matches some
  633. <computeroutput>
  634. B<subscript>x</subscript>
  635. </computeroutput> for
  636. <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
  637. </para>
  638. </listitem>
  639. <listitem>
  640. <para>
  641. An expression <computeroutput>E</computeroutput> matches
  642. <computeroutput>
  643. <classname>proto::and_</classname>&lt;B<subscript>0</subscript>,...B<subscript>n</subscript>&gt;
  644. </computeroutput> if
  645. <computeroutput>E</computeroutput> matches all
  646. <computeroutput>
  647. B<subscript>x</subscript>
  648. </computeroutput> for
  649. <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>.
  650. </para>
  651. </listitem>
  652. <listitem>
  653. <para>
  654. An expression <computeroutput>E</computeroutput> matches
  655. <computeroutput>
  656. <classname>proto::if_</classname>&lt;T,U,V&gt;
  657. </computeroutput> if:
  658. <itemizedlist>
  659. <listitem>
  660. <computeroutput>
  661. boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>,T&gt;(E)&gt;::type::value
  662. </computeroutput>
  663. is <computeroutput>true</computeroutput> and
  664. <computeroutput>E</computeroutput> matches
  665. <computeroutput>U</computeroutput>, <emphasis>or</emphasis>
  666. </listitem>
  667. <listitem>
  668. <computeroutput>
  669. boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>,T&gt;(E)&gt;::type::value
  670. </computeroutput>
  671. is <computeroutput>false</computeroutput> and <computeroutput>E</computeroutput> matches
  672. <computeroutput>V</computeroutput>.
  673. </listitem>
  674. </itemizedlist>
  675. Note: <computeroutput>U</computeroutput> defaults to <computeroutput>
  676. <classname>proto::_</classname>
  677. </computeroutput>
  678. and <computeroutput>V</computeroutput> defaults to
  679. <computeroutput>
  680. <classname>proto::not_</classname>&lt;<classname>proto::_</classname>&gt;
  681. </computeroutput>.
  682. </para>
  683. </listitem>
  684. <listitem>
  685. <para>
  686. An expression <computeroutput>E</computeroutput> matches
  687. <computeroutput>
  688. <classname>proto::not_</classname>&lt;T&gt;
  689. </computeroutput> if
  690. <computeroutput>E</computeroutput> does <emphasis>not</emphasis> match <computeroutput>T</computeroutput>.
  691. </para>
  692. </listitem>
  693. <listitem>
  694. <para>
  695. An expression <computeroutput>E</computeroutput> matches
  696. <computeroutput>
  697. <classname>proto::switch_</classname>&lt;C, T&gt;
  698. </computeroutput> if
  699. <computeroutput>E</computeroutput> matches <computeroutput>C::case_&lt;boost::result_of&lt;<classname>proto::when</classname>&lt;<classname>proto::_</classname>,T&gt;(E)&gt;::type&gt;</computeroutput>.
  700. Note: <computeroutput>T</computeroutput> defaults to <computeroutput><classname>proto::tag_of</classname>&lt;<classname>proto::_</classname>&gt;()</computeroutput>
  701. </para>
  702. </listitem>
  703. </itemizedlist>
  704. </para>
  705. <para>
  706. A terminal expression can trivially match the grammar <classname>proto::_</classname>. In addition,
  707. a terminal expression
  708. <computeroutput>
  709. <classname>proto::basic_expr</classname>&lt;AT,
  710. <classname>proto::term</classname>&lt;A&gt; &gt;
  711. </computeroutput> matches a grammar
  712. <computeroutput>
  713. <classname>proto::basic_expr</classname>&lt;BT, <classname>proto::term</classname>&lt;B&gt; &gt;
  714. </computeroutput>
  715. if <computeroutput>BT</computeroutput> is <computeroutput><classname>proto::_</classname></computeroutput>
  716. or <computeroutput>AT</computeroutput> and one of the following is true:
  717. <itemizedlist>
  718. <listitem>
  719. <para>
  720. <computeroutput>B</computeroutput> is the wildcard pattern,
  721. <computeroutput>
  722. <classname>proto::_</classname>
  723. </computeroutput>
  724. </para>
  725. </listitem>
  726. <listitem>
  727. <para>
  728. <computeroutput>A</computeroutput> is <computeroutput>B</computeroutput>
  729. </para>
  730. </listitem>
  731. <listitem>
  732. <para>
  733. <computeroutput>A</computeroutput> is <computeroutput>B &amp;</computeroutput>
  734. </para>
  735. </listitem>
  736. <listitem>
  737. <para>
  738. <computeroutput>A</computeroutput> is <computeroutput>B const &amp;</computeroutput>
  739. </para>
  740. </listitem>
  741. <listitem>
  742. <para>
  743. <computeroutput>B</computeroutput> is <computeroutput>
  744. <classname>proto::exact</classname>&lt;A&gt;
  745. </computeroutput>
  746. </para>
  747. </listitem>
  748. <listitem>
  749. <para>
  750. <computeroutput>B</computeroutput> is
  751. <computeroutput>
  752. <classname>proto::convertible_to</classname>&lt;X&gt;
  753. </computeroutput>
  754. and <computeroutput>boost::is_convertible&lt;A,X&gt;::value</computeroutput> is
  755. <computeroutput>true</computeroutput>.
  756. </para>
  757. </listitem>
  758. <listitem>
  759. <para>
  760. <computeroutput>A</computeroutput> is <computeroutput>X[M]</computeroutput> or
  761. <computeroutput>X(&amp;)[M]</computeroutput> and
  762. <computeroutput>B</computeroutput> is <computeroutput>
  763. X[<globalname>proto::N</globalname>]
  764. </computeroutput>.
  765. </para>
  766. </listitem>
  767. <listitem>
  768. <para>
  769. <computeroutput>A</computeroutput> is <computeroutput>X(&amp;)[M]</computeroutput>
  770. and <computeroutput>B</computeroutput> is <computeroutput>
  771. X(&amp;)[<globalname>proto::N</globalname>]
  772. </computeroutput>.
  773. </para>
  774. </listitem>
  775. <listitem>
  776. <para>
  777. <computeroutput>A</computeroutput> is <computeroutput>X[M]</computeroutput> or
  778. <computeroutput>X(&amp;)[M]</computeroutput> and <computeroutput>B</computeroutput> is
  779. <computeroutput>X*</computeroutput>.
  780. </para>
  781. </listitem>
  782. <listitem>
  783. <para>
  784. <computeroutput>B</computeroutput> <replaceable>lambda-matches</replaceable>
  785. <computeroutput>A</computeroutput> (see below).
  786. </para>
  787. </listitem>
  788. </itemizedlist>
  789. </para>
  790. <para>
  791. A type <computeroutput>B</computeroutput> <replaceable>lambda-matches</replaceable>
  792. <computeroutput>A</computeroutput> if one of the following is true:
  793. <itemizedlist>
  794. <listitem>
  795. <para>
  796. <computeroutput>B</computeroutput> is <computeroutput>A</computeroutput>
  797. </para>
  798. </listitem>
  799. <listitem>
  800. <para>
  801. <computeroutput>B</computeroutput> is the wildcard pattern, <computeroutput>
  802. <classname>proto::_</classname>
  803. </computeroutput>
  804. </para>
  805. </listitem>
  806. <listitem>
  807. <para>
  808. <computeroutput>B</computeroutput> is <computeroutput>
  809. T&lt;B<subscript>0</subscript>,...B<subscript>n</subscript>&gt;
  810. </computeroutput> and <computeroutput>A</computeroutput> is <computeroutput>
  811. T&lt;A<subscript>0</subscript>,...A<subscript>n</subscript>&gt;
  812. </computeroutput> and for each <computeroutput>x</computeroutput> in <computeroutput>[0,n]</computeroutput>,
  813. <computeroutput>A<subscript>x</subscript></computeroutput> and
  814. <computeroutput>B<subscript>x</subscript></computeroutput> are types such that
  815. <computeroutput>A<subscript>x</subscript></computeroutput> <replaceable>lambda-matches</replaceable>
  816. <computeroutput>B<subscript>x</subscript></computeroutput>
  817. </para>
  818. </listitem>
  819. </itemizedlist>
  820. </para>
  821. </description>
  822. <inherit>
  823. <type>mpl::bool_&lt;<replaceable>true-or-false</replaceable>&gt;</type></inherit>
  824. </struct>
  825. </namespace>
  826. </namespace>
  827. </header>