Parser

Internal documentation for the amalgam.parser module.

class amalgam.parser.Parser[source]

Class that serves as the frontend for parsing text.

parse_buffer

The text buffer used within Parser.repl_parse().

Type

StringIO

parse(text: str)amalgam.amalgams.Amalgam[source]

Facilitates regular parsing that can fail.

repl_parse(text: str) → Optional[amalgam.amalgams.Amalgam][source]

Facilitates multi-line parsing for the REPL.

Writes the given text string to the parse_buffer and attempts to parse text.

If MissingClosing is raised, returns None to allow for parsing to continue.

If another subclass of ParsingError is raised, clears the parse_buffer and re-raises the exception.

Otherwise, if parsing succeeds, clears the parse_buffer and returns the parsed expression.

class amalgam.parser.Expression(visit_tokens=True)[source]

Transforms expressions in text into their respective amalgams.Amalgam representations.

atom(identifier: lark.lexer.Token)amalgam.amalgams.Atom[source]
floating(number: lark.lexer.Token)amalgam.amalgams.Numeric[source]
fraction(number: lark.lexer.Token)amalgam.amalgams.Numeric[source]
integral(number: lark.lexer.Token)amalgam.amalgams.Numeric[source]
quoted(expression: amalgam.amalgams.Amalgam)amalgam.amalgams.Quoted[source]
s_expression(*expressions: amalgam.amalgams.Amalgam)amalgam.amalgams.SExpression[source]
string(*values: lark.lexer.Token) → amalgam.amalgams.String[source]
symbol(identifier: lark.lexer.Token)amalgam.amalgams.Symbol[source]
vector(*expressions: amalgam.amalgams.Amalgam)amalgam.amalgams.Vector[source]
class amalgam.parser.ParsingError(line: int, column: int)[source]

Base exception for errors during parsing.

line

the line number nearest to the error

Type

int

column

the column number nearest to the error

Type

int

class amalgam.parser.ExpectedEOF(line: int, column: int)[source]

Raised when multiple expressions are found.

class amalgam.parser.ExpectedExpression(line: int, column: int)[source]

Raised when no expressions are found.

class amalgam.parser.MissingClosing(line: int, column: int)[source]

Raised on missing closing parentheses or brackets.

class amalgam.parser.MissingOpening(line: int, column: int)[source]

Raised on missing opening parentheses or brackets.