src/Pure/ProofGeneral/pgml.ML
author chaieb
Wed, 31 Oct 2007 12:19:41 +0100
changeset 25252 833abbc3e733
parent 24584 01e83ffa6c54
child 26548 41bbcaf3e481
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24584
01e83ffa6c54 fixed title
haftmann
parents: 23748
diff changeset
     1
(*  Title:      Pure/ProofGeneral/pgml.ML
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
     2
    ID:         $Id$
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
     3
    Author:     David Aspinall
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
     4
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
     5
PGIP abstraction: PGML 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
     6
*)
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
     7
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
     8
signature PGML =
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
     9
sig
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    10
    type pgmlsym = { name: string, content: string }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    11
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    12
    datatype pgmlatom = Sym of pgmlsym | Str of string
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    13
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    14
    datatype pgmlorient = HOVOrient | HOrient | VOrient | HVOrient
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    15
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    16
    datatype pgmlplace = Subscript | Superscript | Above | Below 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    17
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    18
    datatype pgmldec = Bold | Italic | Error | Warning | Info | Other of string
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    19
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    20
    datatype pgmlaction = Toggle | Button | Menu
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    21
					    
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    22
    datatype pgmlterm = 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    23
	     Atoms of { kind: string option, content: pgmlatom list }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    24
	   | Box of { orient: pgmlorient option, indent: int option, content: pgmlterm list }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    25
	   | Break of { mandatory: bool option, indent: int option }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    26
	   | Subterm of { kind: string option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    27
			  param: string option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    28
			  place: pgmlplace option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    29
			  name: string option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    30
			  decoration: pgmldec option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    31
			  action: pgmlaction option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    32
			  pos: string option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    33
			  xref: PgipTypes.pgipurl option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    34
			  content: pgmlterm list }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    35
	   | Alt of { kind: string option, content: pgmlterm list }
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    36
	   | Embed of XML.content
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    37
	   | Raw of XML.tree
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    38
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    39
    datatype pgml = 
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    40
	     Pgml of { version: string option, systemid: string option, 
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    41
		       area: PgipTypes.displayarea option, 
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    42
		       content: pgmlterm list }
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    43
		       
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    44
    val pgmlterm_to_xml : pgmlterm -> XML.tree
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    45
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    46
    val pgml_to_xml : pgml -> XML.tree
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    47
end
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    48
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    49
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    50
structure Pgml : PGML =
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    51
struct
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    52
    open PgipTypes
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    53
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    54
    type pgmlsym = { name: string, content: string }
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    55
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    56
    datatype pgmlatom = Sym of pgmlsym | Str of string
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    57
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    58
    datatype pgmlorient = HOVOrient | HOrient | VOrient | HVOrient
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    59
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    60
    datatype pgmlplace = Subscript | Superscript | Above | Below 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    61
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    62
    datatype pgmldec = Bold | Italic | Error | Warning | Info | Other of string
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    63
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    64
    datatype pgmlaction = Toggle | Button | Menu
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    65
					    
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    66
    datatype pgmlterm = 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    67
	     Atoms of { kind: string option, content: pgmlatom list }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    68
	   | Box of { orient: pgmlorient option, indent: int option, content: pgmlterm list }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    69
	   | Break of { mandatory: bool option, indent: int option }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    70
	   | Subterm of { kind: string option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    71
			  param: string option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    72
			  place: pgmlplace option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    73
			  name: string option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    74
			  decoration: pgmldec option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    75
			  action: pgmlaction option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    76
			  pos: string option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    77
			  xref: PgipTypes.pgipurl option,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    78
			  content: pgmlterm list }
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    79
	   | Alt of { kind: string option, content: pgmlterm list }
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    80
	   | Embed of XML.content
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    81
	   | Raw of XML.tree
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    82
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    83
		       
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    84
    datatype pgml = 
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    85
	     Pgml of { version: string option, systemid: string option, 
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    86
		       area: PgipTypes.displayarea option, 
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
    87
		       content: pgmlterm list }
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    88
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    89
    fun pgmlorient_to_string HOVOrient = "hov"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    90
      | pgmlorient_to_string HOrient = "h"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    91
      | pgmlorient_to_string VOrient = "v"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    92
      | pgmlorient_to_string HVOrient = "hv"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    93
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    94
    fun pgmlplace_to_string Subscript = "sub"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    95
      | pgmlplace_to_string Superscript = "sup"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    96
      | pgmlplace_to_string Above = "above"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    97
      | pgmlplace_to_string Below = "below"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    98
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
    99
    fun pgmldec_to_string Bold = "bold"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   100
      | pgmldec_to_string Italic = "italic"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   101
      | pgmldec_to_string Error = "error"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   102
      | pgmldec_to_string Warning = "warning"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   103
      | pgmldec_to_string Info = "info"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   104
      | pgmldec_to_string (Other s) = "other"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   105
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   106
    fun pgmlaction_to_string Toggle = "toggle"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   107
      | pgmlaction_to_string Button = "button"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   108
      | pgmlaction_to_string Menu = "menu"
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   109
23610
5ade06703b07 Produce good PGML 2.0
aspinall
parents: 23589
diff changeset
   110
    (* NOTE: we assume strings are already XML escaped here, for convenience in Isabelle; 
5ade06703b07 Produce good PGML 2.0
aspinall
parents: 23589
diff changeset
   111
       would be better not to *)
