]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/example/fundamental/distinct/distinct_parser.cpp
1 /*=============================================================================
2 Copyright (c) 2003 Vaclav Vesely
3 http://spirit.sourceforge.net/
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #include <boost/assert.hpp>
11 #include <boost/cstdlib.hpp>
12 #include <boost/spirit/include/classic_core.hpp>
13 #include <boost/spirit/include/classic_distinct.hpp>
16 using namespace boost
;
17 using namespace BOOST_SPIRIT_CLASSIC_NS
;
20 // (for basic usage instead of std_p)
21 const distinct_parser
<> keyword_p("0-9a-zA-Z_");
24 // (for mor intricate usage, for example together with symbol tables)
25 const distinct_directive
<> keyword_d("0-9a-zA-Z_");
27 struct my_grammar
: public grammar
<my_grammar
>
29 template <typename ScannerT
>
32 typedef rule
<ScannerT
> rule_t
;
34 definition(my_grammar
const& self
)
38 keyword_p("declare") // use keyword_p instead of std_p
40 >> keyword_d
[str_p("ident")] // use keyword_d
46 rule_t
const& start() const
58 info
= parse("declare ident", gram
, space_p
);
59 BOOST_ASSERT(info
.full
); // valid input
61 info
= parse("declare: ident", gram
, space_p
);
62 BOOST_ASSERT(info
.full
); // valid input
64 info
= parse("declareident", gram
, space_p
);
65 BOOST_ASSERT(!info
.hit
); // invalid input