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 __SPYTHONINTERPRETER_HXX__
21 #define __SPYTHONINTERPRETER_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"
42 class MEDCALCULATORSPYTHON_EXPORT SPythonInterpreter
45 SPythonInterpreter(PyObject *globals, PyObject *locals);
47 bool run(const char *str, bool& isSPython);
50 bool checkIndentCoherency(const std::string& s, std::size_t p);
51 void checkPythonInterp(PyObject *r);
52 bool isIndenter(const std::string& s, std::size_t p);
53 bool isSPythonExpression(const std::string& s);
54 bool isSPythonExpressionLev1(const std::string& s, std::string& result);
56 static std::string strip(const std::string& s);
57 static bool isSpythonManipulationNeeded(const std::string& s, std::string& pythonLines);
58 static bool isCandidateParenthesis(const std::string& s, std::size_t p1, std::size_t& n);
60 static const int NB_OF_INDENT=7;
61 static const char *INDENT_TOKEN[];
62 static const char NUMBERS[];
65 std::set<int> _indent_pos;
66 bool _indent_must_change;