33 lignes
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			33 lignes
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| 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
 | |
|         
 | |
| def caml(s, start=0) :
 | |
|     try :
 | |
|         pos_let = s.index("\nlet", start)
 | |
|         fin = s.index(r";;", pos_let)
 | |
|         print(s[pos_let:fin+3])
 | |
|         if s[pos_let+4:].startswith(" rec") :
 | |
|             delta = 5
 | |
|         else :
 | |
|             delta = 0
 | |
|         pos_nom = s.index(" ", pos_let + delta) + 1
 | |
|         fin_nom = s.index(" ", pos_nom)
 | |
|         nom = s[pos_nom:fin_nom]
 | |
|         print(nom)
 | |
|         news = s[:pos_let] + "(*** " + nom + " ***)" + s[pos_let:fin+3] + "(*** " + nom + "_fin ***)\n" + s[fin+3:]
 | |
|         return caml(news, fin + 3 + len("(*** " + nom + " ***)")+ len("(*** " + nom + "_fin ***)\n"))
 | |
|     except ValueError :
 | |
|         return s | 
