1 /*============================================================================= 2 Copyright (c) 2003 Vaclav Vesely 3 http://spirit.sourceforge.net/ 4 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> 10 #include <iostream> 11 #include <boost/cstdlib.hpp> 12 #include <boost/spirit/include/classic_core.hpp> 13 #include <boost/spirit/include/classic_distinct.hpp> 14 15 using namespace std; 16 using namespace boost; 17 using namespace BOOST_SPIRIT_CLASSIC_NS; 18 19 struct my_grammar: public grammar<my_grammar> 20 { 21 template <typename ScannerT> 22 struct definition 23 { 24 typedef rule<ScannerT> rule_t; 25 26 // keyword_p for ASN.1 27 dynamic_distinct_parser<ScannerT> keyword_p; 28 definitionmy_grammar::definition29 definition(my_grammar const& self) 30 : keyword_p(alnum_p | ('-' >> ~ch_p('-'))) // ASN.1 has quite complex naming rules 31 { 32 top 33 = 34 keyword_p("asn-declare") // use keyword_p instead of std_p 35 >> !str_p("--") 36 >> keyword_p("ident") 37 ; 38 } 39 40 rule_t top; 41 startmy_grammar::definition42 rule_t const& start() const 43 { 44 return top; 45 } 46 }; 47 }; 48 main()49int main() 50 { 51 my_grammar gram; 52 parse_info<> info; 53 54 info = parse("asn-declare ident", gram, space_p); 55 BOOST_ASSERT(info.full); // valid input 56 57 info = parse("asn-declare--ident", gram, space_p); 58 BOOST_ASSERT(info.full); // valid input 59 60 info = parse("asn-declare-ident", gram, space_p); 61 BOOST_ASSERT(!info.hit); // invalid input 62 63 return exit_success; 64 } 65