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

Added parseMatchRule to the user Parser. parseMatchRule returns parsed expression.

parent 791e1938
Branches
No related merge requests found
......@@ -502,4 +502,56 @@ boost::shared_ptr<TagRule> Parser::parseSingleRule(
// ----------------------------------------------------------------------------
/**
* @desc Parse single match rule contained in a std::string. Converts the string
* to a stream and calls parseMatchRule with it
* @arg istr input stream with writed rule
* @return the parsed rule via a shared pointer
*/
boost::shared_ptr<Expression> Parser::parseMatchRule(
const std::string& str) const
{
std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str;
try {
return this->parseMatchRule(ss);
}
catch (ParserException&) {
throw;
}
}
/**
* @desc Parse match rule. Runs parse_match_rule rule from the parser grammar.
* @arg istr input stream with writed rule
* @return the parsed rule via a shared pointer
*/
boost::shared_ptr<Expression> Parser::parseMatchRule(std::istream& istr) const
{
ANTLRLexer lexer(istr);
ANTLRParser parser(lexer);
boost::shared_ptr<Expression> res;
try {
res = parser.parse_match_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;
}
} // end Wccl ns
......@@ -17,6 +17,9 @@
// rules
#include <libwccl/ops/rulesequence.h>
// match actions
#include <libwccl/ops/match/applyoperator.h>
// exceptions
#include <libwccl/parser/ParserException.h>
......@@ -78,6 +81,13 @@ public:
boost::shared_ptr<TagRule>
parseSingleRule(std::istream&) const;
// ---------------------------------------------------------------------------
// Parsing match rule from input string
boost::shared_ptr<Expression>
parseMatchRule(const std::string&) const;
boost::shared_ptr<Expression>
parseMatchRule(std::istream&) const;
// ---------------------------------------------------------------------------
const Corpus2::Tagset& tagset() const {
return tagset_;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment