Version 1.0
Copyright © 2022 Lowell D. Thomas
Python APG
 … an ABNF Parser Generator
Functions
apg_py.lib.utilities Namespace Reference

Functions

def string_to_tuple (string)
 Converts a string to a tuple of the Unicode values of the string characters. More...
 
def tuple_to_string (input)
 Converts a tuple of Unicode values to the equivalent string. More...
 
def tuple_to_ascii (input, map=None)
 Converts a tuple of Unicode values to an ASCII string. More...
 
def tuple_to_ascii_underline (map, index)
 Uses the (optional) map generated by tuple_to_ascii() to generate a mapping of the display characters to the actual tuple (integer) characters. More...
 
def pprint_to_string (obj, temp)
 Pretty prints an object to a temporary file, then reads the string back and returns it. More...
 

Function Documentation

◆ pprint_to_string()

def apg_py.lib.utilities.pprint_to_string (   obj,
  temp 
)

Pretty prints an object to a temporary file, then reads the string back and returns it.

Parameters
objThe object to pretty print.
tempThe file name to use to save the printed string. It is deleted after use.
Returns
The pretty printed string or the exception on file error.
  • result['string'] is the displayed object on success
  • result['error'] is the exception raised on failure.

Definition at line 112 of file utilities.py.

◆ string_to_tuple()

def apg_py.lib.utilities.string_to_tuple (   string)

Converts a string to a tuple of the Unicode values of the string characters.

The APG parser requires a tuple of integers as input. However, many problems are defined in terms of ASCII or Unicode strings. This utility is a handy assist to get a string into the proper format for parser input.

Parameters
stringThe string to convert.
Returns
A tuple of the Unicode code points for each of the strings's characters.

Definition at line 8 of file utilities.py.

◆ tuple_to_ascii()

def apg_py.lib.utilities.tuple_to_ascii (   input,
  map = None 
)

Converts a tuple of Unicode values to an ASCII string.

Non-ASCII characters are displayed by hexadecimal value. Used mainly for error reporting in the syntax phase.

Parameters
inputThe tuple of Unicode values to convert.
mapIf map = [] a list of character display mappings is generated. map[index] = [offset, length] where
  • index is the zero-based index of the character to map
  • offset is the offset from the beginning of the ASCII display to the first display gliph for the indexed character
  • length is the number of ASCII characters used to display the indexed character
Returns
The converted string.

Definition at line 36 of file utilities.py.

◆ tuple_to_ascii_underline()

def apg_py.lib.utilities.tuple_to_ascii_underline (   map,
  index 
)

Uses the (optional) map generated by tuple_to_ascii() to generate a mapping of the display characters to the actual tuple (integer) characters.

Used mainly for error reporting in the syntax phase.

Parameters
mapA list of [offset, length] lists, one for each tuple character that indicates the offset into the ASCII display. and the length of the display of that specific character.
indexThe index of the underlying tuple character to accent.
Returns
A string to underline the original with caret(s) to mark the accented character.

Definition at line 85 of file utilities.py.

◆ tuple_to_string()

def apg_py.lib.utilities.tuple_to_string (   input)

Converts a tuple of Unicode values to the equivalent string.

Parameters
inputThe tuple of Unicode values to convert.
Returns
The converted string.

Definition at line 25 of file utilities.py.

Python APG, Version 1.0, is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.