src/Pure/Syntax/syntax_phases.ML
author wenzelm
Sat Apr 16 15:25:25 2011 +0200 (2011-04-16)
changeset 42359 6ca5407863ed
parent 42358 b47d41d9f4b5
child 42360 da8817d01e7c
permissions -rw-r--r--
prefer local name spaces;
tuned signatures;
tuned;
wenzelm@42243
     1
(*  Title:      Pure/Syntax/syntax_phases.ML
wenzelm@42241
     2
    Author:     Makarius
wenzelm@42241
     3
wenzelm@42243
     4
Main phases of inner syntax processing, with standard implementations
wenzelm@42243
     5
of parse/unparse operations.
wenzelm@42241
     6
*)
wenzelm@42241
     7
wenzelm@42243
     8
signature SYNTAX_PHASES =
wenzelm@42242
     9
sig
wenzelm@42242
    10
  val term_sorts: term -> (indexname * sort) list
wenzelm@42242
    11
  val typ_of_term: (indexname -> sort) -> term -> typ
wenzelm@42242
    12
  val decode_term: Proof.context ->
wenzelm@42242
    13
    Position.reports * term Exn.result -> Position.reports * term Exn.result
wenzelm@42242
    14
  val parse_ast_pattern: Proof.context -> string * string -> Ast.ast
wenzelm@42247
    15
  val term_of_typ: Proof.context -> typ -> term
wenzelm@42242
    16
end
wenzelm@42242
    17
wenzelm@42243
    18
structure Syntax_Phases: SYNTAX_PHASES =
wenzelm@42241
    19
struct
wenzelm@42241
    20
wenzelm@42298
    21
(** markup logical entities **)
wenzelm@42298
    22
wenzelm@42298
    23
fun markup_class ctxt c =
wenzelm@42298
    24
  [Name_Space.markup_entry (Type.class_space (ProofContext.tsig_of ctxt)) c];
wenzelm@42298
    25
wenzelm@42298
    26
fun markup_type ctxt c =
wenzelm@42298
    27
  [Name_Space.markup_entry (Type.type_space (ProofContext.tsig_of ctxt)) c];
wenzelm@42298
    28
wenzelm@42298
    29
fun markup_const ctxt c =
wenzelm@42298
    30
  [Name_Space.markup_entry (Consts.space_of (ProofContext.consts_of ctxt)) c];
wenzelm@42298
    31
wenzelm@42298
    32
fun markup_free ctxt x =
wenzelm@42298
    33
  [if can Name.dest_skolem x then Markup.skolem else Markup.free] @
wenzelm@42298
    34
  (if not (Variable.is_body ctxt) orelse Variable.is_fixed ctxt x then []
wenzelm@42298
    35
   else [Markup.hilite]);
wenzelm@42298
    36
wenzelm@42298
    37
fun markup_var xi = [Markup.name (Term.string_of_vname xi) Markup.var];
wenzelm@42298
    38
wenzelm@42298
    39
fun markup_bound def id =
wenzelm@42298
    40
  [Markup.properties [(if def then Markup.defN else Markup.refN, id)] Markup.bound];
wenzelm@42298
    41
wenzelm@42298
    42
fun markup_entity ctxt c =
wenzelm@42298
    43
  (case Syntax.lookup_const (ProofContext.syn_of ctxt) c of
wenzelm@42298
    44
    SOME "" => []
wenzelm@42298
    45
  | SOME b => markup_entity ctxt b
wenzelm@42298
    46
  | NONE => c |> Lexicon.unmark
wenzelm@42298
    47
     {case_class = markup_class ctxt,
wenzelm@42298
    48
      case_type = markup_type ctxt,
wenzelm@42298
    49
      case_const = markup_const ctxt,
wenzelm@42298
    50
      case_fixed = markup_free ctxt,
wenzelm@42298
    51
      case_default = K []});
wenzelm@42298
    52
wenzelm@42298
    53
wenzelm@42298
    54
wenzelm@42242
    55
(** decode parse trees **)
wenzelm@42242
    56
wenzelm@42242
    57
(* sort_of_term *)
wenzelm@42242
    58
wenzelm@42242
    59
fun sort_of_term tm =
wenzelm@42242
    60
  let
wenzelm@42242
    61
    fun err () = raise TERM ("sort_of_term: bad encoding of classes", [tm]);
wenzelm@42242
    62
wenzelm@42242
    63
    fun class s = Lexicon.unmark_class s handle Fail _ => err ();
wenzelm@42242
    64
wenzelm@42242
    65
    fun classes (Const (s, _)) = [class s]
wenzelm@42242
    66
      | classes (Const ("_classes", _) $ Const (s, _) $ cs) = class s :: classes cs
wenzelm@42242
    67
      | classes _ = err ();
wenzelm@42242
    68
wenzelm@42242
    69
    fun sort (Const ("_topsort", _)) = []
wenzelm@42242
    70
      | sort (Const (s, _)) = [class s]
wenzelm@42242
    71
      | sort (Const ("_sort", _) $ cs) = classes cs
wenzelm@42242
    72
      | sort _ = err ();
wenzelm@42242
    73
  in sort tm end;
wenzelm@42242
    74
wenzelm@42242
    75
wenzelm@42242
    76
(* term_sorts *)
wenzelm@42242
    77
wenzelm@42242
    78
fun term_sorts tm =
wenzelm@42242
    79
  let
wenzelm@42242
    80
    val sort_of = sort_of_term;
wenzelm@42242
    81
wenzelm@42242
    82
    fun add_env (Const ("_ofsort", _) $ Free (x, _) $ cs) =
wenzelm@42242
    83
          insert (op =) ((x, ~1), sort_of cs)
wenzelm@42242
    84
      | add_env (Const ("_ofsort", _) $ (Const ("_tfree", _) $ Free (x, _)) $ cs) =
wenzelm@42242
    85
          insert (op =) ((x, ~1), sort_of cs)
wenzelm@42242
    86
      | add_env (Const ("_ofsort", _) $ Var (xi, _) $ cs) =
wenzelm@42242
    87
          insert (op =) (xi, sort_of cs)
wenzelm@42242
    88
      | add_env (Const ("_ofsort", _) $ (Const ("_tvar", _) $ Var (xi, _)) $ cs) =
wenzelm@42242
    89
          insert (op =) (xi, sort_of cs)
wenzelm@42242
    90
      | add_env (Abs (_, _, t)) = add_env t
