Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 72 lines (56 sloc) 1.8 kB
08e46d5 @slomo add json loader
authored
1 from fofTypes import *
f6abf04 @slomo working
authored
2 from subprocess import Popen, PIPE
08e46d5 @slomo add json loader
authored
3 import json
f6abf04 @slomo working
authored
4 import os
08e46d5 @slomo add json loader
authored
5
6 def unary_handler(data):
7 f = load(data['formula'])
341b3b5 @slomo apply final fixes
authored
8 return UnaryOperator("~",f)
08e46d5 @slomo add json loader
authored
9
10 def binary_handler(data):
11 left = load(data['leftFormula'])
12 right = load(data['leftFormula'])
13 return BinaryOperator(data['op'], left, right)
14
15 def quantor_handler(data):
341b3b5 @slomo apply final fixes
authored
16 variables = [ load(x) for x in data["variables"] ]
f6abf04 @slomo working
authored
17 print("---------------------",load(data["formula"]))
341b3b5 @slomo apply final fixes
authored
18 return Quantor(data["op"], variables, load(data["formula"]))
08e46d5 @slomo add json loader
authored
19
20 def function_handler(data):
21 name = data["name"]
22 args = [ load(x) for x in data["terms"] ]
23 return Function(name, args)
24
25 def relation_handler(data):
26 name = data["name"]
27 args = [ load(x) for x in data["terms"] ]
28 return Relation(name, args)
29
30 def variable_handler(data):
31 return Variable(data['name'])
32
33 def load(data):
341b3b5 @slomo apply final fixes
authored
34 dtype = data["type"]
35 if dtype == "relation":
36 return relation_handler(data)
37 elif dtype == "function":
38 return function_handler(data)
39 elif dtype == "binaryOperator":
40 return binary_handler(data)
41 elif dtype == "unaryOperator":
42 return unary_handler(data)
43 elif dtype == "variable":
44 return variable_handler(data)
45 elif dtype == "quantor":
46 return quantor_handler(data)
f6abf04 @slomo working
authored
47 else:
48 print(dtype)
49 assert(False)
50
51 def load_tree(tree):
52 for form in tree:
53 form["formula"] = load(form["formula"])
54
55 return tree
08e46d5 @slomo add json loader
authored
56
57 def load_file(filename):
58
59 with open(filename) as f:
60 tree = json.load(f)
f6abf04 @slomo working
authored
61 return load_tree(tree)
62
63 def parse_and_load(filename):
64
65 parser = Popen(["./parser", filename], stdout=PIPE)
08e46d5 @slomo add json loader
authored
66
f6abf04 @slomo working
authored
67 parser.wait()
68 (data,other) = parser.communicate()
08e46d5 @slomo add json loader
authored
69
f6abf04 @slomo working
authored
70 data = data.decode('utf-8')
71 return load_tree(json.loads(data))
Something went wrong with that request. Please try again.