Update devuldertex2latex.py
Cette révision appartient à :
@@ -23,12 +23,24 @@ def automate(s) :
|
||||
bounding_box = (x, y)
|
||||
intro.setParseAction(assign_bb)
|
||||
|
||||
# parfois, le double cercle des états acceptants est réalisé en superposant deux états de diamètres différents
|
||||
curstatediam = None
|
||||
def do_setstatediam(toks) :
|
||||
nonlocal curstatediam
|
||||
curstatediam = toks[0]
|
||||
statediam = ("\\setstatediam"+"{"+integer+"}").setParseAction(do_setstatediam)
|
||||
|
||||
# letstate
|
||||
etats = {}
|
||||
etats_alias = {}
|
||||
def do_letstate(s, l, toks) :
|
||||
id, x, y = toks
|
||||
nonlocal etats
|
||||
etats[id] = {"id": id, "posx": x, "posy": y, "initial": False, "accepting": False, "label": ""}
|
||||
nonlocal etats, curstatediam, etats_alias
|
||||
for ancien in [e for e in etats.values() if e["posx"] == x and e["posy"] == y and e["statediam"] != curstatediam] :
|
||||
ancien["accepting"] = True
|
||||
etats_alias[id] = ancien["id"]
|
||||
return
|
||||
etats[id] = {"id": id, "posx": x, "posy": y, "initial": False, "accepting": False, "label": "", "statediam" : curstatediam}
|
||||
letstate = (r"\letstate " + ident + "=(" + integer + "," + integer + ")").setParseAction(do_letstate)
|
||||
|
||||
# catégories d'états
|
||||
@@ -47,24 +59,30 @@ def automate(s) :
|
||||
transitions = []
|
||||
def do_trans(toks) :
|
||||
nature, indication, orig, dest, label = toks
|
||||
nonlocal transitions
|
||||
nonlocal transitions, etats_alias
|
||||
if "curved" in nature :
|
||||
bend = True
|
||||
else :
|
||||
bend = False
|
||||
orig = etats_alias.get(orig, orig)
|
||||
dest = etats_alias.get(dest, dest)
|
||||
transitions.append({"orig": orig, "dest": dest, "label": label, "bend": bend, "indication":indication})
|
||||
trans = (pyp.oneOf(["\\drawcurvedtrans", "\\drawtrans", "\\drawedge"]) + pyp.Optional("["+ident+"]", default=None) + "(" + ident + "," + ident + ")" + maybelabel).setParseAction(do_trans)
|
||||
|
||||
boucles = []
|
||||
def do_loop(toks) :
|
||||
indication, etat, label = toks
|
||||
nonlocal boucles
|
||||
nonlocal boucles, etats_alias
|
||||
etat = etats_alias.get(etat, etat)
|
||||
boucles.append({"indication":indication, "orig":etat, "label":label})
|
||||
loop = ("\\drawloop" + pyp.Optional("[" + ident + "]", default=None) + "(" + ident + ")" + maybelabel).setParseAction(do_loop)
|
||||
|
||||
ignorer = ("\\setprofcurve" + "{" + integer + "}") | ("\\setloopdiam" + "{" + integer + "}") | ("\\setstatediam"+"{"+integer+"}")
|
||||
|
||||
statement = letstate | drawstate | trans | loop | ignorer.suppress()
|
||||
|
||||
ignorer = ("\\setprofcurve" + "{" + integer + "}") | ("\\setloopdiam" + "{" + integer + "}")
|
||||
|
||||
|
||||
statement = letstate | drawstate | trans | loop | statediam | ignorer.suppress()
|
||||
|
||||
outro = pyp.Suppress(r"\end{picture}")
|
||||
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur