Commit d0b0782f authored by Vlad Golubev's avatar Vlad Golubev

Закрытие дескрипторов файлов типа aDOT и cpp

parent 24680000
...@@ -289,32 +289,32 @@ class Parser(): ...@@ -289,32 +289,32 @@ class Parser():
def parse_file(self, filename): def parse_file(self, filename):
# @todo В случае, если на вход будет подан файл в отличной от UTF-8 кодировке программа работать не будет # @todo В случае, если на вход будет подан файл в отличной от UTF-8 кодировке программа работать не будет
gcd_dir_rel_path = os.path.abspath('../../gcd/') gcd_dir_rel_path = os.path.abspath('../../gcd/')
file = open(gcd_dir_rel_path + '/' + filename, encoding='utf-8') # "r") with open(gcd_dir_rel_path + '/' + filename, encoding='utf-8') as file:
dot = file.read() dot = file.read()
self._check_brackets(dot) self._check_brackets(dot)
comments = [m for m in re.finditer(r'\".*\"', dot)] comments = [m for m in re.finditer(r'\".*\"', dot)]
for m in comments: for m in comments:
dot = dot[:m.span()[0]] + (dot[m.span()[0]:m.span()[1]]).replace(' ', '\0') + dot[m.span()[1]:] dot = dot[:m.span()[0]] + (dot[m.span()[0]:m.span()[1]]).replace(' ', '\0') + dot[m.span()[1]:]
dot = re.sub(r"[ \t\r]", "", dot) # deleting all spaces dot = re.sub(r"[ \t\r]", "", dot) # deleting all spaces
dot = re.sub(r"((digraph)|}|{)", "", dot) dot = re.sub(r"((digraph)|}|{)", "", dot)
dot = re.sub(r"\/\/.*", "", dot) dot = re.sub(r"\/\/.*", "", dot)
dot = re.sub(r"^\n$", "", dot) dot = re.sub(r"^\n$", "", dot)
dotlines = dot.splitlines() dotlines = dot.splitlines()
dotlines = list(filter(None, dotlines)) dotlines = list(filter(None, dotlines))
self.fact.name = dotlines[0] self.fact.name = dotlines[0]
dotlines = dotlines[1:] dotlines = dotlines[1:]
# ent_re - regular expr for edges, states, functions properties # ent_re - regular expr for edges, states, functions properties
ent_re = re.compile(r"^\w+\[.*\]$") ent_re = re.compile(r"^\w+\[.*\]$")
# top_re - regular expr for topology properties, most time consuming one # top_re - regular expr for topology properties, most time consuming one
top_re = re.compile(r"^(\w+,?)+(->|=>)(\w+,?)+(\[(\w+=(\(?\w+,?\)?)+,?)+\])?") top_re = re.compile(r"^(\w+,?)+(->|=>)(\w+,?)+(\[(\w+=(\(?\w+,?\)?)+,?)+\])?")
# (r"^\w[\w\s,]*(->|=>)\s*\w[\w\s,=\[\]()]*$") # (r"^\w[\w\s,]*(->|=>)\s*\w[\w\s,=\[\]()]*$")
for i, ln in enumerate(dotlines): for i, ln in enumerate(dotlines):
if ent_re.match(ln): if ent_re.match(ln):
name, parm = self._param_from_entln(ln) name, parm = self._param_from_entln(ln)
self.fact.entities[name] = parm self.fact.entities[name] = parm
elif top_re.match(ln): elif top_re.match(ln):
self._topology(ln) self._topology(ln)
return self.fact.build(Parser.subgr_count) return self.fact.build(Parser.subgr_count)
checked = [] checked = []
...@@ -342,8 +342,9 @@ class Parser(): ...@@ -342,8 +342,9 @@ class Parser():
else: else:
f = open(self.fact.name + ".cpp", "w") f = open(self.fact.name + ".cpp", "w")
print(Template(filename=os.path.abspath("../pycomsdk/cpp/template.cpp")).render(preds=preds, morphs=morphs, print(Template(filename=os.path.abspath("../pycomsdk/cpp/template.cpp")).render(preds=preds, morphs=morphs,
sels=sels, states=st, sels=sels, states=st,
body=body), file=f) body=body), file=f)
f.close()
return f return f
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment