diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index 1a822aab2083902c3b626bc42b80d71088466c93..b7dca250796cbd6bbb657325e75b30bf43a12493 100644 --- a/libwccl/parser/Parser.cpp +++ b/libwccl/parser/Parser.cpp @@ -36,7 +36,12 @@ boost::shared_ptr<Operator<StrSet> > Parser::parseStringOperator( std::stringstream ss (std::stringstream::in | std::stringstream::out); ss << str; - return this->parseStringOperator(ss); + try { + return this->parseStringOperator(ss); + } + catch (ParserException&) { + throw; + } } /** @@ -50,8 +55,27 @@ boost::shared_ptr<Operator<StrSet> > Parser::parseStringOperator( { ANTLRLexer lexer(istr); ANTLRParser parser(lexer); + boost::shared_ptr<Operator<StrSet> > res; + + try { + res = parser.parse_strset_operator(tagset_); + } catch (antlr::MismatchedTokenException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::NoViableAltException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::TokenStreamRecognitionException &e) { + throw ParserException( + e.getLine() + ":" + e.getColumn() + std::string(" ") + e.getMessage() + ); + } catch (antlr::ANTLRException& e) { + throw ParserException(e.getMessage()); + } - return parser.parse_strset_operator(tagset_); + return res; } /** @@ -66,7 +90,12 @@ boost::shared_ptr<Operator<Bool> > Parser::parseBoolOperator( std::stringstream ss (std::stringstream::in | std::stringstream::out); ss << str; - return this->parseBoolOperator(ss); + try { + return this->parseBoolOperator(ss); + } + catch (ParserException&) { + throw; + } } /** @@ -79,8 +108,27 @@ boost::shared_ptr<Operator<Bool> > Parser::parseBoolOperator( { ANTLRLexer lexer(istr); ANTLRParser parser(lexer); + boost::shared_ptr<Operator<Bool> > res; + + try { + res = parser.parse_bool_operator(tagset_); + } catch (antlr::MismatchedTokenException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::NoViableAltException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::TokenStreamRecognitionException &e) { + throw ParserException( + e.getLine() + ":" + e.getColumn() + std::string(" ") + e.getMessage() + ); + } catch (antlr::ANTLRException& e) { + throw ParserException(e.getMessage()); + } - return parser.parse_bool_operator(tagset_); + return res; } // ---------------------------------------------------------------------------- @@ -96,7 +144,12 @@ boost::shared_ptr<Operator<TSet> > Parser::parseSymSetOperator( std::stringstream ss (std::stringstream::in | std::stringstream::out); ss << str; - return this->parseSymSetOperator(ss); + try { + return this->parseSymSetOperator(ss); + } + catch (ParserException&) { + throw; + } } /** @@ -110,7 +163,27 @@ boost::shared_ptr<Operator<TSet> > Parser::parseSymSetOperator( { ANTLRLexer lexer(istr); ANTLRParser parser(lexer); - return parser.parse_symset_operator(tagset_); + boost::shared_ptr<Operator<TSet> > res; + + try { + res = parser.parse_symset_operator(tagset_); + } catch (antlr::MismatchedTokenException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::NoViableAltException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::TokenStreamRecognitionException &e) { + throw ParserException( + e.getLine() + ":" + e.getColumn() + std::string(" ") + e.getMessage() + ); + } catch (antlr::ANTLRException& e) { + throw ParserException(e.getMessage()); + } + + return res; } // ---------------------------------------------------------------------------- @@ -126,7 +199,12 @@ boost::shared_ptr<Operator<Position> > Parser::parsePositionOperator( std::stringstream ss (std::stringstream::in | std::stringstream::out); ss << str; - return this->parsePositionOperator(ss); + try { + return this->parsePositionOperator(ss); + } + catch (ParserException&) { + throw; + } } /** @@ -140,7 +218,27 @@ boost::shared_ptr<Operator<Position> > Parser::parsePositionOperator( { ANTLRLexer lexer(istr); ANTLRParser parser(lexer); - return parser.parse_position_operator(tagset_); + boost::shared_ptr<Operator<Position> > res; + + try { + res = parser.parse_position_operator(tagset_); + } catch (antlr::MismatchedTokenException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::NoViableAltException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::TokenStreamRecognitionException &e) { + throw ParserException( + e.getLine() + ":" + e.getColumn() + std::string(" ") + e.getMessage() + ); + } catch (antlr::ANTLRException& e) { + throw ParserException(e.getMessage()); + } + + return res; } /** @@ -304,7 +402,12 @@ boost::shared_ptr<RuleSequence> Parser::parseRuleSequence( std::stringstream ss (std::stringstream::in | std::stringstream::out); ss << str; - return this->parseRuleSequence(ss); + try { + return this->parseRuleSequence(ss); + } + catch (ParserException&) { + throw; + } } /** @@ -318,7 +421,27 @@ boost::shared_ptr<RuleSequence> Parser::parseRuleSequence( { ANTLRLexer lexer(istr); ANTLRParser parser(lexer); - return parser.parse_rule_sequence(tagset_); + boost::shared_ptr<RuleSequence> res; + + try { + res = parser.parse_rule_sequence(tagset_); + } catch (antlr::MismatchedTokenException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::NoViableAltException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::TokenStreamRecognitionException &e) { + throw ParserException( + e.getLine() + ":" + e.getColumn() + std::string(" ") + e.getMessage() + ); + } catch (antlr::ANTLRException& e) { + throw ParserException(e.getMessage()); + } + + return res; } // ---------------------------------------------------------------------------- @@ -335,7 +458,12 @@ boost::shared_ptr<Rule> Parser::parseSingleRule( std::stringstream ss (std::stringstream::in | std::stringstream::out); ss << str; - return this->parseSingleRule(ss); + try { + return this->parseSingleRule(ss); + } + catch (ParserException&) { + throw; + } } /** @@ -349,7 +477,27 @@ boost::shared_ptr<Rule> Parser::parseSingleRule( { ANTLRLexer lexer(istr); ANTLRParser parser(lexer); - return parser.parse_single_rule(tagset_); + boost::shared_ptr<Rule> res; + + try { + res = parser.parse_single_rule(tagset_); + } catch (antlr::MismatchedTokenException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::NoViableAltException &e) { + throw ParserException( + e.getFileLineColumnString() + " " + e.getMessage() + ); + } catch(antlr::TokenStreamRecognitionException &e) { + throw ParserException( + e.getLine() + ":" + e.getColumn() + std::string(" ") + e.getMessage() + ); + } catch (antlr::ANTLRException& e) { + throw ParserException(e.getMessage()); + } + + return res; } // ---------------------------------------------------------------------------- diff --git a/libwccl/parser/ParserException.h b/libwccl/parser/ParserException.h index a421a67428690eeb6d54e5492981ebfbe474e3c7..d5d0ca29116f1e4a73f8ed0f467e7c2b9461bcca 100644 --- a/libwccl/parser/ParserException.h +++ b/libwccl/parser/ParserException.h @@ -8,12 +8,13 @@ class ParserException : public Wccl::WcclError { public: - ParserException(const std::string); - ~ParserException() throw() { - } + ParserException(const std::string); - // - std::string info() const { return this->msg; } + ~ParserException() throw() { + } + + // + std::string info() const { return this->msg; } private: std::string msg;