src/Pure/term_xml.scala
author wenzelm
Thu Aug 15 16:02:47 2019 +0200 (7 months ago)
changeset 70533 031620901fcd
parent 43779 47bec02c6762
child 70536 fe4d545f12e3
permissions -rw-r--r--
support for (fully reconstructed) proof terms in Scala;
proper cache_typs;
wenzelm@43779
     1
/*  Title:      Pure/term_xml.scala
wenzelm@43779
     2
    Author:     Makarius
wenzelm@43779
     3
wenzelm@43779
     4
XML data representation of lambda terms.
wenzelm@43779
     5
*/
wenzelm@43779
     6
wenzelm@43779
     7
package isabelle
wenzelm@43779
     8
wenzelm@43779
     9
wenzelm@43779
    10
object Term_XML
wenzelm@43779
    11
{
wenzelm@43779
    12
  import Term._
wenzelm@43779
    13
wenzelm@43779
    14
  object Encode
wenzelm@43779
    15
  {
wenzelm@43779
    16
    import XML.Encode._
wenzelm@43779
    17
wenzelm@43779
    18
    val sort: T[Sort] = list(string)
wenzelm@43779
    19
wenzelm@43779
    20
    def typ: T[Typ] =
wenzelm@43779
    21
      variant[Typ](List(
wenzelm@43779
    22
        { case Type(a, b) => (List(a), list(typ)(b)) },
wenzelm@43779
    23
        { case TFree(a, b) => (List(a), sort(b)) },
wenzelm@43779
    24
        { case TVar((a, b), c) => (List(a, int_atom(b)), sort(c)) }))
wenzelm@43779
    25
wenzelm@43779
    26
    def term: T[Term] =
wenzelm@43779
    27
      variant[Term](List(
wenzelm@43779
    28
        { case Const(a, b) => (List(a), typ(b)) },
wenzelm@43779
    29
        { case Free(a, b) => (List(a), typ(b)) },
wenzelm@43779
    30
        { case Var((a, b), c) => (List(a, int_atom(b)), typ(c)) },
wenzelm@43779
    31
        { case Bound(a) => (List(int_atom(a)), Nil) },
wenzelm@43779
    32
        { case Abs(a, b, c) => (List(a), pair(typ, term)(b, c)) },
wenzelm@43779
    33
        { case App(a, b) => (Nil, pair(term, term)(a, b)) }))
wenzelm@43779
    34
  }
wenzelm@43779
    35
wenzelm@43779
    36
  object Decode
wenzelm@43779
    37
  {
wenzelm@43779
    38
    import XML.Decode._
wenzelm@43779
    39
wenzelm@43779
    40
    val sort: T[Sort] = list(string)
wenzelm@43779
    41
wenzelm@43779
    42
    def typ: T[Typ] =
wenzelm@43779
    43
      variant[Typ](List(
wenzelm@43779
    44
        { case (List(a), b) => Type(a, list(typ)(b)) },
wenzelm@43779
    45
        { case (List(a), b) => TFree(a, sort(b)) },
wenzelm@43779
    46
        { case (List(a, b), c) => TVar((a, int_atom(b)), sort(c)) }))
wenzelm@43779
    47
wenzelm@43779
    48
    def term: T[Term] =
wenzelm@43779
    49
      variant[Term](List(
wenzelm@43779
    50
        { case (List(a), b) => Const(a, typ(b)) },
wenzelm@43779
    51
        { case (List(a), b) => Free(a, typ(b)) },
wenzelm@43779
    52
        { case (List(a, b), c) => Var((a, int_atom(b)), typ(c)) },
wenzelm@43779
    53
        { case (List(a), Nil) => Bound(int_atom(a)) },
wenzelm@43779
    54
        { case (List(a), b) => val (c, d) = pair(typ, term)(b); Abs(a, c, d) },
wenzelm@43779
    55
        { case (Nil, a) => val (b, c) = pair(term, term)(a); App(b, c) }))
wenzelm@70533
    56
wenzelm@70533
    57
    def proof: T[Proof] =
wenzelm@70533
    58
      variant[Proof](List(
wenzelm@70533
    59
        { case (Nil, Nil) => MinProof },
wenzelm@70533
    60
        { case (List(a), Nil) => PBound(int_atom(a)) },
wenzelm@70533
    61
        { case (List(a), b) => val (c, d) = pair(typ, proof)(b); Abst(a, c, d) },
wenzelm@70533
    62
        { case (List(a), b) => val (c, d) = pair(term, proof)(b); AbsP(a, c, d) },
wenzelm@70533
    63
        { case (Nil, a) => val (b, c) = pair(proof, term)(a); Appt(b, c) },
wenzelm@70533
    64
        { case (Nil, a) => val (b, c) = pair(proof, proof)(a); AppP(b, c) },
wenzelm@70533
    65
        { case (Nil, a) => Hyp(term(a)) },
wenzelm@70533
    66
        { case (List(a), b) => PAxm(a, list(typ)(b)) },
wenzelm@70533
    67
        { case (List(a), b) => OfClass(typ(b), a) },
wenzelm@70533
    68
        { case (List(a), b) => val (c, d) = pair(term, list(typ))(b); Oracle(a, c, d) },
wenzelm@70533
    69
        { case (List(a, b), c) => PThm(long_atom(a), b, list(typ)(c)) }))
wenzelm@43779
    70
  }
wenzelm@43779
    71
}