1 // Copyright (c) 2019, Facebook, Inc.
2 // All rights reserved.
4 // This source code is licensed under the MIT license found in the
5 // LICENSE file in the "hack" directory of this source tree.
7 use facts_rust as facts;
9 use oxidized::relative_path::RelativePath;
11 use facts::facts_parser::*;
13 caml!(extract_as_json_ffi(
20 let flags = flags.i32_val();
21 return extract_as_json_ffi0(
22 ((1 << 0) & flags) != 0, // php5_compat_mode
23 ((1 << 1) & flags) != 0, // hhvm_compat_mode
24 ((1 << 2) & flags) != 0, // allow_new_attribute_syntax
25 ((1 << 3) & flags) != 0, // disallow_func_ptrs_in_constants
26 RelativePath::from_ocamlvalue(&filename),
27 ocaml::Str::from(text).as_str(),
28 mangle_xhp.i32_val() != 0,
32 fn extract_as_json_ffi0(
33 php5_compat_mode: bool,
34 hhvm_compat_mode: bool,
35 allow_new_attribute_syntax: bool,
36 disallow_func_ptrs_in_constants: bool,
37 filename: RelativePath,
41 let opts = ExtractAsJsonOpts {
44 allow_new_attribute_syntax,
45 disallow_func_ptrs_in_constants,
48 // return empty string in case of failure (ambiguous because "" is not a valid JSON)
49 // as ocaml-rs doesn't offer conversion from/to option (caller will use None for failure)
50 let f = || extract_as_json(text, opts).unwrap_or(String::from(""));
54 without_xhp_mangling(f)