wenzelm@42242
    91
      | add_env (t1 $ t2) = add_env t1 #> add_env t2
wenzelm@42242
    92
      | add_env _ = I;
wenzelm@42242
    93
  in add_env tm [] end;
wenzelm@42242
    94
wenzelm@42242
    95
wenzelm@42242
    96
(* typ_of_term *)
wenzelm@42242
    97
wenzelm@42242
    98
fun typ_of_term get_sort tm =
wenzelm@42242
    99
  let
wenzelm@42242
   100
    fun err () = raise TERM ("typ_of_term: bad encoding of type", [tm]);
wenzelm@42242
   101
wenzelm@42242
   102
    fun typ_of (Free (x, _)) = TFree (x, get_sort (x, ~1))
wenzelm@42242
   103
      | typ_of (Var (xi, _)) = TVar (xi, get_sort xi)
wenzelm@42242
   104
      | typ_of (Const ("_tfree",_) $ (t as Free _)) = typ_of t
wenzelm@42242
   105
      | typ_of (Const ("_tvar",_) $ (t as Var _)) = typ_of t
wenzelm@42242
   106
      | typ_of (Const ("_ofsort", _) $ Free (x, _) $ _) = TFree (x, get_sort (x, ~1))
wenzelm@42242
   107
      | typ_of (Const ("_ofsort", _) $ (Const ("_tfree",_) $ Free (x, _)) $ _) =
wenzelm@42242
   108
          TFree (x, get_sort (x, ~1))
wenzelm@42242
   109
      | typ_of (Const ("_ofsort", _) $ Var (xi, _) $ _) = TVar (xi, get_sort xi)
wenzelm@42242
   110
      | typ_of (Const ("_ofsort", _) $ (Const ("_tvar",_) $ Var (xi, _)) $ _) =
wenzelm@42242
   111
          TVar (xi, get_sort xi)
wenzelm@42242
   112
      | typ_of (Const ("_dummy_ofsort", _) $ t) = TFree ("'_dummy_", sort_of_term t)
wenzelm@42242
   113
      | typ_of t =
wenzelm@42242
   114
          let
wenzelm@42242
   115
            val (head, args) = Term.strip_comb t;
wenzelm@42242
   116
            val a =
wenzelm@42242
   117
              (case head of
wenzelm@42242
   118
                Const (c, _) => (Lexicon.unmark_type c handle Fail _ => err ())
wenzelm@42242
   119
              | _ => err ());
wenzelm@42242
   120
          in Type (a, map typ_of args) end;
wenzelm@42242
   121
  in typ_of tm end;
wenzelm@42242
   122
wenzelm@42242
   123
wenzelm@42242
   124
(* parsetree_to_ast *)
wenzelm@42242
   125
wenzelm@42242
   126
fun parsetree_to_ast ctxt constrain_pos trf parsetree =
wenzelm@42242
   127
  let
wenzelm@42250
   128
    val get_class = ProofContext.read_class ctxt;
wenzelm@42250
   129
    val get_type = #1 o dest_Type o ProofContext.read_type_name_proper ctxt false;
wenzelm@42282
   130
wenzelm@42242
   131
    val reports = Unsynchronized.ref ([]: Position.reports);
wenzelm@42242
   132
    fun report pos = Position.reports reports [pos];
wenzelm@42242
   133
wenzelm@42242
   134
    fun trans a args =
wenzelm@42242
   135
      (case trf a of
wenzelm@42242
   136
        NONE => Ast.mk_appl (Ast.Constant a) args
wenzelm@42242
   137
      | SOME f => f ctxt args);
wenzelm@42242
   138
wenzelm@42282
   139
    fun asts_of (Parser.Node ("_class_name", [Parser.Tip tok])) =
wenzelm@42242
   140
          let
wenzelm@42242
   141
            val c = get_class (Lexicon.str_of_token tok);
wenzelm@42298
   142
            val _ = report (Lexicon.pos_of_token tok) (markup_class ctxt) c;
wenzelm@42282
   143
          in [Ast.Constant (Lexicon.mark_class c)] end
wenzelm@42282
   144
      | asts_of (Parser.Node ("_type_name", [Parser.Tip tok])) =
wenzelm@42242
   145
          let
wenzelm@42242
   146
            val c = get_type (Lexicon.str_of_token tok);
wenzelm@42298
   147
            val _ = report (Lexicon.pos_of_token tok) (markup_type ctxt) c;
wenzelm@42282
   148
          in [Ast.Constant (Lexicon.mark_type c)] end
wenzelm@42282
   149
      | asts_of (Parser.Node ("_constrain_position", [pt as Parser.Tip tok])) =
wenzelm@42242
   150
          if constrain_pos then
wenzelm@42282
   151
            [Ast.Appl [Ast.Constant "_constrain", ast_of pt,
wenzelm@42282
   152
              Ast.Variable (Term_Position.encode (Lexicon.pos_of_token tok))]]
wenzelm@42282
   153
          else [ast_of pt]
wenzelm@42282
   154
      | asts_of (Parser.Node (a, pts)) =
wenzelm@42282
   155
          let
wenzelm@42282
   156
            val _ = pts |> List.app
wenzelm@42282
   157
              (fn Parser.Node _ => () | Parser.Tip tok =>
wenzelm@42282
   158
                if Lexicon.valued_token tok then ()
wenzelm@42298
   159
                else report (Lexicon.pos_of_token tok) (markup_entity ctxt) a);
wenzelm@42282
   160
          in [trans a (maps asts_of pts)] end
wenzelm@42282
   161
      | asts_of (Parser.Tip tok) =
wenzelm@42282
   162
          if Lexicon.valued_token tok
wenzelm@42282
   163
          then [Ast.Variable (Lexicon.str_of_token tok)]
wenzelm@42282
   164
          else []
wenzelm@42282
   165
wenzelm@42282
   166
    and ast_of pt =
wenzelm@42282
   167
      (case asts_of pt of
wenzelm@42282
   168
        [ast] => ast
wenzelm@42282
   169
      | asts => raise Ast.AST ("parsetree_to_ast: malformed parsetree", asts));
wenzelm@42242
   170
wenzelm@42242
   171
    val ast = Exn.interruptible_capture ast_of parsetree;
wenzelm@42242
   172
  in (! reports, ast) end;
wenzelm@42242
   173
wenzelm@42242
   174
wenzelm@42242
   175
(* ast_to_term *)
wenzelm@42242
   176
wenzelm@42242
   177
fun ast_to_term ctxt trf =
wenzelm@42242
   178
  let
