From b636e86c564f95abcd91f7da8c22dff462e2a3dc Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 1 Oct 2021 12:50:41 -0500 Subject: [PATCH] i hate python --- agtest/__main__.py | 5 ---- old.py | 41 -------------------------- setup.cfg | 15 ++++++++++ setup.py | 6 ---- {agtest => src/agtest}/__init__.py | 0 {agtest => src/agtest}/ast.py | 0 {agtest => src/agtest}/driver.py | 4 ++- {agtest => src/agtest}/gen.py | 0 {agtest => src/agtest}/grammar.lark | 0 {agtest => src/agtest}/runtime.tmpl.py | 0 10 files changed, 18 insertions(+), 53 deletions(-) delete mode 100644 agtest/__main__.py delete mode 100644 old.py create mode 100644 setup.cfg rename {agtest => src/agtest}/__init__.py (100%) rename {agtest => src/agtest}/ast.py (100%) rename {agtest => src/agtest}/driver.py (89%) rename {agtest => src/agtest}/gen.py (100%) rename {agtest => src/agtest}/grammar.lark (100%) rename {agtest => src/agtest}/runtime.tmpl.py (100%) diff --git a/agtest/__main__.py b/agtest/__main__.py deleted file mode 100644 index e909d1f..0000000 --- a/agtest/__main__.py +++ /dev/null @@ -1,5 +0,0 @@ -import sys -import agtest.driver - -if __name__ == "__main__": - agtest.driver.run(sys.argv[1]) diff --git a/old.py b/old.py deleted file mode 100644 index df9c9f1..0000000 --- a/old.py +++ /dev/null @@ -1,41 +0,0 @@ -from typing import Generic, TypeVar, Optional, Callable - -T = TypeVar("T") - - -class Thunk(Generic[T]): - value: Optional[T] - - def __init__(self, func: Callable[[], T]): - self.func = func - self.value = None - - def get(self) -> T: - if self.value is None: - self.value = self.func() - return self.value - - -class Node: - value: Thunk[int] - - -class Add(Node): - def __init__(self, left: Node, right: Node): - self.value = Thunk(lambda: left.value.get() + right.value.get()) - - -class Mul(Node): - def __init__(self, left: Node, right: Node): - self.value = Thunk(lambda: left.value.get() * right.value.get()) - - -class Lit(Node): - def __init__(self, num: int): - self.num = num - self.value = Thunk(lambda: num) - - -if __name__ == "__main__": - tree = Add(Mul(Lit(3), Lit(4)), Lit(5)) - print(tree.value.get()) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..c198c76 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,15 @@ +[metadata] +name = click + +[options.entry_points] +console_scripts = + agt = agtest.driver:run + +[options] +packages = find: +package_dir = = src +include_package_data = true +python_requires = >= 3.6 + +[options.packages.find] +where = src diff --git a/setup.py b/setup.py index 80903ac..0adedc4 100644 --- a/setup.py +++ b/setup.py @@ -3,10 +3,4 @@ from setuptools import setup setup( name="agtest", version="0.1.0", - packages=["agtest"], - entry_points={ - 'console_scripts': [ - 'agt = agtest.driver.run', - ], - }, ) diff --git a/agtest/__init__.py b/src/agtest/__init__.py similarity index 100% rename from agtest/__init__.py rename to src/agtest/__init__.py diff --git a/agtest/ast.py b/src/agtest/ast.py similarity index 100% rename from agtest/ast.py rename to src/agtest/ast.py diff --git a/agtest/driver.py b/src/agtest/driver.py similarity index 89% rename from agtest/driver.py rename to src/agtest/driver.py index a7f2726..192eec1 100644 --- a/agtest/driver.py +++ b/src/agtest/driver.py @@ -8,7 +8,9 @@ from pathlib import Path from agtest.ast import Parser from agtest.gen import GenResult -grammar = path.join(path.dirname(path.realpath(__file__)), "grammar.lark") +src_dir = path.dirname(path.realpath(__file__)) +print("SOURCE", src_dir) +grammar = path.join(src_dir, "grammar.lark") p = lark.Lark(open(grammar).read(), start="program", parser="lalr") def run(path: Path): diff --git a/agtest/gen.py b/src/agtest/gen.py similarity index 100% rename from agtest/gen.py rename to src/agtest/gen.py diff --git a/agtest/grammar.lark b/src/agtest/grammar.lark similarity index 100% rename from agtest/grammar.lark rename to src/agtest/grammar.lark diff --git a/agtest/runtime.tmpl.py b/src/agtest/runtime.tmpl.py similarity index 100% rename from agtest/runtime.tmpl.py rename to src/agtest/runtime.tmpl.py