maj
Cette révision appartient à :
@@ -1,19 +1,33 @@
|
||||
def code(s) :
|
||||
try :
|
||||
debut = s.index(r"\begin{tabbing}")
|
||||
fin = s.index(r"\end{tabbing}")
|
||||
pos_let = s.index("let", debut)
|
||||
if s[pos_let+3:].startswith(" rec") :
|
||||
pos_let = pos_let + 4
|
||||
pos_nom = s.index(" ", pos_let) + 1
|
||||
fin_nom = s.index(" ", pos_nom)
|
||||
nom = s[pos_nom:fin_nom]
|
||||
repl = r"\lstinputcaml[linerange="+nom+"-"+nom+"_fin]{ccp2004.ml}\n"
|
||||
news = s[:debut] + repl + s[fin + len(r"\end{tabbing}"):]
|
||||
return code(news)
|
||||
except ValueError :
|
||||
return s
|
||||
|
||||
import os
|
||||
|
||||
def extraire_caml(nf_tex, nf_ml, nf_texo, tag) :
|
||||
output_tex = open(nf_texo, "w")
|
||||
output_ml = open(nf_ml, "w")
|
||||
incode = False
|
||||
nomfonc = ""
|
||||
mlref = os.path.basename(nf_ml)
|
||||
for l in open(nf_tex) :
|
||||
lstrip = l.strip()
|
||||
if lstrip == r"\begin{"+tag+"}" :
|
||||
incode = True
|
||||
nomfonc = ""
|
||||
continue
|
||||
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) :
|
||||
try :
|
||||
pos_let = s.index("\nlet", start)
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur