• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2002-2003 Joel de Guzman
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 
10 // *** See the section "Look Ma' No Rules" in
11 // *** chapter "Techniques" of the Spirit documentation
12 // *** for information regarding this snippet
13 
14 #include <iostream>
15 #include <boost/spirit/include/classic_core.hpp>
16 #include <boost/assert.hpp>
17 
18 using namespace BOOST_SPIRIT_CLASSIC_NS;
19 
20     struct skip_grammar : grammar<skip_grammar>
21     {
22         template <typename ScannerT>
23         struct definition
24         {
definitionskip_grammar::definition25             definition(skip_grammar const& /*self*/)
26             {
27                 skip
28                     =   space_p
29                     |   "//" >> *(anychar_p - '\n') >> '\n'
30                     |   "/*" >> *(anychar_p - "*/") >> "*/"
31                     ;
32             }
33 
34             rule<ScannerT> skip;
35 
36             rule<ScannerT> const&
startskip_grammar::definition37             start() const { return skip; }
38         };
39     };
40 
41 int
main()42 main()
43 {
44     skip_grammar g;
45     bool success = parse(
46         "/*this is a comment*/\n//this is a c++ comment\n\n",
47         *g).full;
48     BOOST_ASSERT(success);
49     std::cout << "SUCCESS!!!\n";
50     return 0;
51 }
52