ExpressionParser.cc 1.22 KB
/*
 * ExpressionParser.cc
 *
 *  Created on: 02/2019
 *      Author: akka
 */

#include <sstream>

#include "ParserLogger.hh"
#include "ExpressionParser.hh"
#include "ParserGrammar.hh"
#include "ExpressionPrinter.hh"
#include "Properties.hh"

namespace AMDA {
namespace parser {

bool ExpressionParser::parse(const std::string& str, AMDA::helpers::Properties& lProperties, std::string &kernelExpression, std::vector<std::string>& paramsList) {
	LOG4CXX_INFO(gLogger, "ExpressionParser::parse - Try to parse " << str)

	std::string::const_iterator iter = str.begin(), end = str.end();

	try {
		ParserGrammar<std::string::const_iterator,boost::spirit::qi::space_type> grammar(lProperties);
		Expression::ExpressionContainer expr;

		bool result = boost::spirit::qi::phrase_parse(iter,end,grammar,boost::spirit::qi::space, expr);

		if(!result || iter != end)
		{
			LOG4CXX_ERROR(gLogger, "ExpressionParser::parse - Cannot parse the expression at -> " << std::string(iter, str.end()))

			return false;
		}

        	getExpressionInfo(expr, kernelExpression, paramsList);
	}
	catch(...) {
		LOG4CXX_ERROR(gLogger, "ExpressionParser::parse - An exception occured")
		return false;
	}

	return true;
}
	
} /* namespace parser */
} /* namespace AMDA */