wenzelm@42242
   179
    fun trans a args =
wenzelm@42242
   180
      (case trf a of
wenzelm@42242
   181
        NONE => Term.list_comb (Lexicon.const a, args)
wenzelm@42242
   182
      | SOME f => f ctxt args);
wenzelm@42242
   183
wenzelm@42242
   184
    fun term_of (Ast.Constant a) = trans a []
wenzelm@42242
   185
      | term_of (Ast.Variable x) = Lexicon.read_var x
wenzelm@42242
   186
      | term_of (Ast.Appl (Ast.Constant a :: (asts as _ :: _))) =
wenzelm@42242
   187
          trans a (map term_of asts)
wenzelm@42242
   188
      | term_of (Ast.Appl (ast :: (asts as _ :: _))) =
wenzelm@42242
   189
          Term.list_comb (term_of ast, map term_of asts)
wenzelm@42242
   190
      | term_of (ast as Ast.Appl _) = raise Ast.AST ("ast_to_term: malformed ast", [ast]);
wenzelm@42242
   191
  in term_of end;
wenzelm@42242
   192
wenzelm@42242
   193
wenzelm@42242
   194
(* decode_term -- transform parse tree into raw term *)
wenzelm@42242
   195
wenzelm@42242
   196
fun decode_term _ (result as (_: Position.reports, Exn.Exn _)) = result
wenzelm@42242
   197
  | decode_term ctxt (reports0, Exn.Result tm) =
wenzelm@42242
   198
      let
wenzelm@42250
   199
        fun get_const a =
