Reputation: 33
I'm trying to extend an existing use of Boost::spirit implementing a configuration language (with Boost 1.55.0).
If a rule or token fails to match, then the Boost system happily takes care of throwing an expectation_failure
exception that I can use to complain about where in the nested set of configuration files the error was encountered.
However, there are several clauses where a semantic action consists of something like:
[ phx::bind(map_insert_table, qi::_1, ref(tbl), _val) ]
where map_insert_table()
is a function I define which might have an exception condition. If I simply throw my own C++ exception I will abort processing of the file with a meaningful error message, but I will have no way to tell the user the location of their error. If I simply set _pass
to false per boost spirit semantic action parameters, then the user will know where the error occurred, but not be given the information we have as to what was actually wrong.
I appreciate the information in that linked question regarding the context, but I don't see how it can help me here, nor how I would access it from the semantic action as phrased above.
I also appreciate that I might be told I'm not using the system in the best way -- that may be true, and I can make incremental changes, but rewriting our whole use of Boost::spirit would be very much a solution of last resort.
All answers appreciated. If more information is needed for my question to be answered (this is my first post after years of lurking) I will certainly try to provide it.
Upvotes: 3
Views: 170
Reputation: 393114
You are already using references inside the phoenix actor. You can use the same method to store error information somewhere "out-of-band".
Alternatively, you might store optional diagnostics information as part of the attribute type.
Upvotes: 1