diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index 41914ca0afdba93638829ab4d25b958f751a5077..fe0be08d02b96226596f7a413a6aa8efdbd2d58b 100644 --- a/libwccl/parser/Parser.cpp +++ b/libwccl/parser/Parser.cpp @@ -292,4 +292,35 @@ boost::shared_ptr<FunctionalOperator> Parser::parseAnyOperator( // ---------------------------------------------------------------------------- +/** + * @desc Parse rule sequence contained in a std::string. Converts the string + * to a stream and calls parseRuleSequence with it + * @arg str rules string + * @return the parsed rule sequence via a shared pointer + */ +boost::shared_ptr<RuleSequence> Parser::parseRuleSequence( + const std::string& str) const +{ + std::stringstream ss (std::stringstream::in | std::stringstream::out); + ss << str; + + return this->parseRuleSequence(ss); +} + +/** + * @desc Parse a sequence rules. Runs parse_rule_sequence rule in the parser + * grammar. + * @arg istr input stream with writed rules + * @return the parsed rule sequence via a shared pointer + */ +boost::shared_ptr<RuleSequence> Parser::parseRuleSequence( + std::istream& istr) const +{ + ANTLRLexer lexer(istr); + ANTLRParser parser(lexer); + return parser.parse_rule_sequence(tagset_); +} + +// ---------------------------------------------------------------------------- + } // end Wccl ns diff --git a/libwccl/parser/Parser.h b/libwccl/parser/Parser.h index b41892986c604addfeeac7dfcd0cfb281dd535d6..7845a7da983a63de2d6a51506fbe126ed39d931c 100644 --- a/libwccl/parser/Parser.h +++ b/libwccl/parser/Parser.h @@ -14,6 +14,9 @@ #include <libwccl/values/strset.h> #include <libwccl/ops/operator.h> +// rules +#include <libwccl/ops/rulesequence.h> + // exceptions #include <libwccl/parser/ParserException.h> @@ -60,8 +63,15 @@ public: parseAnyOperator(const std::string&) const; boost::shared_ptr<FunctionalOperator> parseAnyOperator(std::istream&) const; + // --------------------------------------------------------------------------- + // Parsing rule sequence from input string + boost::shared_ptr<RuleSequence> + parseRuleSequence(const std::string&) const; + boost::shared_ptr<RuleSequence> + parseRuleSequence(std::istream&) const; + // --------------------------------------------------------------------------- const Corpus2::Tagset& tagset() const { return tagset_; }