fparser.common.splitline

Defines LineSplitter and helper functions.

Original Author: Pearu Peterson <pearu@cens.ioc.ee> First version created: May 2006


Module Contents

Classes

String

Dummy string class.

Functions

string_replace_map(line[, lower])

  1. Replaces string constants with symbol '_F2PY_STRING_CONSTANT_<index>_'

splitquote(line[, stopchar, lower, quotechars])

Splits the supplied line of text into parts consisting of regions that

splitparen(line[, paren_open, paren_close])

Splits a line into top-level parenthesis and not-parenthesised

class fparser.common.splitline.String[source]

Bases: str

Dummy string class.

fparser.common.splitline.string_replace_map(line, lower=False)[source]
  1. Replaces string constants with symbol ‘_F2PY_STRING_CONSTANT_<index>_’

  2. Replaces (expression) with symbol (F2PY_EXPR_TUPLE_<index>)

  3. Replaces real numerical constants containing an exponent with symbol F2PY_REAL_CONSTANT_<index>_

Parameters:
  • line (str) – the line of text in which to perform substitutions.

  • lower (bool) – whether or not the call to splitquote() should return items as lowercase (default is to leave the case unchanged).

Returns:

a new line and the replacement map.

Return type:

2-tuple of str and fparser.common.splitline.StringReplaceDict

fparser.common.splitline.splitquote(line, stopchar=None, lower=False, quotechars='"\'')[source]

Splits the supplied line of text into parts consisting of regions that are not contained within quotes and those that are.

Allows for the processing of a line that follows on from a previous one where a quoted string was begun but not closed by supporting the current closing quotation character to be specified.

Parameters:
  • line (str) – the line to split.

  • stopchar (Optional[str]) – the quote character that will terminate an existing quoted string or None otherwise.

  • lower (bool) – whether or not to convert the split parts of the line to lowercase.

  • quotechars (str) – the characters that are considered to delimit quoted strings.

Returns:

tuple containing a list of the parts of the line split into those parts that are not quoted strings and those parts that are as well as the quote character corresponding with any quoted string that has not been closed before the end of the line.

Return type:

Tuple[List[str], str]

fparser.common.splitline.splitparen(line, paren_open='([', paren_close=')]')[source]

Splits a line into top-level parenthesis and not-parenthesised parts. E.g.: “a( (1+2)*3) = b(x)” becomes: [“a”, “( (1+2)*3)”, “ = b”, “(x)”] :param str line: the string to split. :param str paren_open: The characters that define an open parentheses. :param str paren_close: The characters that define a closing parentheses. :return: List of parenthesised and not-parenthesised parts :rtype: list of str The paren_open and paren_close strings must be matched in order: paren_open[x] is closed by paren_close[x].