author | gagern |
Mon, 31 Mar 2008 23:29:36 +0200 | |
changeset 26505 | 49967f8b1068 |
parent 24611 | 1f92518fbabe |
child 26886 | d43264d547f8 |
permissions | -rw-r--r-- |
webertj@23207 | 1 |
(* Title: Admin/isatest/annomaly.ML |
webertj@23207 | 2 |
ID: $Id$ |
webertj@23207 | 3 |
Author: Martin von Gagern <martin@von-gagern.net> |
webertj@23207 | 4 |
*) |
webertj@23207 | 5 |
|
webertj@23207 | 6 |
use "ML-Systems/smlnj.ML"; |
gagern@22488 | 7 |
|
gagern@22488 | 8 |
local |
gagern@22488 | 9 |
|
gagern@22488 | 10 |
val smlnj_use_text = use_text |
gagern@22488 | 11 |
|
gagern@26505 | 12 |
val smlnj_use_file = use_file |
gagern@22488 | 13 |
|
gagern@26505 | 14 |
val smlnj_forget_structure = forget_structure |
gagern@26505 | 15 |
|
gagern@26505 | 16 |
fun mkAbsolute path = |
gagern@26505 | 17 |
OS.Path.mkAbsolute { path = path, relativeTo = OS.FileSys.getDir () } |
gagern@26505 | 18 |
|
gagern@26505 | 19 |
fun toArcs path = #arcs (OS.Path.fromString path) |
gagern@26505 | 20 |
|
gagern@26505 | 21 |
val isabelleHome = |
gagern@26505 | 22 |
case OS.Process.getEnv "ISABELLE_HOME" |
gagern@26505 | 23 |
of NONE => OS.FileSys.getDir () |
gagern@26505 | 24 |
| SOME home => mkAbsolute home |
gagern@26505 | 25 |
|
gagern@26505 | 26 |
fun noparent [] = [] |
gagern@26505 | 27 |
| noparent (n :: ns) = |
gagern@26505 | 28 |
if n = OS.Path.parentArc then noparent ns else n :: noparent ns |
gagern@26505 | 29 |
|
gagern@26505 | 30 |
fun isabellePath [] = [] |
gagern@26505 | 31 |
| isabellePath ("src" :: name) = "Isabelle" :: name |
gagern@26505 | 32 |
| isabellePath (name as (n :: ns)) = |
gagern@26505 | 33 |
if n = OS.Path.parentArc then noparent ns else "Isabelle" :: name |
gagern@26505 | 34 |
|
gagern@26505 | 35 |
fun rewrite defPrefix name = |
gagern@26505 | 36 |
let val abs = mkAbsolute name |
gagern@26505 | 37 |
val rel = OS.Path.mkRelative { path = abs, relativeTo = isabelleHome } |
gagern@26505 | 38 |
val exists = (OS.FileSys.access(abs, nil) |
gagern@26505 | 39 |
handle OS.SysErr _ => false) |
gagern@26505 | 40 |
in if exists andalso rel <> "" |
gagern@26505 | 41 |
then isabellePath (toArcs rel) |
gagern@26505 | 42 |
else defPrefix @ noparent (toArcs name) |
gagern@26505 | 43 |
end handle OS.Path.Path => defPrefix @ noparent (toArcs name) |
gagern@22488 | 44 |
|
gagern@22488 | 45 |
in |
gagern@22488 | 46 |
|
gagern@26505 | 47 |
fun use_text tune (line, name) p v t = |
webertj@23207 | 48 |
let val name = case name of "" => "unnamed" | name => name |
gagern@26505 | 49 |
val arcs = rewrite ["use_text"] name |
gagern@26505 | 50 |
(* should we have different files for different line numbers? * |
gagern@26505 | 51 |
val arcs = if line <= 1 then arcs |
gagern@26505 | 52 |
else arcs @ [ "l." ^ Int.toString line ] |
gagern@26505 | 53 |
*) |
gagern@26505 | 54 |
val arcs = if t = "structure Isabelle =\nstruct\nend;" |
gagern@26505 | 55 |
andalso name = "ML" |
gagern@26505 | 56 |
then ["empty_Isabelle", "empty" ] else arcs |
gagern@26505 | 57 |
val _ = AnnoMaLy.nameNextStream arcs |
gagern@26505 | 58 |
in smlnj_use_text tune (line, name) p v t end; |
gagern@26505 | 59 |
|
gagern@26505 | 60 |
fun use_file tune output verbose name = |
gagern@26505 | 61 |
let val arcs = rewrite ["use_file"] name |
gagern@26505 | 62 |
val _ = AnnoMaLy.nameNextStream arcs |
gagern@26505 | 63 |
in smlnj_use_file tune output verbose name end; |
gagern@26505 | 64 |
|
gagern@26505 | 65 |
fun forget_structure name = |
gagern@26505 | 66 |
let val arcs = [ "forget_structure", name ] |
gagern@26505 | 67 |
val _ = AnnoMaLy.nameNextStream arcs |
gagern@26505 | 68 |
in smlnj_forget_structure name end; |
gagern@22488 | 69 |
|
gagern@22488 | 70 |
end; |