Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modulise clean #17

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions RASP_support/DrawCompFlow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from FunctionalSupport import Unfinished, guarded_contains, base_tokens, \
from .FunctionalSupport import Unfinished, guarded_contains, base_tokens, \
tokens_asis
from Support import clean_val
from .Support import clean_val
import os
import string
import analyse # adds useful functions to all the Unfinisheds

# adds useful functions to all the Unfinisheds
# using dummyimport to import analyse with the relative "." because python
# won't let me do "import .analyse"
from .analyse import dummyimport


# fix: in ordering, we always connect bottom FF to top select. but sometimes,
# there is no FF (if go straight into next select), or there is no rendered
Expand Down Expand Up @@ -602,3 +607,6 @@ def draw_comp_flow(self, w, filename=None,
g.view()
if not keep_dot:
os.remove(filename)


dummyimport = None
4 changes: 2 additions & 2 deletions RASP_support/Environment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from FunctionalSupport import Unfinished, RASPTypeError, tokens_asis, \
from .FunctionalSupport import Unfinished, RASPTypeError, tokens_asis, \
tokens_str, tokens_int, tokens_bool, tokens_float, indices
from Evaluator import RASPFunction
from .Evaluator import RASPFunction


class UndefinedVariable(Exception):
Expand Down
8 changes: 4 additions & 4 deletions RASP_support/Evaluator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from FunctionalSupport import select, zipmap, aggregate, \
from .FunctionalSupport import select, zipmap, aggregate, \
or_selects, and_selects, not_select, indices, \
Unfinished, UnfinishedSequence, UnfinishedSelect
from Sugar import tplor, tpland, tplnot, toseq, full_s
from Support import RASPTypeError, RASPError
from .Sugar import tplor, tpland, tplnot, toseq, full_s
from .Support import RASPTypeError, RASPError
from collections.abc import Iterable
from zzantlr.RASPParser import RASPParser
from .zzantlr.RASPParser import RASPParser

ENCODER_NAME = "s-op"

Expand Down
8 changes: 4 additions & 4 deletions RASP_support/FunctionalSupport.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from Support import aggregate as _aggregate
from Support import Sequence, RASPTypeError
from Support import select as _select
from Support import zipmap as _zipmap
from .Support import aggregate as _aggregate
from .Support import Sequence, RASPTypeError
from .Support import select as _select
from .Support import zipmap as _zipmap
import traceback
import sys # for readable exception handling
from collections.abc import Iterable
Expand Down
12 changes: 6 additions & 6 deletions RASP_support/REPL.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from antlr4.error.ErrorListener import ErrorListener
from antlr4 import CommonTokenStream, InputStream
from collections.abc import Iterable
from zzantlr.RASPLexer import RASPLexer
from zzantlr.RASPParser import RASPParser
from Environment import Environment, UndefinedVariable, ReservedName
from FunctionalSupport import UnfinishedSequence, UnfinishedSelect, Unfinished
from Evaluator import Evaluator, NamedVal, NamedValList, JustVal, \
from .zzantlr.RASPLexer import RASPLexer
from .zzantlr.RASPParser import RASPParser
from .Environment import Environment, UndefinedVariable, ReservedName
from .FunctionalSupport import UnfinishedSequence, UnfinishedSelect, Unfinished
from .Evaluator import Evaluator, NamedVal, NamedValList, JustVal, \
RASPFunction, ArgsError, RASPTypeError, RASPValueError
from Support import Select, Sequence, lazy_type_check
from .Support import Select, Sequence, lazy_type_check

ENCODER_NAME = "s-op"

Expand Down
14 changes: 8 additions & 6 deletions RASP_support/Sugar.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from FunctionalSupport import Unfinished as _Unfinished
from FunctionalSupport import UnfinishedSequence as _UnfinishedSequence
from FunctionalSupport import select, zipmap
from make_operators import add_ops
import DrawCompFlow
from .FunctionalSupport import Unfinished as _Unfinished
from .FunctionalSupport import UnfinishedSequence as _UnfinishedSequence
from .FunctionalSupport import select, zipmap
from .make_operators import add_ops
from .DrawCompFlow import dummyimport
# DrawCompFlow is not at all necessary for sugar, but sugar is really the
# top-level rasp file we import, and nice to have draw_comp_flow added into
# the sequences already on load
# the sequences already on load. also, don't *really* need to import
# dummy specifically, but python won't accept "import .DrawCompFlow"
# while it will accept some form of "from .DrawCompFlow import ..."


def _apply_unary_op(self, f):
Expand Down
1 change: 1 addition & 0 deletions RASP_support/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .REPL import REPL
3 changes: 3 additions & 0 deletions RASP_support/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .REPL import REPL

REPL().run()
5 changes: 4 additions & 1 deletion RASP_support/analyse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from FunctionalSupport import Unfinished, UnfinishedSequence, \
from .FunctionalSupport import Unfinished, UnfinishedSequence, \
UnfinishedSelect, guarded_contains, guarded_compare, zipmap
from collections import defaultdict, Counter
from copy import copy
Expand Down Expand Up @@ -353,3 +353,6 @@ def pre_aggregate_comp(seq):
if isinstance(vreal, tuple): # equivalently, if seq.output_index >= 0:
vreal = vreal[seq.output_index]
return vreal


dummyimport = None
4 changes: 2 additions & 2 deletions rasp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ source raspenv/bin/activate

if [[ $(rlwrap -v) == rlwrap* ]]; then
# the better option. requires rlwrap
rlwrap python3 RASP_support/REPL.py
rlwrap python3 -m RASP_support
else
python3 RASP_support/REPL.py
python3 -m RASP_support
fi

deactivate
4 changes: 2 additions & 2 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def check_equal(f1, f2):


def run_input(name):
os.system("python3 RASP_support/REPL.py <" +
os.system("python3 -m RASP_support <" +
joinpath(inpath, name)+" >"+joinpath(outpath, name))
fix_file_paths(joinpath(outpath, name), curr_path_marker)
return check_equal(joinpath(outpath, name), joinpath(tgtpath, name))
Expand All @@ -34,7 +34,7 @@ def run_inputs():

def test_broken_lib(lib):
os.system("cp "+joinpath(libspath, lib)+" RASP_support/rasplib.rasp")
os.system("python3 RASP_support/REPL.py <"+joinpath(libtestspath,
os.system("python3 -m RASP_support <"+joinpath(libtestspath,
"empty.txt") + " >"+joinpath(liboutspath, lib))
return check_equal(joinpath(liboutspath, lib), joinpath(libtgtspath, lib))

Expand Down
Loading