Update devuldertex2latex.py
Cette révision appartient à :
@@ -23,12 +23,24 @@ def automate(s) :
|
|||||||
bounding_box = (x, y)
|
bounding_box = (x, y)
|
||||||
intro.setParseAction(assign_bb)
|
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
|
# letstate
|
||||||
etats = {}
|
etats = {}
|
||||||
|
etats_alias = {}
|
||||||
def do_letstate(s, l, toks) :
|
def do_letstate(s, l, toks) :
|
||||||
id, x, y = toks
|
id, x, y = toks
|
||||||
nonlocal etats
|
nonlocal etats, curstatediam, etats_alias
|
||||||
etats[id] = {"id": id, "posx": x, "posy": y, "initial": False, "accepting": False, "label": ""}
|
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)
|
letstate = (r"\letstate " + ident + "=(" + integer + "," + integer + ")").setParseAction(do_letstate)
|
||||||
|
|
||||||
# catégories d'états
|
# catégories d'états
|
||||||
@@ -47,24 +59,30 @@ def automate(s) :
|
|||||||
transitions = []
|
transitions = []
|
||||||
def do_trans(toks) :
|
def do_trans(toks) :
|
||||||
nature, indication, orig, dest, label = toks
|
nature, indication, orig, dest, label = toks
|
||||||
nonlocal transitions
|
nonlocal transitions, etats_alias
|
||||||
if "curved" in nature :
|
if "curved" in nature :
|
||||||
bend = True
|
bend = True
|
||||||
else :
|
else :
|
||||||
bend = False
|
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})
|
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)
|
trans = (pyp.oneOf(["\\drawcurvedtrans", "\\drawtrans", "\\drawedge"]) + pyp.Optional("["+ident+"]", default=None) + "(" + ident + "," + ident + ")" + maybelabel).setParseAction(do_trans)
|
||||||
|
|
||||||
boucles = []
|
boucles = []
|
||||||
def do_loop(toks) :
|
def do_loop(toks) :
|
||||||
indication, etat, label = 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})
|
boucles.append({"indication":indication, "orig":etat, "label":label})
|
||||||
loop = ("\\drawloop" + pyp.Optional("[" + ident + "]", default=None) + "(" + ident + ")" + maybelabel).setParseAction(do_loop)
|
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}")
|
outro = pyp.Suppress(r"\end{picture}")
|
||||||
|
|
||||||
|
|||||||
Référencer dans un nouveau ticket
Bloquer un utilisateur