gérer le cas de plusieurs fonctions de même nom

Cette révision appartient à :
Yann Salmon
2022-02-22 09:36:25 +01:00
Parent 34badcee03
révision 6b38d2f986

Voir le fichier

@@ -1,16 +1,22 @@
import os import os, shutil
def extraire_caml(nf_tex, nf_ml, nf_texo, tag) : def extraire_caml(nf_tex, mlref, nf_texo, tag) :
nf_tex = nf_tex.replace("file://", "") nf_tex = nf_tex.replace("file://", "")
nf_ml = nf_ml.replace("file://", "") nf_ml = os.path.join(os.path.dirname(nf_tex), mlref)
nf_texo = nf_texo.replace("file://", "") nf_texo = nf_texo.replace("file://", "")
output_tex = open(nf_texo, "w") output_tex = open(nf_texo, "w")
output_ml = open(nf_ml, "w") output_ml = open(nf_ml, "w")
incode = False incode = False
nomfonc = "" nomfonc = ""
complement = None complement = None
numfoncAnon = 0 compteursNoms = {}
mlref = os.path.basename(nf_ml) def setNom(s) :
if s not in compteursNoms :
compteursNoms[s] = 0
return s
else :
compteursNoms[s] += 1
return "{}__{}".format(s, compteursNoms[s])
for l in open(nf_tex) : for l in open(nf_tex) :
lstrip = l.strip() lstrip = l.strip()
if lstrip.startswith(r"\begin{"+tag+"}") : if lstrip.startswith(r"\begin{"+tag+"}") :
@@ -29,9 +35,9 @@ def extraire_caml(nf_tex, nf_ml, nf_texo, tag) :
if nomfonc.startswith("rec ") : if nomfonc.startswith("rec ") :
nomfonc = nomfonc[4:] nomfonc = nomfonc[4:]
nomfonc = nomfonc.split()[0] nomfonc = nomfonc.split()[0]
nomfonc = setNom(nomfonc)
else : else :
nomfonc = "anon" + str(numfoncAnon) nomfonc = setNom("anon")
numfoncAnon += 1
output_ml.write("(*** " + nomfonc + " ***)\n") output_ml.write("(*** " + nomfonc + " ***)\n")
if lstrip == r"\end{"+tag+"}" : if lstrip == r"\end{"+tag+"}" :
output_ml.write("(*** " + nomfonc + "_fin ***)\n\n") output_ml.write("(*** " + nomfonc + "_fin ***)\n\n")