Cette révision appartient à :
Yann Salmon
2021-02-07 21:24:57 +01:00
Parent 8c401ac973
révision 083a1c0fb2

Voir le fichier

@@ -1,19 +1,33 @@
def code(s) : import os
try :
debut = s.index(r"\begin{tabbing}") def extraire_caml(nf_tex, nf_ml, nf_texo, tag) :
fin = s.index(r"\end{tabbing}") output_tex = open(nf_texo, "w")
pos_let = s.index("let", debut) output_ml = open(nf_ml, "w")
if s[pos_let+3:].startswith(" rec") : incode = False
pos_let = pos_let + 4 nomfonc = ""
pos_nom = s.index(" ", pos_let) + 1 mlref = os.path.basename(nf_ml)
fin_nom = s.index(" ", pos_nom) for l in open(nf_tex) :
nom = s[pos_nom:fin_nom] lstrip = l.strip()
repl = r"\lstinputcaml[linerange="+nom+"-"+nom+"_fin]{ccp2004.ml}\n" if lstrip == r"\begin{"+tag+"}" :
news = s[:debut] + repl + s[fin + len(r"\end{tabbing}"):] incode = True
return code(news) nomfonc = ""
except ValueError : continue
return s if incode :
if nomfonc == "" and "let" in lstrip :
nomfonc = l[4:]
if nomfonc.startswith("rec ") :
nomfonc = nomfonc[4:]
nomfonc = nomfonc.split()[0]
output_ml.write("(*** " + nomfonc + " ***)\n")
if lstrip == r"\end{"+tag+"}" :
output_ml.write("(*** " + nomfonc + "_fin ***)\n\n")
output_tex.write(r"\lstinputcaml[linerange="+nomfonc+"-"+nomfonc+"_fin]{"+ mlref + "}\n")
incode = False
continue
output_ml.write(l)
else :
output_tex.write(l)
def caml(s, start=0) : def caml(s, start=0) :
try : try :
pos_let = s.index("\nlet", start) pos_let = s.index("\nlet", start)