Rule

class neologism.Rule(lhs: str, rhs: Iterable[str])[source]

A class that is used to create and modify the DCFG.

The API uses str for symbols.

Rule is immutable, hashable and has its equivalence implemented.

Warning

Passing a str as rhs is undefined behavior – strings are iterable, so the constructor would silently produce a per-character rule. Pass a tuple, list, or other iterable of symbol strings.

__eq__(other: object) bool[source]

Return self==value.

__hash__() int[source]

Return hash(self).

__init__(lhs: str, rhs: Iterable[str]) None[source]
__repr__() str[source]

Return repr(self).

property lhs: str
Getter:

Left hand side.

Type:

str

property rhs: Tuple[str, ...]
Getter:

Right hand side.

Type:

tuple[str]

A Rule is the atomic production: one left-hand-side non-terminal expanding to a tuple of zero or more symbols on the right-hand side. Rules are immutable, hashable, and value-equal – two Rule objects with the same LHS and RHS compare equal regardless of construction order.