Amalgams¶
Internal documentation for the amalgam.amalgams module.
- class amalgam.amalgams.Located[source]¶
The base dataclass for encapsulating location data of nodes.
Provides an API similar to Lark’s
Tokenclass for convenience.- line_span¶
Lines spanned by a node
- Type
Tuple[int, int]
- column_span¶
Columns spanned by a node
- Type
Tuple[int, int]
- located_on(*, lines: Tuple[int, int] = (- 1, - 1), columns: Tuple[int, int] = (- 1, - 1)) → amalgam.amalgams.L[source]¶
Helper method for setting
Located.line_spanandLocated.column_span.
- property column: int¶
The starting column number of a node.
- property end_column: int¶
The ending column number of a node.
- property end_line: int¶
The ending line number of a node.
- property line: int¶
The starting line number of a node.
- class amalgam.amalgams.Atom(value: str)[source]¶
An
Amalgamthat represents different atoms.- value¶
The name of the atom.
- Type
str
- class amalgam.amalgams.Numeric(value: amalgam.amalgams.N)[source]¶
An
Amalgamthat wraps around numeric types.Parameterized as a
Genericby:N = TypeVar("N", int, float, Fraction)- value¶
The numeric value being wrapped.
- Type
N
- class amalgam.amalgams.Symbol(value: str)[source]¶
An
Amalgamthat wraps around symbols.- value¶
The name of the symbol.
- Type
str
- evaluate(environment: Environment) → Amalgam[source]¶
Searches the provided environment fully with
Symbol.value. Returns theAmalgamobject bound to theSymbol.valuein the environment. Returns a fatalNotificationif a binding is not found.
- class amalgam.amalgams.Function(name: str, fn: Callable[[...], amalgam.amalgams.Amalgam], defer: bool = False, contextual: bool = False)[source]¶
An
Amalgamthat wraps around functions.- name¶
The name of the function.
- Type
str
- fn¶
The function being wrapped. Must have the signature: (env, amalgams…) -> amalgam.
- Type
Callable[..., Amalgam]
- defer¶
If set to
False, arguments are evaluated before being passed toFunction.fn.- Type
bool
- contextual¶
If set to
True, disallows function calls whenFunction.in_contextis set toFalse.- Type
bool
- env¶
The
environment.Environmentinstance bound to the function. Overrides the environment parameter passed to theFunction.call()method.
- in_context¶
Predicate that disallows functions to be called outside of specific contexts. Makes
Function.call()return a fatalNotificationwhen set toFalseandFunction.contextualis set toTrue.- Type
bool
- bind(environment: Environment) → Function[source]¶
Sets the
Function.envattribute and returns the sameFunctionreference.
- call(environment: Environment, *arguments: Amalgam) → Amalgam[source]¶
Performs the call to the
Function.fnattribute.Performs pre-processing depending on the values of
Function.defer,Function.contextual, andFunction.in_context,
- with_name(name: str) → amalgam.amalgams.Function[source]¶
Sets the
Function.nameattribute and returns the sameFunctionreference.
- class amalgam.amalgams.SExpression(*vals: amalgam.amalgams.Amalgam)[source]¶
An
Amalgamthat wraps around S-Expressions.- vals¶
Entities contained by the S-Expression.
- Type
Tuple[Amalgam, ...]
- evaluate(environment: Environment) → Amalgam[source]¶
Evaluates
funcusing environment before invoking thecall()method with environment andSExpression.args.
- property args: Tuple[amalgam.amalgams.Amalgam, ...]¶
The rest of the
SExpression.vals.
- property func: amalgam.amalgams.Amalgam¶
The head of the
SExpression.vals.
- class amalgam.amalgams.Vector(*vals: amalgam.amalgams.T)[source]¶
An
Amalgamthat wraps around a homogenous vector.Parameterized as a
Genericby:T = TypeVar("T", bound=Amalgam)- vals¶
Entities contained by the vector
- Type
Tuple[T, ...]
- mapping¶
Mapping representing vectors with
Atoms for odd indices andAmalgams for even indices.- Type
Mapping[str, Amalgam]
- _as_mapping() → Mapping[str, amalgam.amalgams.Amalgam][source]¶
Attemps to create a
Mapping[str, Amalgam]fromVector.vals.Odd indices must be
Atoms and even indices must beAmalgams. Returns an empty mapping if this form is not met.
- evaluate(environment: Environment) → Amalgam[source]¶
Creates a new
Vectorby evaluating every value inVector.vals.
- class amalgam.amalgams.Quoted(value: amalgam.amalgams.T)[source]¶
An
Amalgamthat defers evaluation of otherAmalgams.Parameterized as a
Genericby:T = TypeVar("T", bound=Amalgam)
- class amalgam.amalgams.Failure(amalgam: Amalgam, environment: Environment, message: str)[source]¶
Represents failures during evaluation.
- message¶
An error message attached to the failure.
- Type
str
- class amalgam.amalgams.FailureStack(failures: List[amalgam.amalgams.Failure])[source]¶
Represents a collection of
Failureinstances.- make_report(text: str, source: str = '<unknown>') → str[source]¶
Generates a report to be printed to
sys.stderr.Accepts
textandsourcefor prettified output.
- push(failure: amalgam.amalgams.Failure) → None[source]¶