1 // Copyright (C) 2007-2013 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
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __SPYTHONPARSER_HXX__
22 #define __SPYTHONPARSER_HXX__
24 // rnv: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined
25 #ifdef _POSIX_C_SOURCE
26 #undef _POSIX_C_SOURCE
35 #include "MedCalculatorSPythonDefines.hxx"
55 class MEDCALCULATORSPYTHON_EXPORT SPythonPredParser
59 TypeOfEntity getType() const { return _type; }
60 void assign(const std::string& s, PyObject *glob, PyObject *loc);
61 std::string getRepr() const;
63 static TypeOfEntity getTypeOfVar(const std::string& var, PyObject *glob, PyObject *loc);
65 static const char FIELD_TYPE_STR[];
73 * This class works on strings previously stripped.
75 class MEDCALCULATORSPYTHON_EXPORT SPythonParser
79 TypeOfEntity getType() const { return _type; }
80 bool parseWithoutEqual(const std::string& s, int parLev, PyObject *glob, PyObject *loc, std::vector<SPythonParser>& alreadyParsed);
81 TypeOfEntity getTypeOfElt(const std::string& elt, PyObject *glob, PyObject *loc, const std::vector<SPythonParser>& alreadyParsed) const;
82 TypeOfEntity combineType(TypeOfEntity t1, TypeOfEntity t2) const;
83 std::string getRepr(const std::vector<SPythonParser>& v) const;
84 std::string replaceByCompacted(const std::string& s, int parLev, int id) const;
85 std::string substitute(const std::vector<SPythonParser>& v) const;
86 TypeOfEntity analyzeType(PyObject *glob, PyObject *loc, const std::vector<SPythonParser>& alreadyParsed);
87 void keepSelectedLevOfPar(const std::string& s, int parLev, PyObject *glob, PyObject *loc);
88 static std::vector<int> levOfParenthesis(const std::string& s);
90 static void replaceFromCompacted(std::string& ret,const std::vector<SPythonParser>& v);
91 static bool isAlreadyControledParenthesis(const std::string& s);
92 static bool isParenthesisMatching(const std::string& s, std::string& res);
93 static bool isElementInParenthesisMatching(const std::string& s, std::string& result, bool& isNumber);
95 static const char NUMBERS[];
98 SPythonPredParser _pred;
100 std::string _content_py;
104 * The main aim of this class is to deal with operator = between spython parts and aggregate it.
105 * HL means HL because parse method dispatch the core operation on SPythonParse class.
107 class MEDCALCULATORSPYTHON_EXPORT SPythonParserHL
110 SPythonParserHL(PyObject *glob, PyObject *loc);
111 bool parse(const std::string& s, std::string& result);
112 static std::vector<std::string> splitBetweenEqualChar(const std::string &s);
114 bool parseWithoutEqual(const std::string& s, TypeOfEntity& type, std::string& result);