Select Git revision
OnelabParser.cpp
Forked from
gmsh / gmsh
Source project has a limited visibility.
-
Christophe Geuzaine authoredChristophe Geuzaine authored
OnelabParser.cpp 49.85 KiB
#include "OnelabClients.h"
#include <algorithm>
#include "mathex.h"
// reserved keywords for the onelab parser
namespace olkey{
static std::string deflabel("onelab.tags");
static std::string label("OL."), comment("#"), separator(";");
static std::string line(label+"line");
static std::string begin(label+"block");
static std::string end(label+"endblock");
static std::string include(label+"include");
static std::string loader(label+"loaderName");
static std::string message(label+"msg");
static std::string showParam(label+"show");
static std::string showGmsh(label+"merge");
static std::string dump(label+"dump");
static std::string ifcond(label+"if");
static std::string iftrue(label+"iftrue"), ifntrue(label+"ifntrue");
static std::string olelse(label+"else"), olendif(label+"endif");
static std::string getValue(label+"get");
static std::string mathex(label+"eval");
static std::string getRegion(label+"region");
}
int extractLogic(const std::string &in, std::vector<std::string> &arguments){
// syntax: ( argument[0], argument[1]\in{<,>,<=,>=,==,!=}, arguments[2])
size_t pos, cursor;
arguments.resize(0);
cursor=0;
if ( (pos=in.find("(",cursor)) == std::string::npos )
OLMsg::Error("Syntax error: <%s>",in.c_str());
unsigned int count=1;
pos++; // skips '('
cursor=pos;
do{
if(in[pos]=='(') count++;
if(in[pos]==')') count--;
if( (in[pos]=='<') || (in[pos]=='=') || (in[pos]=='>') || (in[pos]=='!') ){
arguments.push_back(removeBlanks(in.substr(cursor,pos-cursor)));
if(count!=1)
OLMsg::Error("Syntax error: <%s>",in.c_str());
cursor=pos;
if(in[pos+1]=='='){
arguments.push_back(in.substr(cursor,2));
pos++;
}
else{
arguments.push_back(in.substr(cursor,1));
}
cursor=pos+1;
}
pos++;
} while( count && (pos!=std::string::npos) );
// count is 0 when the closing brace is found.
if(count)
OLMsg::Error("Syntax error: mismatched parenthesis in <%s>",in.c_str());
else
arguments.push_back(removeBlanks(in.substr(cursor,pos-1-cursor)));
if((arguments.size()!=1) && (arguments.size()!=3))
OLMsg::Error("Syntax error: <%s>",in.c_str());
return arguments.size();
}
// Client member functions defined here because they use parser commands