Skip to content

Commit

Permalink
colorama
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomlogo committed Mar 17, 2024
1 parent 03dba5e commit 06ceb3a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions flax/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def dyadic_link(link, w, x, flat=False):
if call == None:
call = overloads.get("any-any")
if call == None:
raise ValueError
error("call: overload not defined")
return call(x)
elif not flat_w and link.dw > dw:
return dyadic_link(link, [w], x)
Expand Down Expand Up @@ -369,7 +369,7 @@ def monadic_link(link, x, flat=False):
if call == None:
call = overloads.get("any")
if call == None:
raise ValueError
error("call: overload not defined")
return call(x)
elif link.dx > dx:
return monadic_link(link, [x])
Expand Down
9 changes: 5 additions & 4 deletions flax/error.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# error: holds the error handling things
import sys
import flax.common
from colorama import Fore, Style


def error(msg, exit_status=1, prefix="\n'"):
def error(msg, exit_status=1, prefix="'"):
"""error: errors with msg and optional exit_status"""
print(prefix + str(msg), file=sys.stderr)
print(Fore.RED + prefix + str(msg) + Style.RESET_ALL, file=sys.stderr)
exit(exit_status)


def debug(msg, prefix='\n"'):
def debug(msg, prefix='"'):
"""debug: log a debug message to stderr"""
if flax.common.DEBUG:
print(prefix + str(msg), file=sys.stderr)
print(Fore.YELLOW + prefix + str(msg) + Style.RESET_ALL, file=sys.stderr)
3 changes: 2 additions & 1 deletion flax/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re

from flax.builtins import *
from flax.error import error
from flax.common import TOKEN_TYPE

__all__ = ["TOKEN_TYPE", "tokenise"]
Expand Down Expand Up @@ -74,7 +75,7 @@ def tokenise(program):
elif digraph in quicks:
tokens.append([TOKEN_TYPE.QUICK, digraph])
else:
raise NameError("Digraph not defined.")
error(f'syn: non-existent diagraph "{diagraph}"')
elif head == LIST_DELIMETER_L:
contents = ""
k = 1
Expand Down
2 changes: 1 addition & 1 deletion flax/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parse(tokens):
if stack == [] and chains == []:
if token[1] in "ⁿ":
break
error(f'not enough links to pop for "{token[1]}"')
error(f'syn: not enough links for "{token[1]}"')
popped.insert(0, (stack or chains).pop())
stack += quicks[token[1]].qlink(popped, trains, index)
chains.append(create_chain(stack, arity, is_forward))
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ flax = "flax.main:main"
python = ">=3.9"
mpmath = "*"
more_itertools = "*"
colorama = "*"

[tool.poetry.dev-dependencies]
pytest = "*"
Expand Down

0 comments on commit 06ceb3a

Please sign in to comment.