src/Tools/WWW_Find/find_theorems.ML
author krauss
Mon, 30 May 2011 17:07:48 +0200
changeset 43072 8aeb7ec8003a
parent 43068 ac769b5edd1d
child 43073 a4c985fe015d
permissions -rw-r--r--
attempt to clarify code; removed "handle _" and dead code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33823
24090eae50b6 standardized headers;
wenzelm
parents: 33817
diff changeset
     1
(*  Title:      Tools/WWW_Find/find_theorems.ML
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
     2
    Author:     Timothy Bourke, NICTA
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
     3
33823
24090eae50b6 standardized headers;
wenzelm
parents: 33817
diff changeset
     4
Simple find_theorems server.
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
     5
*)
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
     6
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
     7
local
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36960
diff changeset
     8
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
     9
val default_limit = 20;
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36960
diff changeset
    10
val thy_names = sort string_ord (Thy_Info.get_names ());
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    11
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    12
val find_theorems_url = "find_theorems";
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    13
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    14
fun is_sorry thm =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    15
  Thm.proof_of thm
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    16
  |> Proofterm.approximate_proof_body
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    17
  |> Proofterm.all_oracles_of
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    18
  |> exists (fn (x, _) => x = "Pure.skip_proof");
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    19
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    20
local open Xhtml in
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    21
fun find_theorems_form thy_name (query, limit, withdups) =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    22
  let
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    23
    val query_input =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    24
      input (id "query", {
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    25
        name = "query",
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    26
        itype = TextInput { value = query, maxlength = NONE }});
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    27
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    28
    val max_results = divele noid
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    29
      [
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    30
        label (noid, { for = "limit" }, "Max. results:"),
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    31
        input (id "limit",
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    32
          { name = "limit",
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 38980
diff changeset
    33
            itype = TextInput { value = SOME (string_of_int limit),
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    34
                                maxlength = NONE }})
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    35
      ];
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    36
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    37
    val theories = divele noid
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    38
      [
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    39
        label (noid, { for = "theory" }, "Search in:"),
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    40
        select (id "theory", { name = "theory", value = SOME thy_name })
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    41
               thy_names
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    42
      ];
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    43
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    44
    val with_dups = divele noid
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    45
      [
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    46
        label (noid, { for = "withdups" }, "Allow duplicates:"),
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    47
        input (id "withdups",
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    48
          { name = "withdups",
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    49
            itype = Checkbox { checked = withdups, value = SOME "true" }})
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    50
      ];
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    51
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    52
    val help = divele (class "help")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    53
      [ a { href="/pasting_help.html", text="(pasting from proof general)" } ];
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    54
  in
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    55
    form (id "findtheorems", { method = "post", action = "/isabelle/find_theorems" })
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    56
      [tag "fieldset" []
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    57
        [tag "legend" [] [text "find_theorems"],
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    58
         (add_script (OnKeyPress, "encodequery(this)")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    59
          o add_script (OnChange, "encodequery(this)")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    60
          o add_script (OnMouseUp, "encodequery(this)")) query_input,
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    61
         divele (class "settings") [ max_results, theories, with_dups, help ],
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    62
         divele (class "mainbuttons")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    63
           [ reset_button (id "reset"), submit_button (id "submit") ]
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    64
        ]
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    65
      ]
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    66
  end;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    67
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    68
fun html_header thy_name args =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    69
  html { lang = "en" } [
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    70
    head { title = "Find Theorems: results", stylesheet_href = "/basic.css" }
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    71
         [script (noid, { script_type="text/javascript",
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    72
                          src="/find_theorems.js" })],
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    73
    add_script (OnLoad, "encodequery(document.getElementById('query'))")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    74
      (body noid [
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    75
          h (noid, 1, "Theory " ^ thy_name),
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    76
          find_theorems_form thy_name args,
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    77
          divele noid []
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    78
         ])
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    79
  ];
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    80
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    81
fun html_error msg = p ((class "error"), msg);
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    82
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    83
val find_theorems_table =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    84
  table (class "findtheorems")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    85
    [
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    86
      thead noid [tr [th (noid, "name"), th (noid, "theorem")]],
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    87
      tbody noid []
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    88
    ];
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    89
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    90
fun show_criterion (b, c) =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    91
  let
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    92
    fun prfx s = let
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    93
        val (c, v) = if b then ("criterion", s) else ("ncriterion", "-" ^ s);
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    94
      in span (class c, v) end;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    95
  in
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    96
    (case c of
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    97
      Find_Theorems.Name name => prfx ("name: " ^ quote name)
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    98
    | Find_Theorems.Intro => prfx "intro"
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
    99
    | Find_Theorems.IntroIff => prfx "introiff"
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   100
    | Find_Theorems.Elim => prfx "elim"
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   101
    | Find_Theorems.Dest => prfx "dest"
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   102
    | Find_Theorems.Solves => prfx "solves"
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   103
    | Find_Theorems.Simp pat => prfx ("simp: \"" ^ pat ^ "\"")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   104
    | Find_Theorems.Pattern pat => prfx ("\"" ^ pat ^ "\""))
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   105
  end;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   106
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   107
fun find_theorems_summary (othmslen, thmslen, args) =
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   108
  let
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   109
    val args =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   110
      (case othmslen of
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   111
         NONE => args
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 38980
diff changeset
   112
       | SOME l => Symtab.update ("limit", string_of_int l) args)
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   113
    val qargs = HttpUtil.make_query_string args;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   114
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   115
    val num_found_text =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   116
      (case othmslen of
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 38980
diff changeset
   117
         NONE => text (string_of_int thmslen)
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   118
       | SOME l =>
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   119
           a { href = find_theorems_url ^
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   120
               (if qargs = "" then "" else "?" ^ qargs),
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 38980
diff changeset
   121
           text = string_of_int l })
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   122
    val found = [text "found ", num_found_text, text " theorems"] : tag list;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   123
    val displayed =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   124
      if is_some othmslen
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 38980
diff changeset
   125
      then " (" ^ string_of_int thmslen ^ " displayed)"
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   126
      else "";
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   127
  in
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   128
    table (class "findtheoremsquery")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   129
      [ tr [ th' noid (found @ [text (displayed ^ ":")]) ] ]
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   130
  end
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   131
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   132
fun sorry_class thm = if is_sorry thm then class "sorried" else noid;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   133
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   134
fun html_thm ctxt (n, (thmref, thm)) =
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   135
  let
38980
af73cf0dc31f turned show_question_marks into proper configuration option;
wenzelm
parents: 37863
diff changeset
   136
    val output_thm =
36745
403585a89772 unified/simplified Pretty.margin_default;
wenzelm
parents: 36610
diff changeset
   137
      Output.output o Pretty.string_of_margin 100 o
38980
af73cf0dc31f turned show_question_marks into proper configuration option;
wenzelm
parents: 37863
diff changeset
   138
        Display.pretty_thm (Config.put show_question_marks false ctxt);
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   139
  in
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 38980
diff changeset
   140
    tag' "tr" (class ("row" ^ string_of_int (n mod 2)))
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   141
      [
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   142
        tag' "td" (class "name")
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   143
          [span' (sorry_class thm)
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   144
             [raw_text (Facts.string_of_ref thmref)]
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   145
          ],
38980
af73cf0dc31f turned show_question_marks into proper configuration option;
wenzelm
parents: 37863
diff changeset
   146
        tag' "td" (class "thm") [pre noid (output_thm thm)]
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   147
      ]
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   148
  end;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   149
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   150
end;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   151
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   152
fun app_index f xs = fold_index (fn x => K (f x)) xs ();
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   153
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   154
fun parse_request (ScgiReq.Req {request_method, query_string, ...}, content, send) =
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   155
  (case request_method of
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   156
     ScgiReq.Get => query_string
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   157
   | ScgiReq.Post =>
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   158
      content
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   159
      |> Byte.bytesToString
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   160
      |> HttpUtil.parse_query_string
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   161
   | ScgiReq.Head => raise Fail "Cannot handle Head requests.",
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   162
  send);
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   163
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   164
fun find_theorems (arg_data, send) =
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   165
  let
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   166
    val args = Symtab.lookup arg_data;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   167
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   168
    val query_str = the_default "" (args "query");
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   169
    fun get_query () =
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   170
      (query_str ^ ";")
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36959
diff changeset
   171
      |> Outer_Syntax.scan Position.start
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36745
diff changeset
   172
      |> filter Token.is_proper
43068
ac769b5edd1d exported raw query parser; removed inconsistent clone
krauss
parents: 43067
diff changeset
   173
      |> Scan.error Find_Theorems.query_parser
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   174
      |> fst;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   175
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   176
    val limit = case args "limit" of
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   177
        NONE => default_limit
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   178
      | SOME str => the_default default_limit (Int.fromString str);
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   179
    val thy_name = the_default "Main" (args "theory");
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   180
    val with_dups = is_some (args "with_dups");
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   181
    
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   182
    val ctxt = Proof_Context.init_global (Thy_Info.get_theory thy_name);
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   183
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   184
    fun do_find query =
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   185
      let
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   186
        val (othmslen, thms) =
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   187
          Find_Theorems.find_theorems_cmd ctxt NONE (SOME limit) with_dups query
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   188
          ||> rev;
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   189
      in
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   190
        Xhtml.write send
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   191
          (find_theorems_summary (othmslen, length thms, arg_data));
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   192
        if null thms then ()
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   193
        else Xhtml.write_enclosed send find_theorems_table (fn send =>
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   194
               HTML_Unicode.print_mode (app_index (Xhtml.write send o html_thm ctxt)) thms)
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   195
      end;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   196
  in
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   197
    send Xhtml.doctype_xhtml1_0_strict;
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   198
    Xhtml.write_enclosed send
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   199
      (html_header thy_name (args "query", limit, with_dups))
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   200
      (fn send => 
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   201
        if query_str = "" then ()
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   202
        else
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   203
          do_find (get_query ())
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   204
          handle ERROR msg => Xhtml.write send (html_error msg))
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   205
  end;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   206
in
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36960
diff changeset
   207
42289
dafae095d733 discontinued special status of structure Printer;
wenzelm
parents: 41522
diff changeset
   208
val () = Printer.show_question_marks_default := false;
43072
8aeb7ec8003a attempt to clarify code; removed "handle _" and dead code
krauss
parents: 43068
diff changeset
   209
val () = ScgiServer.register (find_theorems_url, SOME Mime.html, find_theorems o parse_request);
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36960
diff changeset
   210
33817
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   211
end;
f6a4da31f2f1 WWW_Find component: find_theorems via web browser
kleing
parents:
diff changeset
   212