Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __SPYTHONPARSER_HXX__
00021 #define __SPYTHONPARSER_HXX__
00022
00023 #include "Python.h"
00024
00025 #include <string>
00026 #include <vector>
00027
00028 namespace ParaMEDMEM
00029 {
00030 typedef enum
00031 {
00032 EMPTY_TYPE=0,
00033 FLOAT_TYPE=2,
00034 INT_TYPE=3,
00035 FIELDDB_TYPE=4,
00036 FUNC_TYPE=5,
00037 UNKNOWN_TYPE=6,
00038 IDENTITY_TYPE=7
00039 } TypeOfEntity;
00040
00041 class SPythonParser;
00042
00043 class SPythonPredParser
00044 {
00045 public:
00046 SPythonPredParser();
00047 TypeOfEntity getType() const { return _type; }
00048 void assign(const std::string& s, PyObject *glob, PyObject *loc);
00049 std::string getRepr() const;
00050 bool empty() const;
00051 static TypeOfEntity getTypeOfVar(const std::string& var, PyObject *glob, PyObject *loc);
00052 public:
00053 static const char FIELD_TYPE_STR[];
00054 private:
00055 std::string _var;
00056 std::string _method;
00057 TypeOfEntity _type;
00058 };
00059
00063 class SPythonParser
00064 {
00065 public:
00066 SPythonParser();
00067 TypeOfEntity getType() const { return _type; }
00068 bool parseWithoutEqual(const std::string& s, int parLev, PyObject *glob, PyObject *loc, std::vector<SPythonParser>& alreadyParsed);
00069 TypeOfEntity getTypeOfElt(const std::string& elt, PyObject *glob, PyObject *loc, const std::vector<SPythonParser>& alreadyParsed) const;
00070 TypeOfEntity combineType(TypeOfEntity t1, TypeOfEntity t2) const;
00071 std::string getRepr(const std::vector<SPythonParser>& v) const;
00072 std::string replaceByCompacted(const std::string& s, int parLev, int id) const;
00073 std::string substitute(const std::vector<SPythonParser>& v) const;
00074 TypeOfEntity analyzeType(PyObject *glob, PyObject *loc, const std::vector<SPythonParser>& alreadyParsed);
00075 void keepSelectedLevOfPar(const std::string& s, int parLev, PyObject *glob, PyObject *loc);
00076 static std::vector<int> levOfParenthesis(const std::string& s);
00077
00078 static void replaceFromCompacted(std::string& ret,const std::vector<SPythonParser>& v);
00079 static bool isAlreadyControledParenthesis(const std::string& s);
00080 static bool isParenthesisMatching(const std::string& s, std::string& res);
00081 static bool isElementInParenthesisMatching(const std::string& s, std::string& result, bool& isNumber);
00082 public:
00083 static const char NUMBERS[];
00084 private:
00085 TypeOfEntity _type;
00086 SPythonPredParser _pred;
00087 std::string _content;
00088 std::string _content_py;
00089 };
00090
00095 class SPythonParserHL
00096 {
00097 public:
00098 SPythonParserHL(PyObject *glob, PyObject *loc);
00099 bool parse(const std::string& s, std::string& result);
00100 static std::vector<std::string> splitBetweenEqualChar(const std::string &s);
00101 private:
00102 bool parseWithoutEqual(const std::string& s, TypeOfEntity& type, std::string& result);
00103 private:
00104 PyObject *_glob;
00105 PyObject *_loc;
00106 };
00107 }
00108
00109 #endif