Select Git revision
GUI_Extras.cpp
Forked from
gmsh / gmsh
Source project has a limited visibility.
OnelabParser.cpp 43.16 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 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 enclosed(const std::string &in, std::vector<std::string> &arguments,
int &end){
// syntax: (arguments[Ø], arguments[1], ... , arguments[n])
// arguments[i] may contain parenthesis
int pos, cursor;
arguments.resize(0);
cursor=0;
if ( (pos=in.find("(",cursor)) == std::string::npos )
OLMsg::Fatal("Syntax error: <%s>",in.c_str());
if (pos>0){
std::cout << pos << in << std::endl;
OLMsg::Fatal("Syntax error: <%s>",in.c_str());
}
unsigned int count=1;
pos++; // skips '('
cursor = pos;
do{
if(in[pos]=='(') count++;
else if(in[pos]==')') count--;
else if(in[pos]==',' && (count==1)) {
arguments.push_back(removeBlanks(in.substr(cursor,pos-cursor)));
if(count!=1)
OLMsg::Fatal("Syntax error: mismatched parenthesis <%s>",in.c_str());
cursor=pos+1; // skips ','
}
else if(in[pos]==';')
OLMsg::Fatal("Syntax error: unterminated sentence <%s>",in.c_str());
pos++;
} while( count && (pos!=std::string::npos) );
// count is 0 when the closing brace is found.
if(count)
OLMsg::Fatal("Syntax error: <%s>",in.c_str());
else
arguments.push_back(removeBlanks(in.substr(cursor,pos-1-cursor)));
end=pos;
return arguments.size();
}
int extractLogic(const std::string &in, std::vector<std::string> &arguments){
// syntax: ( argument[0], argument[1]\in{<,>,<=,>=,==,!=}, arguments[2])
int pos, cursor;
arguments.resize(0);