modernize musrfit function handling using spirit x3 instead of spirit classic now.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,12 @@
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
|
||||
#include "PFunctionHandler.h"
|
||||
|
||||
namespace x3 = boost::spirit::x3;
|
||||
|
||||
//-------------------------------------------------------------
|
||||
// Constructor
|
||||
//-------------------------------------------------------------
|
||||
@@ -67,7 +71,6 @@ PFunctionHandler::~PFunctionHandler()
|
||||
Bool_t PFunctionHandler::DoParse()
|
||||
{
|
||||
Bool_t success = true;
|
||||
PFunctionGrammar function;
|
||||
TString line;
|
||||
|
||||
// feed the function block into the parser. Start with i=1, since i=0 is FUNCTIONS
|
||||
@@ -89,14 +92,32 @@ Bool_t PFunctionHandler::DoParse()
|
||||
}
|
||||
line.ToUpper();
|
||||
|
||||
// do parsing
|
||||
tree_parse_info<> info = ast_parse(line.Data(), function, space_p);
|
||||
// do parsing with X3
|
||||
musrfit::ast::assignment assignment;
|
||||
std::string str(line.Data());
|
||||
auto iter = str.begin();
|
||||
auto end = str.end();
|
||||
|
||||
if (info.full) { // parsing successful
|
||||
PFunction func(info); // generate an evaluation function object based on the AST tree
|
||||
fFuncs.push_back(func); // feeds it to the functions vector
|
||||
} else {
|
||||
// Get the X3 grammar
|
||||
auto const& grammar = musrfit::function_grammar();
|
||||
|
||||
try {
|
||||
bool parseSuccess = x3::phrase_parse(iter, end, grammar, x3::space, assignment);
|
||||
|
||||
if (parseSuccess && iter == end) { // parsing successful
|
||||
PFunction func(assignment); // generate an evaluation function object based on the AST
|
||||
fFuncs.push_back(func); // feeds it to the functions vector
|
||||
} else {
|
||||
std::cerr << std::endl << "**ERROR**: FUNCTIONS parse failed in line " << fLines[i].fLineNo << std::endl;
|
||||
if (iter != end) {
|
||||
std::cerr << "**ERROR**: Stopped at: " << std::string(iter, end) << std::endl;
|
||||
}
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
} catch (x3::expectation_failure<std::string::iterator> const& e) {
|
||||
std::cerr << std::endl << "**ERROR**: FUNCTIONS parse failed in line " << fLines[i].fLineNo << std::endl;
|
||||
std::cerr << "**ERROR**: Expected: " << e.which() << std::endl;
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user