Commit 3b1e99df authored by Savva Golubitsky's avatar Savva Golubitsky

First parser implementation

parent 1b6fe950
import re
from typing import NamedTuple
from enum import Enum, auto
# Ключевые слова, описывающие граф
scope = [
"__BEGIN__",
"__END__"
]
class Stmt():
__slots__=(
'name',
'module',
'entry_func',
'predicate',
'selector',
'function',
'morphism',
'parallelism'
)
def __init__(self, name):
for slot in self.__slots__:
setattr(self, slot, None)
self.name = name
def __str__(self):
stri = ""
for s in self.__slots__:
stri += s+": {}, ".format(getattr(self, s))
return stri
# ent = [{"name":{"module":"val" , "entr_func":"val"...}}]
dotfile = open("./testgr.adot", "r").read()
graphcheck = re.match(r"\A(digraph)\s+\w*\n{(.*\s)*}\Z", dotfile)
if graphcheck is None:
print("Incorrect graph, check syntax!")
exit()
# Все что до __BEGIN__ считается объявлением
beg = re.search((scope[0]), dotfile).start()
stmts = []
rawstmts = re.findall(r"\w+\s\[.*\]", dotfile[:beg])
for raw in rawstmts:
res = raw.split(r" ", 1)
st = Stmt(res[0])
rs =res[1][1:-1].split(r", ")
for r in rs:
r=r.split(r"=", 1)
for s in st.__slots__:
if s == r[0]:
setattr(st, s, r[1])
print(st)
stmts.append(st)
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