1 // Copyright (C) 2006-2019 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, or (at your option) any later version.
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
23 # if defined py2yacslib_EXPORTS
24 # define PY2YACSLIB_EXPORT __declspec( dllexport )
26 # define PY2YACSLIB_EXPORT __declspec( dllimport )
29 # define PY2YACSLIB_EXPORT
37 class PY2YACSLIB_EXPORT Py2yacsException: std::exception
40 Py2yacsException(const std::string& what);
41 virtual ~Py2yacsException()throw ();
42 virtual const char *what() const throw ();
55 struct PY2YACSLIB_EXPORT FunctionProperties
59 std::list<std::string> _input_ports;
60 std::list<std::string> _output_ports;
61 std::list<std::string> _errors;
62 std::list<std::string> _imports;
65 /*! \brief Converter of a python script to a yacs schema.
66 * This class converts a string containing a python script to a yacs schema
67 * containing a python script node.
69 class PY2YACSLIB_EXPORT Py2yacs
75 * This constructor can be used if you want to define your own python parser.
76 * The parser function should be a python function and return a tuple of
78 * The first list contains the properties of all the functions in the script
79 * and the second one contains global errors.
80 * \param python_parser_module: name of the parser module
81 * \param python_parser_function: name of the parser function
83 Py2yacs(const std::string& python_parser_module,
84 const std::string& python_parser_function);
87 * \param python_code: contains the python code that will be converted
90 void load(const std::string& python_code);
93 * \param file_path: path to the xml file where to save the yacs schema.
94 * \param python_function: function defined in the python code that will be
95 * called in the yacs node.
97 void save(const std::string& file_path,
98 const std::string& python_function)const;
101 * A new schema is created.
102 * \param python_function: function defined in the python code that will be
103 * called in the yacs node.
105 YACS::ENGINE::Proc* createProc(const std::string& python_function)const;
108 * Syntax errors when parsing python and py2yacs global errors.
109 * \return a list of errors.
111 const std::list<std::string>& getGlobalErrors() const;
113 const std::list<FunctionProperties>& getFunctionProperties()const;
116 * Get a string containing global errors and errors specific to py2yacs for
117 * every function in python script.
118 * An empty string means there is no error.
120 std::string getAllErrors()const;
123 * Same as getAllErrors but only for one function.
124 * py2yacs errors for other functions are ignored.
125 * If the function name is not found, you get an error message in the
128 std::string getFunctionErrors(const std::string& functionName)const;
131 std::string _python_parser_module;
132 std::string _python_parser_function;
133 std::list<FunctionProperties> _functions;
134 std::list<std::string> _global_errors;
135 std::string _python_code;