Blame view

src/expressionParser/ExpressionParser.cc 1.22 KB
e3ca4c3f   Benjamin Renard   adding structure ...
1
2
3
4
5
6
7
/*
 * ExpressionParser.cc
 *
 *  Created on: 02/2019
 *      Author: akka
 */

e3ca4c3f   Benjamin Renard   adding structure ...
8
#include <sstream>
e3ca4c3f   Benjamin Renard   adding structure ...
9

a7f2648e   Benjamin Renard   Parser: First imp...
10
#include "ParserLogger.hh"
e3ca4c3f   Benjamin Renard   adding structure ...
11
#include "ExpressionParser.hh"
a7f2648e   Benjamin Renard   Parser: First imp...
12
13
#include "ParserGrammar.hh"
#include "ExpressionPrinter.hh"
e58d7be4   Benjamin Renard   Parser: Add const...
14
#include "Properties.hh"
e3ca4c3f   Benjamin Renard   adding structure ...
15
16

namespace AMDA {
a7f2648e   Benjamin Renard   Parser: First imp...
17
namespace parser {
e3ca4c3f   Benjamin Renard   adding structure ...
18

aae52524   Benjamin Renard   Parser: Write res...
19
bool ExpressionParser::parse(const std::string& str, AMDA::helpers::Properties& lProperties, std::string &kernelExpression, std::vector<std::string>& paramsList) {
a7f2648e   Benjamin Renard   Parser: First imp...
20
21
22
23
	LOG4CXX_INFO(gLogger, "ExpressionParser::parse - Try to parse " << str)

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

aae52524   Benjamin Renard   Parser: Write res...
24
25
26
	try {
		ParserGrammar<std::string::const_iterator,boost::spirit::qi::space_type> grammar(lProperties);
		Expression::ExpressionContainer expr;
a7f2648e   Benjamin Renard   Parser: First imp...
27

aae52524   Benjamin Renard   Parser: Write res...
28
		bool result = boost::spirit::qi::phrase_parse(iter,end,grammar,boost::spirit::qi::space, expr);
a7f2648e   Benjamin Renard   Parser: First imp...
29

aae52524   Benjamin Renard   Parser: Write res...
30
31
		if(!result || iter != end)
		{
b3f524fc   Benjamin Renard   Fix error location
32
			LOG4CXX_ERROR(gLogger, "ExpressionParser::parse - Cannot parse the expression at -> " << std::string(iter, str.end()))
aae52524   Benjamin Renard   Parser: Write res...
33
34
35
36
37
38
39
40
41

			return false;
		}

        	getExpressionInfo(expr, kernelExpression, paramsList);
	}
	catch(...) {
		LOG4CXX_ERROR(gLogger, "ExpressionParser::parse - An exception occured")
		return false;
a7f2648e   Benjamin Renard   Parser: First imp...
42
	}
e3ca4c3f   Benjamin Renard   adding structure ...
43

aae52524   Benjamin Renard   Parser: Write res...
44
	return true;
e3ca4c3f   Benjamin Renard   adding structure ...
45
}
a7f2648e   Benjamin Renard   Parser: First imp...
46
47
48
	
} /* namespace parser */
} /* namespace AMDA */
e3ca4c3f   Benjamin Renard   adding structure ...