From e8e62eb46ec000307f0135fdcbc33c81f9b7723a Mon Sep 17 00:00:00 2001 From: ilor <kailoran@gmail.com> Date: Thu, 25 Nov 2010 17:56:35 +0100 Subject: [PATCH] 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 --- libwccl/parser/Parser.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index 66ddfab..94d6014 100644 --- a/libwccl/parser/Parser.cpp +++ b/libwccl/parser/Parser.cpp @@ -134,39 +134,45 @@ boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator( boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator( std::istream& istr) const { + std::stringstream ss; + ss << istr.rdbuf(); + std::stringstream errors; boost::shared_ptr<ANTLRParserResultBase> result; if (!result) { - istr.seekg(0); - ANTLRLexer lexer(istr); + ss.seekg(0, std::ios::beg); + ANTLRLexer lexer(ss); ANTLRParser parser(lexer); try { result = parser.parse_sym_set_operator(tagset_); - } catch (antlr::ANTLRException) { + } catch (antlr::ANTLRException& e) { + errors << "(as tset) " << e.getMessage() << "\n"; // ignore, try another type } } if (!result) { - istr.clear(); - istr.seekg(0); - ANTLRLexer lexer(istr); + ss.seekg(0, std::ios::beg); + ANTLRLexer lexer(ss); ANTLRParser parser(lexer); try { result = parser.parse_string_operator(tagset_); - } catch (antlr::ANTLRException) { + } catch (antlr::ANTLRException& e) { + errors << "(as strset) " << e.getMessage() << "\n"; // ignore, try another type } } if (!result) { - istr.clear(); - istr.seekg(0); - ANTLRLexer lexer(istr); + ss.seekg(0, std::ios::beg); + ANTLRLexer lexer(ss); ANTLRParser parser(lexer); try { result = parser.parse_predicates(tagset_); - } catch (antlr::ANTLRException) { - throw; + } catch (antlr::ANTLRException& e) { + errors << "(as predicate) " << e.getMessage() << "\n"; + // ignore, try another type } } - assert(result); + if (!result) { + throw ParserException(errors.str()); + } return result; } -- GitLab