211 lines
6.9 KiB
C
211 lines
6.9 KiB
C
/*
|
|
* Copyright (C) 2023 Weber Yann
|
|
*
|
|
* This file is part of pyrpn.
|
|
*
|
|
* pyrpn is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* any later version.
|
|
*
|
|
* pyrpn is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef _PYTHON_RPNTOKEN_H__
|
|
#define _PYTHON_RPNTOKEN_H__
|
|
|
|
#include "config.h"
|
|
#include "rpn_parse.h"
|
|
|
|
#define PY_SSIZE_T_CLEAN
|
|
#include <Python.h>
|
|
#include "structmember.h"
|
|
|
|
/**@file python_rpntoken.h
|
|
* @brief Python RPNToken type headers
|
|
* @ingroup python_ext
|
|
* @ingroup pymod_pyrpn_token
|
|
*
|
|
* This file is the header of the RPNToken classes and subclasses
|
|
*
|
|
*/
|
|
|
|
/**@defgroup pymod_pyrpn_token module pyrpn.token
|
|
* @brief Python module representing RPNExpr tokens
|
|
* @ingroup pymod_pyrpn
|
|
*/
|
|
/**@brief pyrpn.token module */
|
|
extern PyModuleDef rpntokens_module;
|
|
|
|
/**@defgroup pymod_pyrpn_token_Token pyrpn.token.Token
|
|
* @brief Abstract class representing an @ref pymod_pyrpn_RPNExpr token
|
|
* @ingroup pymod_pyrpn_token */
|
|
/**@brief pyrpn.token.Token generic type
|
|
* @ingroup pymod_pyrpn_token_Token */
|
|
extern PyTypeObject RPNTokenType;
|
|
|
|
/**@defgroup pymod_pyrpn_token_TokenOp pyrpn.token.TokenOp
|
|
* @brief Python class representing an @ref pymod_pyrpn_RPNExpr operation token
|
|
*
|
|
* Extends @ref pymod_pyrpn_token_Token
|
|
* @ingroup pymod_pyrpn_token */
|
|
/**@brief pyrpn.token.TokenOp type
|
|
* @ingroup pymod_pyrpn_token_TokenOp */
|
|
extern PyTypeObject RPNTokenOpType;
|
|
|
|
/**@defgroup pymod_pyrpn_token_TokenVal pyrpn.token.TokenVal
|
|
* @brief Python class representing an @ref pymod_pyrpn_RPNExpr value token
|
|
*
|
|
* Extends @ref pymod_pyrpn_token_Token
|
|
* @ingroup pymod_pyrpn_token */
|
|
/**@brief pyrpn.token.TokenVal type
|
|
* @ingroup pymod_pyrpn_token_TokenVal */
|
|
extern PyTypeObject RPNTokenValType;
|
|
|
|
/**@defgroup pymod_pyrpn_token_TokenArg pyrpn.token.TokenArg
|
|
* @brief Python class representing an @ref pymod_pyrpn_RPNExpr argument token
|
|
*
|
|
* Extends @ref pymod_pyrpn_token_Token
|
|
* @ingroup pymod_pyrpn_token */
|
|
/**@brief pyrpn.token.TokenArg type
|
|
* @ingroup pymod_pyrpn_token_TokenArg */
|
|
extern PyTypeObject RPNTokenArgType;
|
|
|
|
|
|
/**@brief C representation of @ref RPNTokenType generic class
|
|
* @ingroup pymod_pyrpn_token_Token */
|
|
typedef struct
|
|
{
|
|
/** Python's type definition */
|
|
PyObject_HEAD;
|
|
/** @brief The token value (will be set by subtypes) */
|
|
rpn_token_t value;
|
|
} RPNToken_t;
|
|
|
|
/**@brief C representation of all @ref RPNTokenType subclasses
|
|
* @ingroup pymod_pyrpn_token_tokenOp
|
|
* @ingroup pymod_pyrpn_token_tokenVal
|
|
* @ingroup pymod_pyrpn_token_tokenArg
|
|
*/
|
|
typedef struct {
|
|
/** @brief Pointer on super type */
|
|
RPNToken_t super;
|
|
} RPNTokenSubClass_t;
|
|
|
|
/**@brief C representation of @ref RPNTokenOpType
|
|
* @ingroup pymod_pyrpn_token_TokenOp */
|
|
typedef RPNTokenSubClass_t RPNTokenOp_t;
|
|
/**@brief C representation of @ref RPNTokenValType
|
|
* @ingroup pymod_pyrpn_token_TokenVal */
|
|
typedef RPNTokenSubClass_t RPNTokenVal_t;
|
|
/**@brief C representation of @ref RPNTokenArgType
|
|
* @ingroup pymod_pyrpn_token_TokenArg */
|
|
typedef RPNTokenSubClass_t RPNTokenArg_t;
|
|
|
|
|
|
/**@brief Module initialisation function
|
|
* @return initialized module
|
|
* @ingroup pymod_pyrpn_token */
|
|
PyObject* rpntokens_module_init(void);
|
|
|
|
/**@brief Class method returning a token instance from a string representation
|
|
* @param cls @ref RPNTokenType class or any subclass
|
|
* @param arg A str representing a token
|
|
* @return A new @ref RPNTokenType subclass instance or NULL on error
|
|
* @ingroup pymod_pyrpn_token_Token
|
|
*/
|
|
PyObject* rpntoken_from_str(PyObject *cls, PyObject *arg);
|
|
|
|
/**@brief Instanciate a new RPNToken subclass given a C token
|
|
* @param token An expression token
|
|
* @return A new @ref RPNTokenType subclass instance
|
|
* @ingroup pymod_pyrpn_token_Token
|
|
*/
|
|
PyObject* rpntoken_from_token(const rpn_token_t *token);
|
|
|
|
|
|
/**@brief @ref RPNTokenType __init__ method
|
|
* @param _self @ref RPNTokenType subclass instance
|
|
* @param args Positional arguments
|
|
* @param kwds Keyword arguments
|
|
* @return 0 or -1 on error
|
|
* @ingroup pymod_pyrpn_token_Token
|
|
*/
|
|
int rpntoken_init(PyObject *_self, PyObject *args, PyObject *kwds);
|
|
|
|
/**@brief PEP-207 comparison method
|
|
* @param _self An @ref RPNTokenType subclass instance
|
|
* @param other The @ref RPNTokenType subclass instance to compare to
|
|
* @param op The comparison
|
|
* @return Py_True or Py_False
|
|
* @ingroup pymod_pyrpn_token_Token
|
|
*/
|
|
PyObject* rpntoken_richcompare(PyObject *_self, PyObject *other, int op);
|
|
|
|
/**@brief __str__ method
|
|
* @param _self An @ref RPNTokenType subclass instance
|
|
* @return A str representing the token
|
|
* @ingroup pymod_pyrpn_token_Token */
|
|
PyObject* rpntoken_str(PyObject *_self);
|
|
|
|
/**@brief __repr__ method
|
|
* @param _self An @ref RPNTokenType subclass instance
|
|
* @return A str representing the token
|
|
* @ingroup pymod_pyrpn_token_Token */
|
|
PyObject* rpntoken_repr(PyObject *_self);
|
|
|
|
|
|
|
|
|
|
|
|
/**@brief @ref RPNTokenOpType __init__ method
|
|
* @param _self RPNTokenOpType being initialized
|
|
* @param args Positional arguments
|
|
* @param kwds Keyword arguments
|
|
* @return 0 or -1 on error
|
|
* @ingroup pymod_pyrpn_token_TokenOp */
|
|
int rpntokenop_init(PyObject *_self, PyObject *args, PyObject *kwds);
|
|
|
|
/**@brief @ref RPNTokenOpType opcode_max method
|
|
* @param Py_UNUSED unused argument for static method
|
|
* @return The maximum valid opcode
|
|
* @ingroup pymod_pyrpn_token_TokenOp */
|
|
PyObject *rpntokenop_opcode_max(PyObject *Py_UNUSED(_static));
|
|
|
|
/**@brief @ref RPNTokenOpType chr method
|
|
* @param _self @ref RPNTokenOpType instance
|
|
* @param Py_UNUSED unused argument
|
|
* @return A string with a single chr representing the operation
|
|
* @ingroup pymod_pyrpn_token_TokenOp */
|
|
PyObject *rpntokenop_opchr(PyObject *_self, PyObject* Py_UNUSED(_null));
|
|
|
|
/**@brief @ref RPNTokenOpType str method
|
|
* @param _self @ref RPNTokenOpType instance
|
|
* @param Py_UNUSED unused argument
|
|
* @return A string representing the operation on multiple chr
|
|
* @ingroup pymod_pyrpn_token_TokenOp */
|
|
PyObject *rpntokenop_opstr(PyObject *_self, PyObject* Py_UNUSED(_null));
|
|
|
|
|
|
/**@brief @ref RPNTokenValType __init__ method
|
|
* @param _self RPNTokenValType being initialized
|
|
* @param args Positional arguments
|
|
* @param kwds Keyword arguments
|
|
* @return 0 or -1 on error
|
|
* @ingroup pymod_pyrpn_token_TokenVal */
|
|
int rpntokenval_init(PyObject *_self, PyObject *args, PyObject *kwds);
|
|
|
|
/**@brief @ref RPNTokenArgType __init__ method
|
|
* @param _self RPNTokenArgType being initialized
|
|
* @param args Positional arguments
|
|
* @param kwds Keyword arguments
|
|
* @return 0 or -1 on error
|
|
* @ingroup pymod_pyrpn_token_TokenArg */
|
|
int rpntokenarg_init(PyObject *_self, PyObject *args, PyObject *kwds);
|
|
|
|
#endif
|