class documentation
class SExprParser(object):
Class that implements an S-Expression parser.
| Method | ast |
Generate an abstract syntax tree (AST) from normalized input. |
| Method | normalize |
Parse an input string into a list of opening and closing parentheses, and atoms. Atoms include symbols, numbers and strings. |
| Class Variable | error |
In case of an error this attribute contains the error expression. |
def ast(self, input:
SSymbolsList | str, topLevel: bool = True, allowBrackets: bool = False, parentSymbol: SSymbol | None = None) -> SSymbolsList:
¶
Generate an abstract syntax tree (AST) from normalized input.
The result is a list of elements. Each element is either an atom, a string, a number, or again a list of elements.
| Parameters | |
input:SSymbolsList | str | Either a string or a list of SSymbol elements. A string would internally be parsed to a list of SSymbol elements before further processing. |
topbool | Indicating whether a parsed input is at the top level or a branch of a another AST. |
allowbool | Allow "[" and "]" for opening and closing lists as well. |
parentSSymbol | None | The parent symbol of the current AST. |
| Returns | |
SSymbolsList | A list that represents the abstract syntax tree. |
| Raises | |
ValueError | In case of a syntax error (usually missing opening or closing paranthesis). |
Parse an input string into a list of opening and closing parentheses, and atoms. Atoms include symbols, numbers and strings.
The results excludes all whitespaces. Also, special escape characters outside and inside of strings are handled. The escape character is backslash.
| Parameters | |
input:str | The input string. |
allowbool | Allow "[" and "]" for opening and closing lists as well. |
| Returns | |
SSymbolsList | A list of paranthesis and atoms. |