Esempio n. 1
0
def parse(timeseries_expression, method=None, functions=None, debug=False):
    '''Function for parsing :ref:`timeseries expressions <dsl-script>`.
If succesful, it returns an instance of :class:`dynts.dsl.Expr` which
can be used to to populate timeseries or scatters once data is available.

Parsing is implemented using the ply_ module,
an implementation of lex and yacc parsing tools for Python.

:parameter expression: A :ref:`timeseries expressions <dsl-script>` string.
:parameter method: Not yet used.
:parameter functions: dictionary of functions to use when parsing.
    If not provided the :data:`dynts.function_registry`
    will be used.

    Default ``None``.
:parameter debug: debug flag for ply_.  Default ``False``.

For examples and usage check the :ref:`dsl documentation <dsl>`.

.. _ply: http://www.dabeaz.com/ply/
'''
    if not parsefunc:
        raise ExpressionError('Could not parse. No parser installed.')
    functions = functions if functions is not None else function_registry
    expr_str = to_string(timeseries_expression).lower()
    return parsefunc(expr_str, functions, method, debug)
Esempio n. 2
0
def parse(timeseries_expression, method = None,
          functions = None, debug = False):
    '''Function for parsing :ref:`timeseries expressions <dsl-script>`.
If succesful, it returns an instance of :class:`dynts.dsl.Expr` which
can be used to to populate timeseries or scatters once data is available.

Parsing is implemented using the ply_ module,
an implementation of lex and yacc parsing tools for Python.

:parameter expression: A :ref:`timeseries expressions <dsl-script>` string.
:parameter method: Not yet used.
:parameter functions: dictionary of functions to use when parsing.
    If not provided the :data:`dynts.function_registry`
    will be used.

    Default ``None``.
:parameter debug: debug flag for ply_.  Default ``False``.

For examples and usage check the :ref:`dsl documentation <dsl>`.

.. _ply: http://www.dabeaz.com/ply/
'''
    if not parsefunc:
        raise ExpressionError('Could not parse. No parser installed.')
    functions = functions if functions is not None else function_registry
    expr_str = to_string(timeseries_expression).lower()
    return parsefunc(expr_str, functions, method, debug)
Esempio n. 3
0
def parse(timeseries_expression, method = None, functions = None, debug = False):
    '''Function for parsing :ref:`timeseries expressions <dsl-script>`.
If succesful, it returns an instance of :class:`dynts.dsl.Expr`.'''
    from ply import yacc
    from .rules import rules
    functions = functions if functions is not None else function_registry
    ru = rules(functions)
    ru.build()
    ru.input(to_string(timeseries_expression).lower())
    tokens     = ru.tokens
    precedence = ru.precedence
    yacc       = yacc.yacc(method = method or 'SLR')
    return yacc.parse(lexer = ru.lexer, debug = debug)
Esempio n. 4
0
def parse(timeseries_expression, method=None, functions=None, debug=False):
    '''Function for parsing :ref:`timeseries expressions <dsl-script>`.
If succesful, it returns an instance of :class:`dynts.dsl.Expr`.'''
    from ply import yacc
    from .rules import rules
    functions = functions if functions is not None else function_registry
    ru = rules(functions)
    ru.build()
    ru.input(to_string(timeseries_expression).lower())
    tokens = ru.tokens
    precedence = ru.precedence
    yacc = yacc.yacc(method=method or 'SLR')
    return yacc.parse(lexer=ru.lexer, debug=debug)