Added subscript parsing
parent
0c215a5df4
commit
bd13b10f76
|
@ -77,7 +77,6 @@ The lines in a file look exactly the same as regular entries in the prompt, but
|
|||
|
||||
|
||||
## Todo (pre-release, in this order):
|
||||
- Export will break with :save, fix it.
|
||||
- Prevent macro-chaining recursion
|
||||
- Full-reduce option (expand all macros)
|
||||
- step-by-step reduction
|
||||
|
|
|
@ -166,11 +166,14 @@ def prepare(root: lbn.Root, *, ban_macro_name = None) -> list:
|
|||
if (n.input.name in bound_variables):
|
||||
raise lbn.ReductionError(f"Bound variable name conflict: \"{n.input.name}\"")
|
||||
else:
|
||||
bound_variables[n.input.name] = lbn.Bound(n.input.name)
|
||||
bound_variables[n.input.name] = lbn.Bound(
|
||||
lamb.utils.remove_sub(n.input.name),
|
||||
macro_name = n.input.name
|
||||
)
|
||||
n.input = bound_variables[n.input.name]
|
||||
|
||||
elif s == lbn.Direction.LEFT:
|
||||
del bound_variables[n.input.name]
|
||||
del bound_variables[n.input.macro_name] # type: ignore
|
||||
|
||||
return warnings
|
||||
|
||||
|
|
|
@ -333,11 +333,16 @@ class History(ExpandableEndNode):
|
|||
|
||||
bound_counter = 0
|
||||
class Bound(EndNode):
|
||||
def __init__(self, name: str, *, forced_id = None, runner = None):
|
||||
def __init__(self, name: str, *, forced_id = None, runner = None, macro_name = None):
|
||||
self.name = name
|
||||
global bound_counter
|
||||
self.runner = runner # type: ignore
|
||||
|
||||
# The name of the macro this bound came from.
|
||||
# Always equal to self.name, unless the macro
|
||||
# this came from had a subscript.
|
||||
self.macro_name: str | None = macro_name
|
||||
|
||||
if forced_id is None:
|
||||
self.identifier = bound_counter
|
||||
bound_counter += 1
|
||||
|
|
|
@ -13,7 +13,7 @@ class LambdaParser:
|
|||
# We still create macro objects from them, they are turned into
|
||||
# bound variables after the expression is built.
|
||||
self.pp_macro = pp.Word(pp.alphas + "_")
|
||||
self.pp_bound = pp.Char(pp.srange("[a-z]"))
|
||||
self.pp_bound = pp.Regex("[a-z][₀₁₂₃₄₅₆₈₉]*")
|
||||
self.pp_name = self.pp_bound ^ self.pp_macro
|
||||
self.pp_church = pp.Word(pp.nums)
|
||||
self.pp_history = pp.Char("$")
|
||||
|
|
|
@ -5,6 +5,8 @@ from prompt_toolkit.key_binding import KeyBindings
|
|||
from prompt_toolkit import print_formatted_text as printf
|
||||
from importlib.metadata import version
|
||||
|
||||
import re
|
||||
|
||||
|
||||
style = Style.from_dict({ # type: ignore
|
||||
# Basic formatting
|
||||
|
@ -108,6 +110,9 @@ def show_greeting():
|
|||
""
|
||||
])), style = style)
|
||||
|
||||
def remove_sub(s: str):
|
||||
return re.sub("[₀₁₂₃₄₅₆₈₉]*", "", s)
|
||||
|
||||
def base4(n: int):
|
||||
if n == 0:
|
||||
return [0]
|
||||
|
@ -119,9 +124,9 @@ def base4(n: int):
|
|||
|
||||
def subscript(num: int):
|
||||
|
||||
# unicode subscripts ₀₁₂₃
|
||||
# usually look different than
|
||||
# the rest, so we'll use base 4.
|
||||
# unicode subscripts ₀₁₂₃ and ₄₅₆₈₉
|
||||
# usually look different,
|
||||
# so we'll use base 4.
|
||||
qb = base4(num)
|
||||
|
||||
sub = {
|
||||
|
|
Reference in New Issue