c++ - Error handling in Boost Spirit symbol table -


assuming have symbol table this:

struct jass_types : qi::symbols<char, jass_type> { 

now want fill customly declared type parent type:

identifier %=      char_("a-za-z") >> -(*char_("a-za-z_0-9") >> char_("a-za-z0-9"))     ;  type %=     lit("type") >> identifier >>     lit("extends") >> identifier[type_symbols.find(_1)] 

the structure followed:

boost_fusion_adapt_struct( wc3lib::jass::jass_type, (std::string, identifier) (wc3lib::jass::jass_type*, parent) ) 

how have write code stores 0 attribute "parent" if identifier after "extends" not found in symbol table , how react missing symbols properly?

my idea make like:

boost::variant<wc3lib::jass::jass_type*,std::string> parent 

and fill either pointer or identifier depending on fact if type found in symbol table or not have detect typeinformation of parent afterwards. option store 0 parent mentoined , create error object identifier information etc. maybe boost same thing if symbol not found???

edit:

firstly made error of using _2 instead of _1 still won't work since apparently needs char* value instead of std::string, added custom function:

inline jass_type* get_type_symbol(jass_types &types, const std::string &value) {     return types.find(value.c_str()); } 

and semantic action:

type =     lit("type") >> identifier >>     lit("extends") >> identifier[phoenix::bind(&get_type_symbol, ref(type_symbols), _1)]     ; 

but still seems overcomplicated way , couldn't solve problem of proper error detection/storage of identifier if symbol not found!

you can this:

// simplified identifier rule exposes `std::strirng`: qi::rule<it, std::string()> identifier = char_("a-za-z") >> *char_("a-za-z_0-9");  struct jass_types : qi::symbols<char, jass_type*> {         // ... };  typedef boost::variant<jass_type*, std::string> jass_typeref; jass_types type_symbols; 

note made symbols<> parser return pointer jass_type directly. rule simple as:

qi::rule<it, jass_typeref()> typeref_ = type_symbols | identifier; 

use e.g. as

type %= "type" >> identifier >> "extends" >> typeref_; 

to supply default, do

type %= "type" >> identifier >>          ("extends" >> typeref_ | qi::attr(std::string("::object"))); 

(assuming types ultimate extend ::object)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -