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