Commit 814b2d50 authored by Kim Nguyễn's avatar Kim Nguyễn
Browse files

Move some conditional code into plugins.

parent db3d9aa7
let define_ops () =
let fail () = Value.failwith' "Javascript feature not available in native Runtime" in
let open Operators in
let open Builtin_defs in
begin
register_fun2 ~ns:Ns.cduce_unsafe_ns "js_replace_inner"
string_latin1 string_latin1 nil
(fun _ _ -> fail ())
end;
begin
register_fun2 ~ns:Ns.cduce_unsafe_ns "js_replace_outer"
string_latin1 string_latin1 nil
(fun _ _ -> fail ())
end;
begin
let htype = Types.( arrow
(cons string_latin1)
(cons (arrow (cons empty(*_open_record*)) (cons nil)))
)
in
register_fun3 ~ns:Ns.cduce_unsafe_ns "js_register_event"
string_latin1 string_latin1 htype nil
(fun _ _ _ -> fail ())
end;
begin
register_fun ~ns:Ns.cduce_unsafe_ns "js_cast"
Types.any Types.empty
(fun _ -> fail())
end;
begin
register_fun ~ns:Ns.cduce_unsafe_ns "js_get"
string_latin1 js_value
(fun _ -> fail ())
end
let use () =
define_ops ()
let () =
Cduce_config.register
"dummy_js"
"Dummy Javascript implementation"
use
open Value
open Ident
open Encodings
open Load_xml
let string s q =
let s = Utf8.mk s in
String_utf8 (Utf8.start_index s,Utf8.end_index s, s, q)
let load_html s =
let rec val_of_doc q = function
| Nethtml.Data data ->
if (Load_xml.only_ws data (String.length data)) then q else string data q
| Nethtml.Element (tag, att, child) ->
let att = List.map (fun (n,v) -> (Label.mk (Ns.empty, U.mk n), U.mk v)) att in
Pair (elem Ns.empty_table (Atoms.V.mk (Ns.empty,U.mk tag) )
att (val_of_docs child), q, Value.Identity)
and val_of_docs = function
| [] -> nil
| h::t -> val_of_doc (val_of_docs t) h
in
Cduce_loc.protect_op "load_html";
let parse src = Nethtml.parse_document ~dtd:Nethtml.relaxed_html40_dtd src in
let doc =
if Cduce_url.is_url s then
parse (Lexing.from_string (Cduce_url.load_url s))
else
let ic = open_in s in
let doc =
try parse (Lexing.from_channel ic)
with exn -> close_in ic; raise exn in
close_in ic;
doc
in
let doc = Nethtml.decode ~subst:(fun _ -> "???") doc in
let doc = Nethtml.map_list
(Netconversion.convert ~in_enc:`Enc_iso88591
~out_enc:`Enc_utf8) doc in
val_of_docs doc
let use () =
Load_xml.html_parser := load_html
let () =
Cduce_config.register
"netstring"
"netstring HTML parser"
use
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment