- | "/ask_uwobo" ->
- let url = req#param "url" in
- let server_and_port =
- (Pcre.extract ~rex:server_and_port_url_RE url).(1)
- in
- if List.mem server_and_port valid_servers then
- Http_daemon.respond
- ~headers:["Content-Type", "text/html"]
- ~body:(Http_client.http_get url)
- outchan
- else
- Http_daemon.respond
- ~body:(pp_error ("Untrusted UWOBO server: " ^ server_and_port))
- outchan
- | "/searchPattern"
- | "/matchConclusion"
- | "/locateInductivePrinciple" ->
- let mqi_handle = C.init mqi_flags debug_print in
- let term_string = req#param "term" in
- let lexbuf = Lexing.from_string term_string in
- let (context, metasenv) = ([], []) in
- let (dom, mk_metasenv_and_expr) =
- CicTextualParserContext.main
- ~context ~metasenv CicTextualLexer.token lexbuf
- in
- let id_to_uris_raw = req#param "aliases" in
- let tokens = Pcre.split ~pat:"\\s" id_to_uris_raw in
- let rec parse_tokens keys lookup = function (* TODO spostarla fuori *)
- | [] -> keys, lookup
- | "alias" :: key :: value :: rest ->
- let key' = CicTextualParser0.Id key in
- parse_tokens
- (key'::keys)
- (fun id ->
- if id = key' then
- Some
- (CicTextualParser0.Uri (MQueryMisc.cic_textual_parser_uri_of_string value))
- else lookup id)
- rest
- | _ -> failwith "Can't parse aliases"
- in
- let parse_choices choices_raw =
- let choices = Pcre.split ~pat:";" choices_raw in
- List.fold_left
- (fun f x ->
- match Pcre.split ~pat:"\\s" x with
- | ""::id::tail
- | id::tail when id<>"" ->
- (fun id' ->
-prerr_endline ("#### " ^ id ^ " :=");
-List.iter (fun u -> prerr_endline ("<" ^ Netencoding.Url.decode u ^ ">")) tail;
- if id = id' then
- Some (List.map (fun u -> Netencoding.Url.decode u) tail)
- else
- f id')
- | _ -> failwith "Can't parse choices")
- (fun _ -> None)
- choices
- in
- let (id_to_uris : Disambiguate.domain_and_interpretation) =
- parse_tokens [] (fun _ -> None) tokens in
- let id_to_choices =
- try
- let choices_raw = req#param "choices" in
- parse_choices choices_raw
- with Http_types.Param_not_found _ -> (fun _ -> None)
- in
- let module Chat: Disambiguate.Callbacks =
- struct
-
- let get_metasenv () =
- !CicTextualParser0.metasenv
-
- let set_metasenv metasenv =
- CicTextualParser0.metasenv := metasenv
-
- let output_html ?(append_NL = true) html_msg =
- let rec collect_string = function
- | `BR -> "\n"
- | `T s -> s
- | `L tags -> String.concat "" (List.map collect_string tags)
- in
- match html_msg with
- | `Error msg | `Msg msg ->
- (if append_NL then prerr_endline else prerr_string)
- (collect_string msg ^ (if append_NL then "\n" else ""))
-
- let interactive_user_uri_choice
- ~selection_mode ?ok
- ?enable_button_for_non_vars ~(title: string) ~(msg: string)
- ~(id: string) (choices: string list)
- =
- (match id_to_choices id with
- | Some choices -> choices
- | None ->
- let msg = Pcre.replace ~pat:"\'" ~templ:"\\\'" msg in
- (match selection_mode with
- | `SINGLE -> assert false
- | `MULTIPLE ->
- Http_daemon.send_basic_headers ~code:200 outchan ;
- Http_daemon.send_CRLF outchan ;
- iter_file
- (fun line ->
- let formatted_choices =
- String.concat ","
- (List.map (fun uri -> sprintf "\'%s\'" uri) choices)
- in
- let processed_line =
- apply_substs
- [title_tag_RE, title;
- choices_tag_RE, formatted_choices;
- msg_tag_RE, msg;
- id_to_uris_RE, id_to_uris_raw;
- id_RE, id]
- line
- in
- output_string outchan (processed_line ^ "\n"))
- interactive_user_uri_choice_TPL;
- raise Chat_unfinished))
-
- let interactive_interpretation_choice interpretations =
- let html_interpretations_labels =
- String.concat ", "
- (List.map
- (fun l ->
- "\'" ^
- (String.concat "<br />"
- (List.map
- (fun (id, value) ->
- (sprintf "alias %s %s" id value))
- l)) ^
- "\'")
- interpretations)
- in
- let html_interpretations =
- String.concat ", "
- (List.map
- (fun l ->
- "\'" ^
- (String.concat " "
- (List.map
- (fun (id, value) ->
- (sprintf "alias %s %s"
- id
- (MQueryMisc.wrong_xpointer_format_from_wrong_xpointer_format'
- value)))
- l)) ^
- "\'")
- interpretations)
- in
- Http_daemon.send_basic_headers ~code:200 outchan ;
- Http_daemon.send_CRLF outchan ;
- iter_file
- (fun line ->
- let processed_line =
- apply_substs
- [interpretations_RE, html_interpretations;
- interpretations_labels_RE, html_interpretations_labels]
- line
- in
- output_string outchan (processed_line ^ "\n"))
- interactive_interpretation_choice_TPL;
- raise Chat_unfinished
-
- let input_or_locate_uri ~title =
- UriManager.uri_of_string "cic:/Coq/Init/DataTypes/nat_ind.con"
-
- end