src/HOL/ex/Multiquote.thy
author wenzelm
Mon, 11 Feb 2002 10:56:33 +0100
changeset 12873 d7f8dfaad46d
parent 11823 5a3fcd84e55e
child 14981 e73f8140af78
permissions -rw-r--r--
include SVC_Test;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/ex/Multiquote.thy
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
9297
wenzelm
parents: 8627
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
     5
*)
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
     6
10357
wenzelm
parents: 9297
diff changeset
     7
header {* Multiple nested quotations and anti-quotations *}
wenzelm
parents: 9297
diff changeset
     8
9297
wenzelm
parents: 8627
diff changeset
     9
theory Multiquote = Main:
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    10
11586
wenzelm
parents: 11020
diff changeset
    11
text {*
wenzelm
parents: 11020
diff changeset
    12
  Multiple nested quotations and anti-quotations -- basically a
wenzelm
parents: 11020
diff changeset
    13
  generalized version of de-Bruijn representation.
wenzelm
parents: 11020
diff changeset
    14
*}
wenzelm
parents: 11020
diff changeset
    15
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    16
syntax
11823
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    17
  "_quote" :: "'b => ('a => 'b)"	     ("\<guillemotleft>_\<guillemotright>" [0] 1000)
10838
9423817dee84 use \<acute>;
wenzelm
parents: 10834
diff changeset
    18
  "_antiquote" :: "('a => 'b) => 'b"         ("\<acute>_" [1000] 1000)
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    19
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    20
parse_translation {*
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    21
  let
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    22
    fun antiquote_tr i (Const ("_antiquote", _) $ (t as Const ("_antiquote", _) $ _)) =
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    23
          skip_antiquote_tr i t
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    24
      | antiquote_tr i (Const ("_antiquote", _) $ t) =
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    25
          antiquote_tr i t $ Bound i
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    26
      | antiquote_tr i (t $ u) = antiquote_tr i t $ antiquote_tr i u
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    27
      | antiquote_tr i (Abs (x, T, t)) = Abs (x, T, antiquote_tr (i + 1) t)
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    28
      | antiquote_tr _ a = a
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    29
    and skip_antiquote_tr i ((c as Const ("_antiquote", _)) $ t) =
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    30
          c $ skip_antiquote_tr i t
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    31
      | skip_antiquote_tr i t = antiquote_tr i t;
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    32
8578
wenzelm
parents: 8572
diff changeset
    33
    fun quote_tr [t] = Abs ("s", dummyT, antiquote_tr 0 (Term.incr_boundvars 1 t))
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    34
      | quote_tr ts = raise TERM ("quote_tr", ts);
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    35
  in [("_quote", quote_tr)] end
9297
wenzelm
parents: 8627
diff changeset
    36
*}
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    37
9297
wenzelm
parents: 8627
diff changeset
    38
text {* basic examples *}
11823
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    39
term "\<guillemotleft>a + b + c\<guillemotright>"
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    40
term "\<guillemotleft>a + b + c + \<acute>x + \<acute>y + 1\<guillemotright>"
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    41
term "\<guillemotleft>\<acute>(f w) + \<acute>x\<guillemotright>"
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    42
term "\<guillemotleft>f \<acute>x \<acute>y z\<guillemotright>"
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    43
9297
wenzelm
parents: 8627
diff changeset
    44
text {* advanced examples *}
11823
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    45
term "\<guillemotleft>\<guillemotleft>\<acute>\<acute>x + \<acute>y\<guillemotright>\<guillemotright>"
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    46
term "\<guillemotleft>\<guillemotleft>\<acute>\<acute>x + \<acute>y\<guillemotright> o \<acute>f\<guillemotright>"
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    47
term "\<guillemotleft>\<acute>(f o \<acute>g)\<guillemotright>"
5a3fcd84e55e guillemot syntax;
wenzelm
parents: 11586
diff changeset
    48
term "\<guillemotleft>\<guillemotleft>\<acute>\<acute>(f o \<acute>g)\<guillemotright>\<guillemotright>"
8569
748a9699f28d added HOL/ex/Multiquote.thy;
wenzelm
parents:
diff changeset
    49
9297
wenzelm
parents: 8627
diff changeset
    50
end