Skip to content
Snippets Groups Projects
Select Git revision
  • 81a2b5a8e88c38fb10251d8923310c88b74d5884
  • master default protected
  • fix-words-ann
  • wccl-rules-migration
  • develop
5 results

Parser.cpp

Blame
  • Parser.cpp 3.07 KiB
    #include <libwccl/parser/Parser.h>
    
    /**
     * @desc Parser constructor. Default tagset is NULL
     */
    Parser::Parser(const Corpus2::Tagset& t) : tagset(t)
    {
    }
    
    /**
     *
     */
    Parser::~Parser()
    {
    	//
    }
    
    // ----------------------------------------------------------------------------
    /**
     * @desc Parse string operator writed in std::string. Converts writed operator
     *       to istream and calling parseStringOperator with istream
     * @arg str writed operator
     * @retrun boost::shared_ptr<Wccl::StrSet>
     */
    boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> > Parser::parseStringOperator(
    		const std::string& str) const
    {
    	std::stringstream ss (std::stringstream::in | std::stringstream::out);
    	ss << str;
    
    	return this->parseStringOperator(ss);
    }
    
    /**
     * @desc Parse string operator. Runs parse_string_operator rule
     *       in the parser grammar.
     * @arg istr input stream with writed operator
     * @return boost::shared_ptr<Wccl::Function<Wccl::StrSet> > to created operator
     */
    boost::shared_ptr<ANTLRParserResult<Wccl::StrSet> > Parser::parseStringOperator(
    		std::istream& istr) const
    {
    	ANTLRLexer lexer(istr);
    	ANTLRParser parser(lexer);
    
    	return parser.parse_string_operator();
    }
    
    // ----------------------------------------------------------------------------
    /**
     * @desc Parse predicates writed in std::string. Converts writed predicates
     *       to istream and calling parsePredicate with istream
     * @arg str writed predicate(s)
     * @return boost::shared_ptr<Wccl::Function<Wccl::Bool> > to created predicate
     */
    boost::shared_ptr<ANTLRParserResult<Wccl::Bool> > Parser::parsePredicate(
    		const std::string& str) const
    {
    	std::stringstream ss (std::stringstream::in | std::stringstream::out);
    	ss << str;
    
    	return this->parsePredicate(ss);
    }
    
    /**
     * @desc Parse predicate. Runs parse_predicates rule in the parser grammar.
     * @arg istr input stream with writed predicate
     * @return boost::shared_ptr<Wccl::Function<Wccl::Bool> > to created predicate
     */
    boost::shared_ptr<ANTLRParserResult<Wccl::Bool> > Parser::parsePredicate(
    		std::istream& istr) const
    {
    	ANTLRLexer lexer(istr);
    	ANTLRParser parser(lexer);
    
    	return parser.parse_predicates();
    }
    
    // ----------------------------------------------------------------------------
    /**
     * @desc Parse sym set operator writed in std::string. Converts writed operator
     *       to istream and calling parseSymSetOperator with istream
     * @arg str writed operator
     * @retrun boost::shared_ptr<Wccl::Function<Wccl::TSet> >
     */
    boost::shared_ptr<ANTLRParserResult<Wccl::TSet> > Parser::parseSymSetOperator(
    		const std::string& str) const
    {
    	std::stringstream ss (std::stringstream::in | std::stringstream::out);
    	ss << str;
    
    	return this->parseSymSetOperator(ss);
    }
    
    /**
     * @desc Parse sym set operator. Runs parse_sym_set_operator rule
     *       in the parser grammar.
     * @arg istr input stream with writed operator
     * @return boost::shared_ptr<Wccl::Function<Wccl::TSet> > to created operator
     */
    boost::shared_ptr<ANTLRParserResult<Wccl::TSet> > Parser::parseSymSetOperator(
    		std::istream& istr) const
    {
    	ANTLRLexer lexer(istr);
    	ANTLRParser parser(lexer);
    
    	return parser.parse_sym_set_operator();
    }