2 def __init__(self, keyword, *args):
10 def write_to_file(self, f, indent=0):
14 s += " {:#.6g}".format(a)
21 s += ' "{}"'.format(a)
22 elif type(a)==Resource:
23 s += ' "{}"'.format(a.name)
28 f.write("{}{}".format(tabs, s))
30 f.write("\n{}{{\n".format(tabs))
32 s.write_to_file(f, indent+1)
33 f.write("{}}};\n".format(tabs))
39 def __init__(self, text):
47 def __init__(self, name):
52 def create_reference_statement(self, keyword, *args):
54 raise TypeError("create_reference_statement expected at least 2 arguments, got {}".format(1+len(args)))
62 raise TypeError("create_reference_statement expected a Resource argument, found none")
64 self.references += [r for r in resources if r not in self.references]
65 return Statement(keyword, *args)
67 def create_embed_statement(self, keyword, *args):
69 raise TypeError("create_embed_statement expected at least 2 arguments, got {}".format(1+len(args)))
71 if type(res)!=Resource:
72 raise TypeError("create_embed_statement expected a Resource as last argument, got {}".format(type(args[-1]).__name__))
74 self.references += [r for r in res.references if r not in self.references]
75 st = Statement(keyword, *args[:-1])
76 st.sub = res.statements
79 def collect_references(self):
81 for r in self.references:
82 refs += [e for e in r.collect_references() if e not in refs]
83 refs += [e for e in self.references if e not in refs]