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

add parseWcclFile to Parser

parent c6faccc0
Branches
No related tags found
No related merge requests found
......@@ -554,4 +554,58 @@ boost::shared_ptr<MatchRule> Parser::parseMatchRule(std::istream& istr) const
return res;
}
// ----------------------------------------------------------------------------
/**
* @desc Parse an entire WCCL file contained in a std::string.
* Converts the string to a stream and calls parseWcclFile with it
* @arg istr input stream with writed rule
* @return the parsed file via a shared pointer
*/
boost::shared_ptr<WcclFile> Parser::parseWcclFile(
const std::string& str) const
{
std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str;
try {
return this->parseWcclFile(ss);
}
catch (ParserException&) {
throw;
}
}
/**
* @desc Parse an entire WCCL file. Runs parse_wccl_file rule from the parser grammar.
* @arg istr input stream with writed rule
* @return the parsed file via a shared pointer
*/
boost::shared_ptr<WcclFile> Parser::parseWcclFile(std::istream& istr) const
{
ANTLRLexer lexer(istr);
ANTLRParser parser(lexer);
boost::shared_ptr<WcclFile> res;
try {
res = parser.parse_wccl_file(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
......@@ -20,6 +20,9 @@
// match actions
#include <libwccl/ops/matchrule.h>
// match actions
#include <libwccl/wcclfile.h>
// exceptions
#include <libwccl/parser/ParserException.h>
......@@ -88,6 +91,13 @@ public:
boost::shared_ptr<MatchRule>
parseMatchRule(std::istream& is) const;
// ---------------------------------------------------------------------------
// WCCL file parsing
boost::shared_ptr<WcclFile>
parseWcclFile(const std::string& file_contents_string) const;
boost::shared_ptr<WcclFile>
parseWcclFile(std::istream& is) const;
// ---------------------------------------------------------------------------
const Corpus2::Tagset& tagset() const {
return tagset_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment