author | wenzelm |
Thu, 10 Oct 2019 16:51:47 +0200 | |
changeset 70828 | cb70d84a9f5e |
parent 70784 | 799437173553 |
child 70834 | 614ca81fa28e |
permissions | -rw-r--r-- |
43779 | 1 |
/* Title: Pure/term_xml.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
XML data representation of lambda terms. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
object Term_XML |
|
11 |
{ |
|
12 |
import Term._ |
|
13 |
||
14 |
object Encode |
|
15 |
{ |
|
16 |
import XML.Encode._ |
|
17 |
||
70828 | 18 |
val indexname: P[Indexname] = |
19 |
{ case Indexname(a, 0) => List(a) |
|
20 |
case Indexname(a, b) => List(a, int_atom(b)) } |
|
21 |
||
43779 | 22 |
val sort: T[Sort] = list(string) |
23 |
||
70828 | 24 |
def typ_raw: T[Typ] = |
43779 | 25 |
variant[Typ](List( |
70828 | 26 |
{ case Type(a, b) => (List(a), list(typ_raw)(b)) }, |
43779 | 27 |
{ case TFree(a, b) => (List(a), sort(b)) }, |
70828 | 28 |
{ case TVar(a, b) => (indexname(a), sort(b)) })) |
29 |
||
30 |
val typ: T[Typ] = |
|
31 |
{ case t => option(typ_raw)(if (t == dummyT) None else Some(t)) } |
|
43779 | 32 |
|
33 |
def term: T[Term] = |
|
34 |
variant[Term](List( |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70559
diff
changeset
|
35 |
{ case Const(a, b) => (List(a), list(typ)(b)) }, |
43779 | 36 |
{ case Free(a, b) => (List(a), typ(b)) }, |
70828 | 37 |
{ case Var(a, b) => (indexname(a), typ(b)) }, |
43779 | 38 |
{ case Bound(a) => (List(int_atom(a)), Nil) }, |
39 |
{ case Abs(a, b, c) => (List(a), pair(typ, term)(b, c)) }, |
|
40 |
{ case App(a, b) => (Nil, pair(term, term)(a, b)) })) |
|
41 |
} |
|
42 |
||
43 |
object Decode |
|
44 |
{ |
|
45 |
import XML.Decode._ |
|
46 |
||
70828 | 47 |
val indexname: P[Indexname] = |
48 |
{ case List(a) => Indexname(a, 0) |
|
49 |
case List(a, b) => Indexname(a, int_atom(b)) } |
|
50 |
||
43779 | 51 |
val sort: T[Sort] = list(string) |
52 |
||
70828 | 53 |
def typ_raw: T[Typ] = |
43779 | 54 |
variant[Typ](List( |
70828 | 55 |
{ case (List(a), b) => Type(a, list(typ_raw)(b)) }, |
43779 | 56 |
{ case (List(a), b) => TFree(a, sort(b)) }, |
70828 | 57 |
{ case (a, b) => TVar(indexname(a), sort(b)) })) |
58 |
||
59 |
def typ(body: XML.Body): Typ = option(typ_raw)(body).getOrElse(dummyT) |
|
43779 | 60 |
|
61 |
def term: T[Term] = |
|
62 |
variant[Term](List( |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70559
diff
changeset
|
63 |
{ case (List(a), b) => Const(a, list(typ)(b)) }, |
43779 | 64 |
{ case (List(a), b) => Free(a, typ(b)) }, |
70828 | 65 |
{ case (a, b) => Var(indexname(a), typ(b)) }, |
43779 | 66 |
{ case (List(a), Nil) => Bound(int_atom(a)) }, |
67 |
{ case (List(a), b) => val (c, d) = pair(typ, term)(b); Abs(a, c, d) }, |
|
68 |
{ case (Nil, a) => val (b, c) = pair(term, term)(a); App(b, c) })) |
|
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
69 |
|
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
70 |
def proof: T[Proof] = |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
71 |
variant[Proof](List( |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
72 |
{ case (Nil, Nil) => MinProof }, |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
73 |
{ case (List(a), Nil) => PBound(int_atom(a)) }, |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
74 |
{ case (List(a), b) => val (c, d) = pair(typ, proof)(b); Abst(a, c, d) }, |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
75 |
{ case (List(a), b) => val (c, d) = pair(term, proof)(b); AbsP(a, c, d) }, |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
76 |
{ case (Nil, a) => val (b, c) = pair(proof, term)(a); Appt(b, c) }, |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
77 |
{ case (Nil, a) => val (b, c) = pair(proof, proof)(a); AppP(b, c) }, |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
78 |
{ case (Nil, a) => Hyp(term(a)) }, |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
79 |
{ case (List(a), b) => PAxm(a, list(typ)(b)) }, |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
43779
diff
changeset
|
80 |
{ case (List(a), b) => OfClass(typ(b), a) }, |
70559 | 81 |
{ case (List(a), b) => val (c, d) = pair(option(term), list(typ))(b); Oracle(a, c, d) }, |
70538
fc9ba6fe367f
clarified PThm: theory_name simplifies retrieval from exports;
wenzelm
parents:
70536
diff
changeset
|
82 |
{ case (List(a, b, c), d) => PThm(long_atom(a), b, c, list(typ)(d)) })) |
43779 | 83 |
} |
84 |
} |