Skip to main content

A package to implement spreadsheet-style functions in a safe way

Project description

stift

An awesome module for executing "safe" functions from strings.

Parser Module

Parse a string with functions, strings, variables, and arrays. This allows an executor to construct the response of the string execution.

A tool to use these arguments should start at the end of the returned array (lowest level) and work upwards. Anything of type "str", "int", or "float" can be used as-is. Anything with type ParseTypes.array, ParseTypes.function, or ParseTypes.variable need to be processed.

:param s: String to be parsed
:type s: str
:raises ParserError: Issue with parsing somewhere along the line
:return: Returns a nested list of "Token" dictionaries. These always include a value and a type.
For functions, there will also be an argc and argv element (see example)
For arrays, there will also be an index element (See example)
{
    type: ParseTypes.function, # Type can be str, int, float, or a ParseTypes element
    value: "ceiling" # Variable value or function/array name
    argc: 2, # (Functions only) number of arguments
    argv: [(1,2), (1,3)], # (Functions only) pointer to arg locations e.g. parsed[1][2]
}

:rtype: List[List[dict]]

Parser Example

from stift.parser import Parser, ParserError, ParseTypes

s = r"""blend(banana, kiwi(1,2,"\"yes\" or \"no\"", mango[0]))"""
parsed = Parser().parse(s)

# Returns the following:
# [
#     [
#         {
#             "type": ParseTypes.function,
#             "value": "b",
#             "argc": 2,
#             "argv": [(1, 0), (1, 1)],
#         }
#     ],
#     [
#         {"type": str, "value": "a"},
#         {"type": ParseTypes.array, "value": "s", "index": (2, 0)},
#     ],
#     [{"type": int, "value": 0}],
# ]

Functions (WIP)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stift-0.3.0.tar.gz (9.5 kB view hashes)

Uploaded Source

Built Distribution

stift-0.3.0-py3-none-any.whl (10.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page