diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index fe0be08d02b96226596f7a413a6aa8efdbd2d58b..1bfc88929be3b07cd77afb1050dfcde626277ff7 100644 --- a/libwccl/parser/Parser.cpp +++ b/libwccl/parser/Parser.cpp @@ -323,4 +323,35 @@ boost::shared_ptr<RuleSequence> Parser::parseRuleSequence( // ---------------------------------------------------------------------------- +/** + * @desc Parse single rule contained in a std::string. Converts the string + * to a stream and calls parseSingleRule with it + * @arg str rule + * @return the parsed rule via a shared pointer + */ +boost::shared_ptr<Rule> Parser::parseSingleRule( + const std::string& str) const +{ + std::stringstream ss (std::stringstream::in | std::stringstream::out); + ss << str; + + return this->parseSingleRule(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<Rule> Parser::parseSingleRule( + std::istream& istr) const +{ + ANTLRLexer lexer(istr); + ANTLRParser parser(lexer); + return parser.parse_single_rule(tagset_); +} + +// ---------------------------------------------------------------------------- + } // end Wccl ns diff --git a/libwccl/parser/Parser.h b/libwccl/parser/Parser.h index 7845a7da983a63de2d6a51506fbe126ed39d931c..9f6e3f6bfb6d3d12929a8d60cec8dcde5eedc4d9 100644 --- a/libwccl/parser/Parser.h +++ b/libwccl/parser/Parser.h @@ -71,6 +71,13 @@ public: boost::shared_ptr<RuleSequence> parseRuleSequence(std::istream&) const; + // --------------------------------------------------------------------------- + // Parsing single rule from input string + boost::shared_ptr<Rule> + parseSingleRule(const std::string&) const; + boost::shared_ptr<Rule> + parseSingleRule(std::istream&) const; + // --------------------------------------------------------------------------- const Corpus2::Tagset& tagset() const { return tagset_;