minor changes

This commit is contained in:
Xanderplayz16 2024-09-15 18:02:36 -04:00
parent f903f9a309
commit 90cc4ff466

View file

@ -1,6 +1,7 @@
import tokenize, io import tokenize, io
PREFIX = """ PREFIX = """
import typing as _INTERNAL_typing
# ITHON START # ITHON START
class _INTERNAL_Token: class _INTERNAL_Token:
__slots__ = ('action',) __slots__ = ('action',)
@ -37,7 +38,12 @@ _INTERNAL_rpipe = _INTERNAL_Token(lambda lhs, rhs: lhs(rhs))
_INTERNAL_lspipe = _INTERNAL_Token(lambda lhs, rhs: rhs(*lhs)) _INTERNAL_lspipe = _INTERNAL_Token(lambda lhs, rhs: rhs(*lhs))
_INTERNAL_rspipe = _INTERNAL_Token(lambda lhs, rhs: lhs(*rhs)) _INTERNAL_rspipe = _INTERNAL_Token(lambda lhs, rhs: lhs(*rhs))
# If you write in other programming languages, this is useful.
null = None
nil = None
void = None
type Maybe[T] = T | None
# ITHON END # ITHON END
""" """
@ -130,8 +136,15 @@ def translate(file: io.StringIO):
if name == "<>": # barry is flufl if name == "<>": # barry is flufl
yield tokenize.OP, "!=" yield tokenize.OP, "!="
elif tokens[n - 1][1] != ')' and name == "->": # -> operator, don't trigger on function type annotation
pass
else: else:
yield type, name yield type, name
#elif type == tokenize.NAME:
# if name == "λ":
# yield tokenize.NAME, 'lambda'
# else:
# yield type, name
else: else:
yield type,name yield type,name
@ -143,9 +156,12 @@ def fibonacci(x: int) -> list[int]:
start.append <| start[i] + start[i - 1] start.append <| start[i] + start[i - 1]
return start return start
a = 12 |> fibonacci a = 12 |> fibonacci
b = a :: a b = a :: a :: a :: a
print <| [i for i in b] c = b :: b :: b :: b
print <| [i for i in c]
print <*| ('a', 'b', 'c') print <*| ('a', 'b', 'c')
d = lambda x: x * 2
#d2 = λ x: x * 2
""" """
code = tokenize.untokenize(translate(io.StringIO(script))) code = tokenize.untokenize(translate(io.StringIO(script)))
print(code) print(code)