Skip to content
Snippets Groups Projects
Commit e8e62eb4 authored by ilor's avatar ilor
Browse files

use a stringstream in parse any, gather all exceptions so more useful info is...

use a stringstream in parse any, gather all exceptions so more useful info is displayed in case all rules fail

Conflicts:

	libwccl/parser/Parser.cpp
parent 5b46a726
No related branches found
No related tags found
No related merge requests found
...@@ -134,39 +134,45 @@ boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator( ...@@ -134,39 +134,45 @@ boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator(
boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator( boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator(
std::istream& istr) const std::istream& istr) const
{ {
std::stringstream ss;
ss << istr.rdbuf();
std::stringstream errors;
boost::shared_ptr<ANTLRParserResultBase> result; boost::shared_ptr<ANTLRParserResultBase> result;
if (!result) { if (!result) {
istr.seekg(0); ss.seekg(0, std::ios::beg);
ANTLRLexer lexer(istr); ANTLRLexer lexer(ss);
ANTLRParser parser(lexer); ANTLRParser parser(lexer);
try { try {
result = parser.parse_sym_set_operator(tagset_); result = parser.parse_sym_set_operator(tagset_);
} catch (antlr::ANTLRException) { } catch (antlr::ANTLRException& e) {
errors << "(as tset) " << e.getMessage() << "\n";
// ignore, try another type // ignore, try another type
} }
} }
if (!result) { if (!result) {
istr.clear(); ss.seekg(0, std::ios::beg);
istr.seekg(0); ANTLRLexer lexer(ss);
ANTLRLexer lexer(istr);
ANTLRParser parser(lexer); ANTLRParser parser(lexer);
try { try {
result = parser.parse_string_operator(tagset_); result = parser.parse_string_operator(tagset_);
} catch (antlr::ANTLRException) { } catch (antlr::ANTLRException& e) {
errors << "(as strset) " << e.getMessage() << "\n";
// ignore, try another type // ignore, try another type
} }
} }
if (!result) { if (!result) {
istr.clear(); ss.seekg(0, std::ios::beg);
istr.seekg(0); ANTLRLexer lexer(ss);
ANTLRLexer lexer(istr);
ANTLRParser parser(lexer); ANTLRParser parser(lexer);
try { try {
result = parser.parse_predicates(tagset_); result = parser.parse_predicates(tagset_);
} catch (antlr::ANTLRException) { } catch (antlr::ANTLRException& e) {
throw; errors << "(as predicate) " << e.getMessage() << "\n";
// ignore, try another type
}
} }
if (!result) {
throw ParserException(errors.str());
} }
assert(result);
return result; return result;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment