Skip to content
Snippets Groups Projects
Commit 608d1666 authored by Paweł Kędzia's avatar Paweł Kędzia
Browse files

The parser throws ParserException (ParserException inherits from WcclError)

parent 4569eb22
No related branches found
No related tags found
No related merge requests found
...@@ -36,8 +36,13 @@ boost::shared_ptr<Operator<StrSet> > Parser::parseStringOperator( ...@@ -36,8 +36,13 @@ boost::shared_ptr<Operator<StrSet> > Parser::parseStringOperator(
std::stringstream ss (std::stringstream::in | std::stringstream::out); std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str; ss << str;
try {
return this->parseStringOperator(ss); return this->parseStringOperator(ss);
} }
catch (ParserException&) {
throw;
}
}
/** /**
* @desc Parse a string operator. Runs parse_string_operator rule * @desc Parse a string operator. Runs parse_string_operator rule
...@@ -50,8 +55,27 @@ boost::shared_ptr<Operator<StrSet> > Parser::parseStringOperator( ...@@ -50,8 +55,27 @@ boost::shared_ptr<Operator<StrSet> > Parser::parseStringOperator(
{ {
ANTLRLexer lexer(istr); ANTLRLexer lexer(istr);
ANTLRParser parser(lexer); 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,8 +90,13 @@ boost::shared_ptr<Operator<Bool> > Parser::parseBoolOperator( ...@@ -66,8 +90,13 @@ boost::shared_ptr<Operator<Bool> > Parser::parseBoolOperator(
std::stringstream ss (std::stringstream::in | std::stringstream::out); std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str; ss << str;
try {
return this->parseBoolOperator(ss); return this->parseBoolOperator(ss);
} }
catch (ParserException&) {
throw;
}
}
/** /**
* @desc Parse a predicate. Runs parse_predicates rule in the parser grammar. * @desc Parse a predicate. Runs parse_predicates rule in the parser grammar.
...@@ -79,8 +108,27 @@ boost::shared_ptr<Operator<Bool> > Parser::parseBoolOperator( ...@@ -79,8 +108,27 @@ boost::shared_ptr<Operator<Bool> > Parser::parseBoolOperator(
{ {
ANTLRLexer lexer(istr); ANTLRLexer lexer(istr);
ANTLRParser parser(lexer); 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,8 +144,13 @@ boost::shared_ptr<Operator<TSet> > Parser::parseSymSetOperator( ...@@ -96,8 +144,13 @@ boost::shared_ptr<Operator<TSet> > Parser::parseSymSetOperator(
std::stringstream ss (std::stringstream::in | std::stringstream::out); std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str; ss << str;
try {
return this->parseSymSetOperator(ss); return this->parseSymSetOperator(ss);
} }
catch (ParserException&) {
throw;
}
}
/** /**
* @desc Parse a sym set operator. Runs parse_sym_set_operator rule * @desc Parse a sym set operator. Runs parse_sym_set_operator rule
...@@ -110,7 +163,27 @@ boost::shared_ptr<Operator<TSet> > Parser::parseSymSetOperator( ...@@ -110,7 +163,27 @@ boost::shared_ptr<Operator<TSet> > Parser::parseSymSetOperator(
{ {
ANTLRLexer lexer(istr); ANTLRLexer lexer(istr);
ANTLRParser parser(lexer); 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,8 +199,13 @@ boost::shared_ptr<Operator<Position> > Parser::parsePositionOperator( ...@@ -126,8 +199,13 @@ boost::shared_ptr<Operator<Position> > Parser::parsePositionOperator(
std::stringstream ss (std::stringstream::in | std::stringstream::out); std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str; ss << str;
try {
return this->parsePositionOperator(ss); return this->parsePositionOperator(ss);
} }
catch (ParserException&) {
throw;
}
}
/** /**
* @desc Parse a position operator. Runs parse_sym_set_operator rule * @desc Parse a position operator. Runs parse_sym_set_operator rule
...@@ -140,7 +218,27 @@ boost::shared_ptr<Operator<Position> > Parser::parsePositionOperator( ...@@ -140,7 +218,27 @@ boost::shared_ptr<Operator<Position> > Parser::parsePositionOperator(
{ {
ANTLRLexer lexer(istr); ANTLRLexer lexer(istr);
ANTLRParser parser(lexer); 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,8 +402,13 @@ boost::shared_ptr<RuleSequence> Parser::parseRuleSequence( ...@@ -304,8 +402,13 @@ boost::shared_ptr<RuleSequence> Parser::parseRuleSequence(
std::stringstream ss (std::stringstream::in | std::stringstream::out); std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str; ss << str;
try {
return this->parseRuleSequence(ss); return this->parseRuleSequence(ss);
} }
catch (ParserException&) {
throw;
}
}
/** /**
* @desc Parse a sequence rules. Runs parse_rule_sequence rule in the parser * @desc Parse a sequence rules. Runs parse_rule_sequence rule in the parser
...@@ -318,7 +421,27 @@ boost::shared_ptr<RuleSequence> Parser::parseRuleSequence( ...@@ -318,7 +421,27 @@ boost::shared_ptr<RuleSequence> Parser::parseRuleSequence(
{ {
ANTLRLexer lexer(istr); ANTLRLexer lexer(istr);
ANTLRParser parser(lexer); 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,8 +458,13 @@ boost::shared_ptr<Rule> Parser::parseSingleRule( ...@@ -335,8 +458,13 @@ boost::shared_ptr<Rule> Parser::parseSingleRule(
std::stringstream ss (std::stringstream::in | std::stringstream::out); std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str; ss << str;
try {
return this->parseSingleRule(ss); return this->parseSingleRule(ss);
} }
catch (ParserException&) {
throw;
}
}
/** /**
* @desc Parse a single rule. Runs parse_single_rule rule in the parser * @desc Parse a single rule. Runs parse_single_rule rule in the parser
...@@ -349,7 +477,27 @@ boost::shared_ptr<Rule> Parser::parseSingleRule( ...@@ -349,7 +477,27 @@ boost::shared_ptr<Rule> Parser::parseSingleRule(
{ {
ANTLRLexer lexer(istr); ANTLRLexer lexer(istr);
ANTLRParser parser(lexer); 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;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
......
...@@ -9,6 +9,7 @@ class ParserException : public Wccl::WcclError ...@@ -9,6 +9,7 @@ class ParserException : public Wccl::WcclError
{ {
public: public:
ParserException(const std::string); ParserException(const std::string);
~ParserException() throw() { ~ParserException() throw() {
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment