1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __SPYTHONPARSER_HXX__
21 #define __SPYTHONPARSER_HXX__
23 // rnv: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined
24 #ifdef _POSIX_C_SOURCE
25 #undef _POSIX_C_SOURCE
34 #include "MedCalculatorSPythonDefines.hxx"
54 class MEDCALCULATORSPYTHON_EXPORT SPythonPredParser
58 TypeOfEntity getType() const { return _type; }
59 void assign(const std::string& s, PyObject *glob, PyObject *loc);
60 std::string getRepr() const;
62 static TypeOfEntity getTypeOfVar(const std::string& var, PyObject *glob, PyObject *loc);
64 static const char FIELD_TYPE_STR[];
72 * This class works on strings previously stripped.
74 class MEDCALCULATORSPYTHON_EXPORT SPythonParser
78 TypeOfEntity getType() const { return _type; }
79 bool parseWithoutEqual(const std::string& s, int parLev, PyObject *glob, PyObject *loc, std::vector<SPythonParser>& alreadyParsed);
80 TypeOfEntity getTypeOfElt(const std::string& elt, PyObject *glob, PyObject *loc, const std::vector<SPythonParser>& alreadyParsed) const;
81 TypeOfEntity combineType(TypeOfEntity t1, TypeOfEntity t2) const;
82 std::string getRepr(const std::vector<SPythonParser>& v) const;
83 std::string replaceByCompacted(const std::string& s, int parLev, int id) const;
84 std::string substitute(const std::vector<SPythonParser>& v) const;
85 TypeOfEntity analyzeType(PyObject *glob, PyObject *loc, const std::vector<SPythonParser>& alreadyParsed);
86 void keepSelectedLevOfPar(const std::string& s, int parLev, PyObject *glob, PyObject *loc);
87 static std::vector<int> levOfParenthesis(const std::string& s);
89 static void replaceFromCompacted(std::string& ret,const std::vector<SPythonParser>& v);
90 static bool isAlreadyControledParenthesis(const std::string& s);
91 static bool isParenthesisMatching(const std::string& s, std::string& res);
92 static bool isElementInParenthesisMatching(const std::string& s, std::string& result, bool& isNumber);
94 static const char NUMBERS[];
97 SPythonPredParser _pred;
99 std::string _content_py;
103 * The main aim of this class is to deal with operator = between spython parts and aggregate it.
104 * HL means HL because parse method dispatch the core operation on SPythonParse class.
106 class MEDCALCULATORSPYTHON_EXPORT SPythonParserHL
109 SPythonParserHL(PyObject *glob, PyObject *loc);
110 bool parse(const std::string& s, std::string& result);
111 static std::vector<std::string> splitBetweenEqualChar(const std::string &s);
113 bool parseWithoutEqual(const std::string& s, TypeOfEntity& type, std::string& result);