From 31c7ad7887a09c67932c31a06aea62588fed83db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl> Date: Fri, 11 Feb 2011 12:00:11 +0100 Subject: [PATCH] Added user-parser rule for parsing single rule --- libwccl/parser/Parser.cpp | 31 +++++++++++++++++++++++++++++++ libwccl/parser/Parser.h | 7 +++++++ 2 files changed, 38 insertions(+) diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index fe0be08..1bfc889 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 7845a7d..9f6e3f6 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_; -- GitLab