Exemplo n.º 1
0
def main():
    import sys

    def usage():
        print "usage: \n  {} <file>.iev ".format(sys.argv[0])
        sys.exit(1)

    if len(sys.argv) != 2:
        usage()
        exit(1)
    fn = sys.argv[1]
    import chardet  # $ pip install chardet
    try:
        f = open(fn, 'r')
    except:
        print "not found: %s" % fn
        sys.exit(1)

    with iu.ErrorPrinter():
        with iu.SourceFile(fn):
            s = f.read()
            evs = ev.parse(s)
    global tk
    tk = Tix.Tk()
    RunSample(tk, evs)
    tk.mainloop()
Exemplo n.º 2
0
def import_module(name):
    fname = name + '.ivy'
    f = open(fname, 'r')
    if not f:
        raise IvyError(None,
                       "module {} not found in current directory".format(name))
    with iu.SourceFile(fname):
        mod = read_module(f, nested=True)
    return mod
Exemplo n.º 3
0
def source_file(fn, f, **kwargs):
    try:
        with iu.SourceFile(fn):
            ivy_load_file(f, **kwargs)
            ivy_module.module.name = fn[:fn.rindex('.')]
    except IvyError as e:
        if not hasattr(e, 'filename'):
            e.filename = fn
        print str(e)
        sys.exit(1)
Exemplo n.º 4
0
def main():
    ivy_init.read_params()
    if not sys.argv[1].endswith('ivy'):
        usage()
    for i in range(2, len(sys.argv)):
        st = sys.argv[i].split('=')
        instance[st[0]] = eval(st[1])

    with im.Module():
        with utl.ErrorPrinter():
            with iu.SourceFile(sys.argv[1]):
                decls = read_module(ivy_init.open_read(sys.argv[1]))
                translate(decls)
Exemplo n.º 5
0
def source_file(fn, f, **kwargs):
    try:
        with iu.SourceFile(fn):
            ivy_load_file(f, **kwargs)
            ivy_module.module.name = fn[:fn.rindex('.')]
    except IvyError as e:
        if not hasattr(e, 'filename'):
            e.filename = fn
        print str(e)

        if hasattr(e, 'source_location'):
            print e.source_location.context_line
            if e.source_location.column:
                print ' ' * (e.source_location.column - 1) + '^'
        sys.exit(1)
Exemplo n.º 6
0
def import_module(name):
    fname = name + '.ivy'
    try:
        f = open(fname, 'r')
    except Exception:
        inc = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                           'include', fname)
        try:
            f = open(inc, 'r')
        except Exception:
            raise IvyError(
                None,
                "module {} not found in current directory or module path".
                format(name))
    with iu.SourceFile(fname):
        mod = read_module(f, nested=True)
    return mod
Exemplo n.º 7
0
Arquivo: ivy.py Projeto: asyaf/ivy
def ivy_init():
    read_params()

    #    if mode.get() == "ivy2":
    #        return ivy_init2()

    if len(sys.argv) < 2 or len(sys.argv) > 3:
        usage()

    files = [(fn, open_read(fn)) for fn in sys.argv[1:]]

    if files[0][0].endswith('.a2g'):
        fn, f = files.pop(0)
        ag = pickle.load(f)

        if not hasattr(ag.domain, 'all_relations'):
            #            print "reconstructing all_relations"
            ag.domain.all_relations = []
            for x in ag.domain.relations:
                ag.domain.all_relations.append((x, ag.domain.relations[x]))
            for (x, y) in ag.domain.concepts:
                ag.domain.all_relations.append(
                    (x.atom.relname, len(x.atom.args)))
        ivy_logic.sig = ag.domain.sig  # TODO: make this an environment
        f.close()
    else:
        #        print "creating new"
        ag = ivy_new()

    if files:
        fn, f = files.pop(0)
        if not fn.endswith('.ivy') and not fn.endswith('.dfy'):
            usage()
        try:
            #            print "loading file %s" % fn
            with iu.SourceFile(fn):
                ivy_load_file(f, ag)
        except IvyError as e:
            if not hasattr(e, 'filename'):
                e.filename = fn
            print repr(e)
            sys.exit(1)
    return ag