00001 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D 00002 // 00003 // This library is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public 00005 // License as published by the Free Software Foundation; either 00006 // version 2.1 of the License. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // Lesser General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU Lesser General Public 00014 // License along with this library; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 // 00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00018 // 00019 00020 #ifndef __SPYTHONINTERPRETER_HXX__ 00021 #define __SPYTHONINTERPRETER_HXX__ 00022 00023 #include <Python.h> 00024 00025 #include <string> 00026 #include <vector> 00027 #include <set> 00028 00029 namespace ParaMEDMEM 00030 { 00031 class SPythonInterpreter 00032 { 00033 public: 00034 SPythonInterpreter(PyObject *globals, PyObject *locals); 00035 void initialize(); 00036 bool run(const char *str, bool& isSPython); 00037 bool finishSession(); 00038 private: 00039 bool checkIndentCoherency(const std::string& s, std::size_t p); 00040 void checkPythonInterp(PyObject *r); 00041 bool isIndenter(const std::string& s, std::size_t p); 00042 bool isSPythonExpression(const std::string& s); 00043 bool isSPythonExpressionLev1(const std::string& s, std::string& result); 00044 public: 00045 static std::string strip(const std::string& s); 00046 static bool isSpythonManipulationNeeded(const std::string& s, std::string& pythonLines); 00047 static bool isCandidateParenthesis(const std::string& s, std::size_t p1, std::size_t& n); 00048 public: 00049 static const int NB_OF_INDENT=7; 00050 static const char *INDENT_TOKEN[]; 00051 static const char NUMBERS[]; 00052 private: 00053 std::string _cmd; 00054 std::set<int> _indent_pos; 00055 bool _indent_must_change; 00056 PyObject *_glob; 00057 PyObject *_loc; 00058 }; 00059 } 00060 00061 #endif