simple grammar but many errors. newbie needs help.

View: New views
1 Messages — Rating Filter:   Alert me  

simple grammar but many errors. newbie needs help.

by varnie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

good day.

i'm trying to learn spirit 2.x and i'm toying with the grammar as below. could you please help me fixing its errors? thanks in advance!

//start
 class ident_decl_node {

            //this will  enable fusion_adapt_struct to access your private members
            template < typename, int>
            friend struct boost::fusion::extension::struct_member;

            int type;
            std::string ident;
};

BOOST_FUSION_ADAPT_STRUCT(
   ident_decl_node,
   (int, type)
   (std::string, ident)
)

class empty{};
typedef std::vector<boost::variant<ident_decl_node, empty> > ScriptNodes;

template <typename Iterator>
struct my_grammar : qi::grammar<Iterator, ScriptNodes(), ascii::space_type> {

                struct vartypes_keywords : qi::symbols<char, int> {
                    vartypes_keywords() {
                        add
                        ("void", 0)
                        ("string", 1)
                        ("float", 2)
                        ("int", 3)
                        ("bool", 4)
                        ;
                    }
                } vartypes_keywords_;

                my_grammar() : my_grammar::base_type(start) {

                    using phoenix::construct;
                    using phoenix::at_c;
                    using phoenix::new_;
                    using namespace boost::spirit;
                    using namespace boost::spirit::qi;
                    using namespace boost::spirit::ascii;
                    using namespace boost::spirit::arg_names;
                    using boost::spirit::arg_names::_1;
                    using boost::spirit::arg_names::_val;

                    start %= ident_decl >> eps;
                 
                    ident %= raw[lexeme[((alpha | char_('_')) >> *(alnum | char_('_'))) - vartypes_keywords_]];

                    ident_decl %= vartypes_keywords_ > ident;
                }

                qi::rule<Iterator, std::string(), ascii::space_type> ident;
                qi::rule<Iterator, ident_decl_node(), ascii::space_type> ident_decl;
                qi::rule<Iterator, ScriptNodes(), ascii::space_type> start;
};
//end

i appreciate your help.