23723
4fff46d5faaa renamed XML.Rawtext to XML.Output;
wenzelm
parents: 23610
diff changeset
   112
    fun atom_to_xml (Sym {name,content}) = XML.Elem("sym",attr name name,[XML.Output content])
4fff46d5faaa renamed XML.Rawtext to XML.Output;
wenzelm
parents: 23610
diff changeset
   113
      | atom_to_xml (Str str) = XML.Output str 
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   114
						    
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   115
    fun pgmlterm_to_xml (Atoms {kind, content}) = 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   116
	XML.Elem("atom",opt_attr "kind" kind, map atom_to_xml content)
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   117
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   118
      | pgmlterm_to_xml (Box {orient, indent, content}) =
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   119
	XML.Elem("box", 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   120
		 opt_attr_map pgmlorient_to_string "orient" orient @
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   121
		 opt_attr_map int_to_pgstring "indent" indent,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   122
		 map pgmlterm_to_xml content)
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   123
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   124
      | pgmlterm_to_xml (Break {mandatory, indent}) =
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   125
	XML.Elem("break",
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   126
		 opt_attr_map bool_to_pgstring "mandatory" mandatory @
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   127
		 opt_attr_map int_to_pgstring "indent" indent, [])
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   128
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   129
      | pgmlterm_to_xml (Subterm {kind, param, place, name, decoration, action, pos, xref, content}) =
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   130
	XML.Elem("subterm", 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   131
  		 opt_attr "kind" kind @
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   132
		 opt_attr "param" param @
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   133
		 opt_attr_map pgmlplace_to_string "place" place @
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   134
		 opt_attr "name" name @ 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   135
		 opt_attr_map pgmldec_to_string "decoration" decoration @
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   136
		 opt_attr_map pgmlaction_to_string "action" action @ 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   137
		 opt_attr "pos" pos @
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   138
		 opt_attr_map string_of_pgipurl "xref" xref,
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   139
		 map pgmlterm_to_xml content)
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   140
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   141
      | pgmlterm_to_xml (Alt {kind, content}) = 
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   142
	XML.Elem("alt", opt_attr "kind" kind, map pgmlterm_to_xml content)
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   143
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   144
      | pgmlterm_to_xml (Embed xmls) = XML.Elem("embed", [], xmls)
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   145
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   146
      | pgmlterm_to_xml (Raw xml) = xml
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   147
23748
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   148
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   149
    datatype pgml = 
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   150
	     Pgml of { version: string option, systemid: string option, 
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   151
		       area: PgipTypes.displayarea option, 
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   152
		       content: pgmlterm list }
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   153
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   154
    fun pgml_to_xml (Pgml {version,systemid,area,content}) = 
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   155
	XML.Elem("pgml",
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   156
		 opt_attr "version" version @ 
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   157
		 opt_attr "systemid" systemid @
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   158
		 Option.getOpt(Option.map PgipTypes.attrs_of_displayarea area,[]),
1ff6b562076f Track schema changes: add area attribute to pgml packet. Also add quoted Raw element [hack for Isabelle bottom-up XML production]
aspinall
parents: 23723
diff changeset
   159
		 map pgmlterm_to_xml content)
23571
0cd175710a93 PGML abstraction, draft version
aspinall
parents:
diff changeset
   160
end