fork download
  1. // #define BOOST_SPIRIT_DEBUG
  2. #include <iostream>
  3. #include <iterator>
  4. #include <boost/spirit/include/qi.hpp>
  5. #include <boost/spirit/include/phoenix.hpp>
  6.  
  7. namespace qi = boost::spirit::qi;
  8.  
  9. namespace
  10. {
  11. template<typename Iterator>
  12. struct skel_grammar : public qi::grammar<Iterator>
  13. {
  14. skel_grammar() : skel_grammar::base_type(start)
  15. {
  16. using namespace qi;
  17.  
  18. text = no_skip[+(char_ - macro_b)]; // [_val += _1]];
  19. macro_b = lit("<<");
  20. macro_e = lit(">>");
  21. macro %= macro_b >> skip(space) [ id ] >> macro_e;
  22. id %=
  23. -(alpha | char_('_'))
  24. >> +(alnum | char_('_'));
  25.  
  26. start = *(text | macro);
  27.  
  28. BOOST_SPIRIT_DEBUG_NODE(start);
  29. BOOST_SPIRIT_DEBUG_NODE(macro);
  30. BOOST_SPIRIT_DEBUG_NODE(macro_e);
  31. BOOST_SPIRIT_DEBUG_NODE(macro_b);
  32. BOOST_SPIRIT_DEBUG_NODE(id);
  33. BOOST_SPIRIT_DEBUG_NODE(text);
  34. }
  35.  
  36. private:
  37. qi::rule<Iterator> macro_b;
  38. qi::rule<Iterator> macro_e;
  39. qi::rule<Iterator, qi::space_type> id;
  40. qi::rule<Iterator> macro;
  41. qi::rule<Iterator> text;
  42. qi::rule<Iterator> start;
  43. };
  44.  
  45. } // namespace
  46.  
  47. int main(int argc, char* argv[])
  48. {
  49. std::string input(std::istreambuf_iterator<char>(std::cin),
  50. (std::istreambuf_iterator<char>()));
  51. skel_grammar<std::string::iterator> grammar;
  52.  
  53. bool r = qi::parse(input.begin(), input.end(), grammar);
  54.  
  55. std::cout << std::boolalpha << r << '\n';
  56.  
  57. return 0;
  58. }
  59.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:39: error: ‘space_type’ is not a member of ‘qi’
prog.cpp:39: error: ‘space_type’ is not a member of ‘qi’
prog.cpp:39: error: template argument 2 is invalid
prog.cpp: In constructor ‘<unnamed>::skel_grammar<Iterator>::skel_grammar()’:
prog.cpp:18: error: ‘no_skip’ was not declared in this scope
prog.cpp:18: error: ‘char_’ was not declared in this scope
prog.cpp:19: error: there are no arguments to ‘lit’ that depend on a template parameter, so a declaration of ‘lit’ must be available
prog.cpp:19: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
prog.cpp:20: error: there are no arguments to ‘lit’ that depend on a template parameter, so a declaration of ‘lit’ must be available
prog.cpp:21: error: ‘space’ was not declared in this scope
prog.cpp:23: error: ‘alpha’ was not declared in this scope
prog.cpp:24: error: ‘alnum’ was not declared in this scope
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:53: error: invalid initialization of non-const reference of type ‘__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&’ from a temporary of type ‘__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’
/usr/include/boost/spirit/home/qi/parse.hpp:23: error: in passing argument 1 of ‘bool boost::spirit::qi::parse(Iterator&, Iterator, const Expr&) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = <unnamed>::skel_grammar<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >]’
prog.cpp: In constructor ‘<unnamed>::skel_grammar<Iterator>::skel_grammar() [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]’:
prog.cpp:51:   instantiated from here
prog.cpp:19: error: ‘lit’ was not declared in this scope
stdout
Standard output is empty