wenzelm@42250
   200
          ((true, #1 (Term.dest_Const (ProofContext.read_const_proper ctxt false a)))
wenzelm@42282
   201
            handle ERROR _ => (false, Consts.intern (ProofContext.consts_of ctxt) a));
wenzelm@42250
   202
        val get_free = ProofContext.intern_skolem ctxt;
wenzelm@42250
   203
wenzelm@42242
   204
        val decodeT = typ_of_term (ProofContext.get_sort ctxt (term_sorts tm));
wenzelm@42242
   205
wenzelm@42242
   206
        val reports = Unsynchronized.ref reports0;
wenzelm@42242
   207
        fun report ps = Position.reports reports ps;
wenzelm@42242
   208
wenzelm@42242
   209
        fun decode ps qs bs (Const ("_constrain", _) $ t $ typ) =
wenzelm@42264
   210
              (case Term_Position.decode_position typ of
wenzelm@42242
   211
                SOME p => decode (p :: ps) qs bs t
wenzelm@42242
   212
              | NONE => Type.constraint (decodeT typ) (decode ps qs bs t))
wenzelm@42242
   213
          | decode ps qs bs (Const ("_constrainAbs", _) $ t $ typ) =
wenzelm@42264
   214
              (case Term_Position.decode_position typ of
wenzelm@42242
   215
                SOME q => decode ps (q :: qs) bs t
wenzelm@42242
   216
              | NONE => Type.constraint (decodeT typ --> dummyT) (decode ps qs bs t))
wenzelm@42242
   217
          | decode _ qs bs (Abs (x, T, t)) =
wenzelm@42242
   218
              let
wenzelm@42242
   219
                val id = serial_string ();
wenzelm@42242
   220
                val _ = report qs (markup_bound true) id;
wenzelm@42242
   221
              in Abs (x, T, decode [] [] (id :: bs) t) end
wenzelm@42242
   222
          | decode _ _ bs (t $ u) = decode [] [] bs t $ decode [] [] bs u
wenzelm@42242
   223
          | decode ps _ _ (Const (a, T)) =
wenzelm@42242
   224
              (case try Lexicon.unmark_fixed a of
wenzelm@42282
   225
                SOME x => (report ps (markup_free ctxt) x; Free (x, T))
wenzelm@42242
   226
              | NONE =>
wenzelm@42242
   227
                  let
wenzelm@42242
   228
                    val c =
wenzelm@42242
   229
                      (case try Lexicon.unmark_const a of
wenzelm@42242
   230
                        SOME c => c
wenzelm@42242
   231
                      | NONE => snd (get_const a));
wenzelm@42282
   232
                    val _ = report ps (markup_const ctxt) c;
wenzelm@42242
   233
                  in Const (c, T) end)
wenzelm@42242
   234
          | decode ps _ _ (Free (a, T)) =
wenzelm@42242
   235
              (case (get_free a, get_const a) of
wenzelm@42282
   236
                (SOME x, _) => (report ps (markup_free ctxt) x; Free (x, T))
wenzelm@42282
   237
              | (_, (true, c)) => (report ps (markup_const ctxt) c; Const (c, T))
wenzelm@42242
   238
              | (_, (false, c)) =>
wenzelm@42242
   239
                  if Long_Name.is_qualified c
wenzelm@42282
   240
                  then (report ps (markup_const ctxt) c; Const (c, T))
wenzelm@42282
   241
                  else (report ps (markup_free ctxt) c; Free (c, T)))
wenzelm@42242
   242
          | decode ps _ _ (Var (xi, T)) = (report ps markup_var xi; Var (xi, T))
wenzelm@42242
   243
          | decode ps _ bs (t as Bound i) =
wenzelm@42242
   244
              (case try (nth bs) i of
wenzelm@42242
   245
                SOME id => (report ps (markup_bound false) id; t)
wenzelm@42242
   246
              | NONE => t);
wenzelm@42242
   247
wenzelm@42242
   248
        val tm' = Exn.interruptible_capture (fn () => decode [] [] [] tm) ();
wenzelm@42242
   249
      in (! reports, tm') end;
wenzelm@42242
   250
wenzelm@42242
   251
wenzelm@42242
   252
wenzelm@42242
   253
(** parse **)
wenzelm@42242
   254
wenzelm@42242
   255
(* results *)
wenzelm@42242
   256
wenzelm@42242
   257
fun ambiguity_msg pos = "Parse error: ambiguous syntax" ^ Position.str_of pos;
wenzelm@42242
   258
wenzelm@42242
   259
fun proper_results results = map_filter (fn (y, Exn.Result x) => SOME (y, x) | _ => NONE) results;
wenzelm@42242
   260
fun failed_results results = map_filter (fn (y, Exn.Exn e) => SOME (y, e) | _ => NONE) results;
wenzelm@42242
   261
wenzelm@42242
   262
fun report ctxt = List.app (fn (pos, m) => Context_Position.report ctxt pos m);
wenzelm@42242
   263
wenzelm@42242
   264
fun report_result ctxt pos results =
wenzelm@42242
   265
  (case (proper_results results, failed_results results) of
wenzelm@42242
   266
    ([], (reports, exn) :: _) => (report ctxt reports; reraise exn)
wenzelm@42242
   267
  | ([(reports, x)], _) => (report ctxt reports; x)
wenzelm@42242
   268
  | _ => error (ambiguity_msg pos));
wenzelm@42242
   269
wenzelm@42242
   270
wenzelm@42249
   271
(* parse raw asts *)
wenzelm@42242
   272
wenzelm@42242
   273
fun parse_asts ctxt raw root (syms, pos) =
wenzelm@42242
   274
  let
wenzelm@42251
   275
    val syn = ProofContext.syn_of ctxt;
wenzelm@42253
   276
    val ast_tr = Syntax.parse_ast_translation syn;
wenzelm@42242
   277
wenzelm@42251
   278
    val toks = Syntax.tokenize syn raw syms;
wenzelm@42242
   279
    val _ = List.app (Lexicon.report_token ctxt) toks;
wenzelm@42242
   280
wenzelm@42251
   281
    val pts = Syntax.parse ctxt syn root (filter Lexicon.is_proper toks)
wenzelm@42242
   282
      handle ERROR msg =>
wenzelm@42242
   283
        error (msg ^
wenzelm@42242
   284
          implode (map (Markup.markup Markup.report o Lexicon.reported_token_range ctxt) toks));
wenzelm@42242
   285
    val len = length pts;
wenzelm@42242
   286
wenzelm@42242
   287
    val limit = Config.get ctxt Syntax.ambiguity_limit;
wenzelm@42242
   288
    val _ =
wenzelm@42242
   289
      if len <= Config.get ctxt Syntax.ambiguity_level then ()
wenzelm@42242
   290
      else if not (Config.get ctxt Syntax.ambiguity_enabled) then error (ambiguity_msg pos)
wenzelm@42242
   291
      else
wenzelm@42242
   292
        (Context_Position.if_visible ctxt warning (cat_lines
wenzelm@42242
   293
          (("Ambiguous input" ^ Position.str_of pos ^
wenzelm@42242
   294
            "\nproduces " ^ string_of_int len ^ " parse trees" ^
wenzelm@42242
   295
            (if len <= limit then "" else " (" ^ string_of_int limit ^ " displayed)") ^ ":") ::
wenzelm@42242
   296
            map (Pretty.string_of o Parser.pretty_parsetree) (take limit pts))));
wenzelm@42242
   297
wenzelm@42242
   298
    val constrain_pos = not raw andalso Config.get ctxt Syntax.positions;
wenzelm@42253
   299
    val parsetree_to_ast = parsetree_to_ast ctxt constrain_pos ast_tr;
wenzelm@42242
   300
  in map parsetree_to_ast pts end;
wenzelm@42242
   301
wenzelm@42249
   302
fun parse_raw ctxt root input =
wenzelm@42242
   303
  let
wenzelm@42253
   304
    val syn = ProofContext.syn_of ctxt;
wenzelm@42253
   305
    val tr = Syntax.parse_translation syn;
wenzelm@42255
   306
    val parse_rules = Syntax.parse_rules syn;
wenzelm@42242
   307
  in
wenzelm@42242
   308
    parse_asts ctxt false root input
wenzelm@42255
   309
    |> (map o apsnd o Exn.maps_result)
wenzelm@42255
   310
        (Ast.normalize ctxt parse_rules #> Exn.interruptible_capture (ast_to_term ctxt tr))
wenzelm@42242
   311
  end;
wenzelm@42242
   312
wenzelm@42242
   313
wenzelm@42249
   314
(* parse logical entities *)
wenzelm@42242
   315
wenzelm@42241
   316
fun parse_failed ctxt pos msg kind =
wenzelm@42241
   317
  cat_error msg ("Failed to parse " ^ kind ^
wenzelm@42241
   318
    Markup.markup Markup.report (Context_Position.reported_text ctxt pos Markup.bad ""));
wenzelm@42241
   319
wenzelm@42241
   320
fun parse_sort ctxt text =
wenzelm@42241
   321
  let
wenzelm@42241
   322
    val (syms, pos) = Syntax.parse_token ctxt Markup.sort text;
wenzelm@42249
   323
    val S =
wenzelm@42249
   324
      parse_raw ctxt "sort" (syms, pos)
wenzelm@42249
   325
      |> report_result ctxt pos
wenzelm@42249
   326
      |> sort_of_term
wenzelm@42242
   327
      handle ERROR msg => parse_failed ctxt pos msg "sort";
wenzelm@42241
   328
  in Type.minimize_sort (ProofContext.tsig_of ctxt) S end;
wenzelm@42241
   329
wenzelm@42241
   330
fun parse_typ ctxt text =
wenzelm@42241
   331
  let
wenzelm@42241
   332
    val (syms, pos) = Syntax.parse_token ctxt Markup.typ text;
wenzelm@42249
   333
    val T =
wenzelm@42249
   334
      parse_raw ctxt "type" (syms, pos)
wenzelm@42249
   335
      |> report_result ctxt pos
wenzelm@42249
   336
      |> (fn t => typ_of_term (ProofContext.get_sort ctxt (term_sorts t)) t)
wenzelm@42242
   337
      handle ERROR msg => parse_failed ctxt pos msg "type";
wenzelm@42241
   338
  in T end;
wenzelm@42241
   339
wenzelm@42281
   340
fun parse_term is_prop ctxt text =
wenzelm@42241
   341
  let
wenzelm@42281
   342
    val (markup, kind, root, constrain) =
wenzelm@42281
   343
      if is_prop
wenzelm@42281
   344
      then (Markup.prop, "proposition", "prop", Type.constraint propT)
wenzelm@42288
   345
      else (Markup.term, "term", Config.get ctxt Syntax.root, I);
wenzelm@42241
   346
    val (syms, pos) = Syntax.parse_token ctxt markup text;
wenzelm@42249
   347
  in
wenzelm@42249
   348
    let
wenzelm@42249
   349
      val results = parse_raw ctxt root (syms, pos) |> map (decode_term ctxt);
wenzelm@42249
   350
      val ambiguity = length (proper_results results);
wenzelm@42241
   351
wenzelm@42249
   352
      val level = Config.get ctxt Syntax.ambiguity_level;
wenzelm@42249
   353
      val limit = Config.get ctxt Syntax.ambiguity_limit;
wenzelm@42249
   354
wenzelm@42249
   355
      fun ambig_msg () =
wenzelm@42249
   356
        if ambiguity > 1 andalso ambiguity <= level then
wenzelm@42249
   357
          "Got more than one parse tree.\n\
wenzelm@42249
   358
          \Retry with smaller syntax_ambiguity_level for more information."
wenzelm@42249
   359
        else "";
wenzelm@42249
   360
wenzelm@42249
   361
      (*brute-force disambiguation via type-inference*)
wenzelm@42281
   362
      fun check t = (Syntax.check_term ctxt (constrain t); Exn.Result t)
wenzelm@42249
   363
        handle exn as ERROR _ => Exn.Exn exn;
wenzelm@42249
   364
wenzelm@42249
   365
      val results' =
wenzelm@42249
   366
        if ambiguity > 1 then
wenzelm@42249
   367
          (Par_List.map_name "Syntax_Phases.parse_term" o apsnd o Exn.maps_result)
wenzelm@42249
   368
            check results
wenzelm@42249
   369
        else results;
wenzelm@42249
   370
      val reports' = fst (hd results');
wenzelm@42249
   371
wenzelm@42249
   372
      val errs = map snd (failed_results results');
wenzelm@42249
   373
      val checked = map snd (proper_results results');
wenzelm@42249
   374
      val len = length checked;
wenzelm@42249
   375
wenzelm@42289
   376
      val show_term = Syntax.string_of_term (Config.put Printer.show_brackets true ctxt);
wenzelm@42249
   377
    in
wenzelm@42249
   378
      if len = 0 then
wenzelm@42249
   379
        report_result ctxt pos
wenzelm@42249
   380
          [(reports', Exn.Exn (Exn.EXCEPTIONS (ERROR (ambig_msg ()) :: errs)))]
wenzelm@42249
   381
      else if len = 1 then
wenzelm@42249
   382
        (if ambiguity > level then
wenzelm@42249
   383
          Context_Position.if_visible ctxt warning
wenzelm@42249
   384
            "Fortunately, only one parse tree is type correct.\n\
wenzelm@42249
   385
            \You may still want to disambiguate your grammar or your input."
wenzelm@42249
   386
        else (); report_result ctxt pos results')
wenzelm@42249
   387
      else
wenzelm@42249
   388
        report_result ctxt pos
wenzelm@42249
   389
          [(reports', Exn.Exn (ERROR (cat_lines (ambig_msg () ::
wenzelm@42249
   390
            (("Ambiguous input, " ^ string_of_int len ^ " terms are type correct" ^
wenzelm@42249
   391
              (if len <= limit then "" else " (" ^ string_of_int limit ^ " displayed)") ^ ":") ::
wenzelm@42249
   392
              map show_term (take limit checked))))))]
wenzelm@42249
   393
    end handle ERROR msg => parse_failed ctxt pos msg kind
wenzelm@42249
   394
  end;
wenzelm@42241
   395
wenzelm@42241
   396
wenzelm@42242
   397
(* parse_ast_pattern *)
wenzelm@42242
   398
wenzelm@42242
   399
fun parse_ast_pattern ctxt (root, str) =
wenzelm@42242
   400
  let
wenzelm@42242
   401
    val syn = ProofContext.syn_of ctxt;
wenzelm@42242
   402
wenzelm@42242
   403
    fun constify (ast as Ast.Constant _) = ast
wenzelm@42242
   404
      | constify (ast as Ast.Variable x) =
wenzelm@42298
   405
          if is_some (Syntax.lookup_const syn x) orelse Long_Name.is_qualified x
wenzelm@42298
   406
          then Ast.Constant x
wenzelm@42242
   407
          else ast
wenzelm@42242
   408
      | constify (Ast.Appl asts) = Ast.Appl (map constify asts);
wenzelm@42242
   409
wenzelm@42242
   410
    val (syms, pos) = Syntax.read_token str;
wenzelm@42242
   411
  in
wenzelm@42242
   412
    parse_asts ctxt true root (syms, pos)
wenzelm@42242
   413
    |> report_result ctxt pos
wenzelm@42242
   414
    |> constify
wenzelm@42242
   415
  end;
wenzelm@42242
   416
wenzelm@42242
   417
wenzelm@42242
   418
wenzelm@42245
   419
(** encode parse trees **)
wenzelm@42245
   420
wenzelm@42245
   421
(* term_of_sort *)
wenzelm@42245
   422
wenzelm@42245
   423
fun term_of_sort S =
wenzelm@42245
   424
  let
wenzelm@42245
   425
    val class = Lexicon.const o Lexicon.mark_class;
wenzelm@42245
   426
wenzelm@42245
   427
    fun classes [c] = class c
wenzelm@42245
   428
      | classes (c :: cs) = Lexicon.const "_classes" $ class c $ classes cs;
wenzelm@42245
   429
  in
wenzelm@42245
   430
    (case S of
wenzelm@42245
   431
      [] => Lexicon.const "_topsort"
wenzelm@42245
   432
    | [c] => class c
wenzelm@42245
   433
    | cs => Lexicon.const "_sort" $ classes cs)
wenzelm@42245
   434
  end;
wenzelm@42245
   435
wenzelm@42245
   436
wenzelm@42245
   437
(* term_of_typ *)
wenzelm@42245
   438
wenzelm@42247
   439
fun term_of_typ ctxt ty =
wenzelm@42245
   440
  let
wenzelm@42247
   441
    val show_sorts = Config.get ctxt show_sorts;
wenzelm@42247
   442
wenzelm@42245
   443
    fun of_sort t S =
wenzelm@42245
   444
      if show_sorts then Lexicon.const "_ofsort" $ t $ term_of_sort S
wenzelm@42245
   445
      else t;
wenzelm@42245
   446
wenzelm@42245
   447
    fun term_of (Type (a, Ts)) =
wenzelm@42245
   448
          Term.list_comb (Lexicon.const (Lexicon.mark_type a), map term_of Ts)
wenzelm@42245
   449
      | term_of (TFree (x, S)) =
wenzelm@42290
   450
          if is_some (Term_Position.decode x) then Syntax.free x
wenzelm@42290
   451
          else of_sort (Lexicon.const "_tfree" $ Syntax.free x) S
wenzelm@42290
   452
      | term_of (TVar (xi, S)) = of_sort (Lexicon.const "_tvar" $ Syntax.var xi) S;
wenzelm@42245
   453
  in term_of ty end;
wenzelm@42245
   454
wenzelm@42245
   455
wenzelm@42245
   456
(* simple_ast_of *)
wenzelm@42245
   457
wenzelm@42245
   458
fun simple_ast_of ctxt =
wenzelm@42245
   459
  let
wenzelm@42245
   460
    val tune_var = if Config.get ctxt show_question_marks then I else unprefix "?";
wenzelm@42245
   461
    fun ast_of (Const (c, _)) = Ast.Constant c
wenzelm@42245
   462
      | ast_of (Free (x, _)) = Ast.Variable x
wenzelm@42245
   463
      | ast_of (Var (xi, _)) = Ast.Variable (tune_var (Term.string_of_vname xi))
wenzelm@42245
   464
      | ast_of (t as _ $ _) =
wenzelm@42245
   465
          let val (f, args) = strip_comb t
wenzelm@42245
   466
          in Ast.mk_appl (ast_of f) (map ast_of args) end
wenzelm@42245
   467
      | ast_of (Bound i) = Ast.Variable ("B." ^ string_of_int i)
wenzelm@42245
   468
      | ast_of (Abs _) = raise Fail "simple_ast_of: Abs";
wenzelm@42245
   469
  in ast_of end;
wenzelm@42245
   470
wenzelm@42245
   471
wenzelm@42245
   472
(* sort_to_ast and typ_to_ast *)
wenzelm@42245
   473
wenzelm@42245
   474
fun ast_of_termT ctxt trf tm =
wenzelm@42245
   475
  let
wenzelm@42245
   476
    val ctxt' = Config.put show_sorts false ctxt;
wenzelm@42245
   477
    fun ast_of (t as Const ("_tfree", _) $ Free _) = simple_ast_of ctxt t
wenzelm@42245
   478
      | ast_of (t as Const ("_tvar", _) $ Var _) = simple_ast_of ctxt t
wenzelm@42245
   479
      | ast_of (Const (a, _)) = trans a []
wenzelm@42245
   480
      | ast_of (t as _ $ _) =
wenzelm@42245
   481
          (case strip_comb t of
wenzelm@42245
   482
            (Const (a, _), args) => trans a args
wenzelm@42245
   483
          | (f, args) => Ast.Appl (map ast_of (f :: args)))
wenzelm@42245
   484
      | ast_of t = simple_ast_of ctxt t
wenzelm@42254
   485
    and trans a args = ast_of (trf a ctxt' dummyT args)
wenzelm@42254
   486
      handle Match => Ast.mk_appl (Ast.Constant a) (map ast_of args);
wenzelm@42245
   487
  in ast_of tm end;
wenzelm@42245
   488
wenzelm@42245
   489
fun sort_to_ast ctxt trf S = ast_of_termT ctxt trf (term_of_sort S);
wenzelm@42247
   490
fun typ_to_ast ctxt trf T = ast_of_termT ctxt trf (term_of_typ ctxt T);
wenzelm@42245
   491
wenzelm@42245
   492
wenzelm@42245
   493
(* term_to_ast *)
wenzelm@42245
   494
wenzelm@42252
   495
fun term_to_ast idents is_syntax_const ctxt trf tm =
wenzelm@42245
   496
  let
wenzelm@42245
   497
    val show_types =
wenzelm@42245
   498
      Config.get ctxt show_types orelse Config.get ctxt show_sorts orelse
wenzelm@42245
   499
      Config.get ctxt show_all_types;
wenzelm@42245
   500
    val show_structs = Config.get ctxt show_structs;
wenzelm@42245
   501
    val show_free_types = Config.get ctxt show_free_types;
wenzelm@42245
   502
    val show_all_types = Config.get ctxt show_all_types;
wenzelm@42245
   503
wenzelm@42245
   504
    val {structs, fixes} = idents;
wenzelm@42245
   505
wenzelm@42249
   506
    fun mark_atoms ((t as Const (c, _)) $ u) =
wenzelm@42294
   507
          if member (op =) Syntax.token_markers c
wenzelm@42245
   508
          then t $ u else mark_atoms t $ mark_atoms u
wenzelm@42245
   509
      | mark_atoms (t $ u) = mark_atoms t $ mark_atoms u
wenzelm@42245
   510
      | mark_atoms (Abs (x, T, t)) = Abs (x, T, mark_atoms t)
wenzelm@42245
   511
      | mark_atoms (t as Const (c, T)) =
wenzelm@42252
   512
          if is_syntax_const c then t
wenzelm@42245
   513
          else Const (Lexicon.mark_const c, T)
wenzelm@42245
   514
      | mark_atoms (t as Free (x, T)) =
wenzelm@42245
   515
          let val i = find_index (fn s => s = x) structs + 1 in
wenzelm@42245
   516
            if i = 0 andalso member (op =) fixes x then
wenzelm@42245
   517
              Const (Lexicon.mark_fixed x, T)
wenzelm@42245
   518
            else if i = 1 andalso not show_structs then
wenzelm@42245
   519
              Lexicon.const "_struct" $ Lexicon.const "_indexdefault"
wenzelm@42245
   520
            else Lexicon.const "_free" $ t
wenzelm@42245
   521
          end
wenzelm@42245
   522
      | mark_atoms (t as Var (xi, T)) =
wenzelm@42288
   523
          if xi = Syntax_Ext.dddot_indexname then Const ("_DDDOT", T)
wenzelm@42245
   524
          else Lexicon.const "_var" $ t
wenzelm@42245
   525
      | mark_atoms a = a;
wenzelm@42245
   526
wenzelm@42245
   527
    fun prune_typs (t_seen as (Const _, _)) = t_seen
wenzelm@42245
   528
      | prune_typs (t as Free (x, ty), seen) =
wenzelm@42245
   529
          if ty = dummyT then (t, seen)
wenzelm@42290
   530
          else if not show_free_types orelse member (op aconv) seen t then (Syntax.free x, seen)
wenzelm@42245
   531
          else (t, t :: seen)
wenzelm@42245
   532
      | prune_typs (t as Var (xi, ty), seen) =
wenzelm@42245
   533
          if ty = dummyT then (t, seen)
wenzelm@42290
   534
          else if not show_free_types orelse member (op aconv) seen t then (Syntax.var xi, seen)
wenzelm@42245
   535
          else (t, t :: seen)
wenzelm@42245
   536
      | prune_typs (t_seen as (Bound _, _)) = t_seen
wenzelm@42245
   537
      | prune_typs (Abs (x, ty, t), seen) =
wenzelm@42245
   538
          let val (t', seen') = prune_typs (t, seen);
wenzelm@42245
   539
          in (Abs (x, ty, t'), seen') end
wenzelm@42245
   540
      | prune_typs (t1 $ t2, seen) =
wenzelm@42245
   541
          let
wenzelm@42245
   542
            val (t1', seen') = prune_typs (t1, seen);
wenzelm@42245
   543
            val (t2', seen'') = prune_typs (t2, seen');
wenzelm@42245
   544
          in (t1' $ t2', seen'') end;
wenzelm@42245
   545
wenzelm@42245
   546
    fun ast_of tm =
wenzelm@42245
   547
      (case strip_comb tm of
wenzelm@42284
   548
        (t as Abs _, ts) => Ast.mk_appl (ast_of (Syntax_Trans.abs_tr' ctxt t)) (map ast_of ts)
wenzelm@42245
   549
      | ((c as Const ("_free", _)), Free (x, T) :: ts) =>
wenzelm@42290
   550
          Ast.mk_appl (constrain (c $ Syntax.free x) T) (map ast_of ts)
wenzelm@42245
   551
      | ((c as Const ("_var", _)), Var (xi, T) :: ts) =>
wenzelm@42290
   552
          Ast.mk_appl (constrain (c $ Syntax.var xi) T) (map ast_of ts)
wenzelm@42245
   553
      | ((c as Const ("_bound", _)), Free (x, T) :: ts) =>
wenzelm@42290
   554
          Ast.mk_appl (constrain (c $ Syntax.free x) T) (map ast_of ts)
wenzelm@42245
   555
      | (Const ("_idtdummy", T), ts) =>
wenzelm@42245
   556
          Ast.mk_appl (constrain (Lexicon.const "_idtdummy") T) (map ast_of ts)
wenzelm@42245
   557
      | (const as Const (c, T), ts) =>
wenzelm@42245
   558
          if show_all_types
wenzelm@42245
   559
          then Ast.mk_appl (constrain const T) (map ast_of ts)
wenzelm@42245
   560
          else trans c T ts
wenzelm@42245
   561
      | (t, ts) => Ast.mk_appl (simple_ast_of ctxt t) (map ast_of ts))
wenzelm@42245
   562
wenzelm@42254
   563
    and trans a T args = ast_of (trf a ctxt T args)
wenzelm@42254
   564
      handle Match => Ast.mk_appl (Ast.Constant a) (map ast_of args)
wenzelm@42245
   565
wenzelm@42245
   566
    and constrain t T =
wenzelm@42245
   567
      if show_types andalso T <> dummyT then
wenzelm@42248
   568
        Ast.Appl [Ast.Constant "_constrain", simple_ast_of ctxt t,
wenzelm@42247
   569
          ast_of_termT ctxt trf (term_of_typ ctxt T)]
wenzelm@42245
   570
      else simple_ast_of ctxt t;
wenzelm@42245
   571
  in
wenzelm@42245
   572
    tm
wenzelm@42284
   573
    |> Syntax_Trans.prop_tr'
wenzelm@42245
   574
    |> show_types ? (#1 o prune_typs o rpair [])
wenzelm@42245
   575
    |> mark_atoms
wenzelm@42245
   576
    |> ast_of
wenzelm@42245
   577
  end;
wenzelm@42245
   578
wenzelm@42245
   579
wenzelm@42245
   580
wenzelm@42242
   581
(** unparse **)
wenzelm@42242
   582
wenzelm@42245
   583
local
wenzelm@42245
   584
wenzelm@42267
   585
fun free_or_skolem ctxt x =
wenzelm@42267
   586
  let
wenzelm@42267
   587
    val m =
wenzelm@42267
   588
      if Variable.is_fixed ctxt x orelse Syntax.is_pretty_global ctxt
wenzelm@42267
   589
      then Markup.fixed x
wenzelm@42267
   590
      else Markup.hilite;
wenzelm@42267
   591
  in
wenzelm@42267
   592
    if can Name.dest_skolem x
wenzelm@42267
   593
    then ([m, Markup.skolem], ProofContext.revert_skolem ctxt x)
wenzelm@42267
   594
    else ([m, Markup.free], x)
wenzelm@42267
   595
  end;
wenzelm@42267
   596
wenzelm@42267
   597
fun var_or_skolem s =
wenzelm@42267
   598
  (case Lexicon.read_variable s of
wenzelm@42267
   599
    SOME (x, i) =>
wenzelm@42267
   600
      (case try Name.dest_skolem x of
wenzelm@42267
   601
        NONE => (Markup.var, s)
wenzelm@42267
   602
      | SOME x' => (Markup.skolem, Term.string_of_vname (x', i)))
wenzelm@42267
   603
  | NONE => (Markup.var, s));
wenzelm@42267
   604
wenzelm@42267
   605
fun unparse_t t_to_ast prt_t markup ctxt t =
wenzelm@42245
   606
  let
wenzelm@42253
   607
    val syn = ProofContext.syn_of ctxt;
wenzelm@42267
   608
wenzelm@42267
   609
    fun token_trans "_tfree" x = SOME (Pretty.mark_str (Markup.tfree, x))
wenzelm@42267
   610
      | token_trans "_tvar" x = SOME (Pretty.mark_str (Markup.tvar, x))
wenzelm@42267
   611
      | token_trans "_free" x = SOME (Pretty.marks_str (free_or_skolem ctxt x))
wenzelm@42267
   612
      | token_trans "_bound" x = SOME (Pretty.mark_str (Markup.bound, x))
wenzelm@42267
   613
      | token_trans "_var" x = SOME (Pretty.mark_str (var_or_skolem x))
wenzelm@42267
   614
      | token_trans "_numeral" x = SOME (Pretty.mark_str (Markup.numeral, x))
wenzelm@42267
   615
      | token_trans "_inner_string" x = SOME (Pretty.mark_str (Markup.inner_string, x))
wenzelm@42267
   616
      | token_trans _ _ = NONE;
wenzelm@42267
   617
wenzelm@42301
   618
    fun markup_extern c =
wenzelm@42301
   619
      (case Syntax.lookup_const syn c of
wenzelm@42301
   620
        SOME "" => ([], c)
wenzelm@42301
   621
      | SOME b => markup_extern b
wenzelm@42301
   622
      | NONE => c |> Lexicon.unmark
wenzelm@42359
   623
         {case_class = fn x => ([Markup.tclass x], ProofContext.extern_class ctxt x),
wenzelm@42359
   624
          case_type = fn x => ([Markup.tycon x], ProofContext.extern_type ctxt x),
wenzelm@42359
   625
          case_const = fn x => ([Markup.const x], ProofContext.extern_const ctxt x),
wenzelm@42301
   626
          case_fixed = fn x => free_or_skolem ctxt x,
wenzelm@42301
   627
          case_default = fn x => ([], x)});
wenzelm@42245
   628
  in
wenzelm@42255
   629
    t_to_ast ctxt (Syntax.print_translation syn) t
wenzelm@42255
   630
    |> Ast.normalize ctxt (Syntax.print_rules syn)
wenzelm@42267
   631
    |> prt_t ctxt (Syntax.prtabs syn) (Syntax.print_ast_translation syn) token_trans markup_extern
wenzelm@42253
   632
    |> Pretty.markup markup
wenzelm@42245
   633
  end;
wenzelm@42245
   634
wenzelm@42245
   635
in
wenzelm@42245
   636
wenzelm@42267
   637
val unparse_sort = unparse_t sort_to_ast Printer.pretty_typ_ast Markup.sort;
wenzelm@42267
   638
val unparse_typ = unparse_t typ_to_ast Printer.pretty_typ_ast Markup.typ;
wenzelm@42241
   639
wenzelm@42241
   640
fun unparse_term ctxt =
wenzelm@42241
   641
  let
wenzelm@42252
   642
    val thy = ProofContext.theory_of ctxt;
wenzelm@42252
   643
    val syn = ProofContext.syn_of ctxt;
wenzelm@42252
   644
    val idents = Local_Syntax.idents_of (ProofContext.syntax_of ctxt);
wenzelm@42241
   645
  in
wenzelm@42298
   646
    unparse_t (term_to_ast idents (is_some o Syntax.lookup_const syn))
wenzelm@42267
   647
      (Printer.pretty_term_ast (not (Pure_Thy.old_appl_syntax thy)))
wenzelm@42267
   648
      Markup.term ctxt
wenzelm@42241
   649
  end;
wenzelm@42241
   650
wenzelm@42249
   651
end;
wenzelm@42249
   652
wenzelm@42241
   653
wenzelm@42245
   654
wenzelm@42245
   655
(** translations **)
wenzelm@42245
   656
wenzelm@42245
   657
(* type propositions *)
wenzelm@42245
   658
wenzelm@42247
   659
fun type_prop_tr' ctxt T [Const ("\\<^const>Pure.sort_constraint", _)] =
wenzelm@42247
   660
      Lexicon.const "_sort_constraint" $ term_of_typ (Config.put show_sorts true ctxt) T
wenzelm@42247
   661
  | type_prop_tr' ctxt T [t] =
wenzelm@42247
   662
      Lexicon.const "_ofclass" $ term_of_typ ctxt T $ t
wenzelm@42245
   663
  | type_prop_tr' _ T ts = raise TYPE ("type_prop_tr'", [T], ts);
wenzelm@42245
   664
wenzelm@42245
   665
wenzelm@42245
   666
(* type reflection *)
wenzelm@42245
   667
wenzelm@42247
   668
fun type_tr' ctxt (Type ("itself", [T])) ts =
wenzelm@42247
   669
      Term.list_comb (Lexicon.const "_TYPE" $ term_of_typ ctxt T, ts)
wenzelm@42245
   670
  | type_tr' _ _ _ = raise Match;
wenzelm@42245
   671
wenzelm@42245
   672
wenzelm@42245
   673
(* type constraints *)
wenzelm@42245
   674
wenzelm@42247
   675
fun type_constraint_tr' ctxt (Type ("fun", [T, _])) (t :: ts) =
wenzelm@42248
   676
      Term.list_comb (Lexicon.const "_constrain" $ t $ term_of_typ ctxt T, ts)
wenzelm@42245
   677
  | type_constraint_tr' _ _ _ = raise Match;
wenzelm@42245
   678
wenzelm@42245
   679
wenzelm@42295
   680
(* authentic syntax *)
wenzelm@42295
   681
wenzelm@42295
   682
fun const_ast_tr intern ctxt [Ast.Variable c] =
wenzelm@42295
   683
      let
wenzelm@42295
   684
        val Const (c', _) = ProofContext.read_const_proper ctxt false c;
wenzelm@42295
   685
        val d = if intern then Lexicon.mark_const c' else c;
wenzelm@42295
   686
      in Ast.Constant d end
wenzelm@42296
   687
  | const_ast_tr intern ctxt [Ast.Appl [Ast.Constant "_constrain", x, T]] =
wenzelm@42296
   688
      Ast.Appl [Ast.Constant "_constrain", const_ast_tr intern ctxt [x], T]
wenzelm@42295
   689
  | const_ast_tr _ _ asts = raise Ast.AST ("const_ast_tr", asts);
wenzelm@42295
   690
wenzelm@42295
   691
wenzelm@42245
   692
(* setup translations *)
wenzelm@42245
   693
wenzelm@42245
   694
val _ = Context.>> (Context.map_theory
wenzelm@42295
   695
 (Sign.add_advanced_trfuns
wenzelm@42295
   696
  ([("_context_const", const_ast_tr true),
wenzelm@42295
   697
    ("_context_xconst", const_ast_tr false)], [], [], []) #>
wenzelm@42295
   698
  Sign.add_advanced_trfunsT
wenzelm@42245
   699
   [("_type_prop", type_prop_tr'),
wenzelm@42245
   700
    ("\\<^const>TYPE", type_tr'),
wenzelm@42245
   701
    ("_type_constraint_", type_constraint_tr')]));
wenzelm@42245
   702
wenzelm@42245
   703
wenzelm@42245
   704
wenzelm@42242
   705
(** install operations **)
wenzelm@42242
   706
wenzelm@42241
   707
val _ = Syntax.install_operations
wenzelm@42241
   708
  {parse_sort = parse_sort,
wenzelm@42241
   709
   parse_typ = parse_typ,
wenzelm@42281
   710
   parse_term = parse_term false,
wenzelm@42281
   711
   parse_prop = parse_term true,
wenzelm@42241
   712
   unparse_sort = unparse_sort,
wenzelm@42241
   713
   unparse_typ = unparse_typ,
wenzelm@42241
   714
   unparse_term = unparse_term};
wenzelm@42241
   715
wenzelm@42241
   716
end;