1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#![allow(non_camel_case_types)]
#![allow(improper_ctypes)]
#![allow(dead_code)]
use mpc_c_types::*;
use std::os::raw::c_char;
#[repr(C)]
#[derive(Eq, PartialEq)]
pub enum res_t
{
ok,
err
}
#[repr(C)]
pub struct parse_result
{
pub ok: *mut mpc_ast_t,
pub err: *mut mpc_err_t,
pub res: res_t,
}
extern
{
pub fn glue_parse(filename: *const c_char, string: *const c_char, p: *mut mpc_parser_t) -> parse_result;
}
pub fn parse(filename: *const c_char, string: *const c_char, p: *mut mpc_parser_t) -> Result<*mut mpc_ast_t, *mut mpc_err_t>
{
let res = unsafe { glue_parse(filename, string, p) };
match res.res
{
res_t::ok => Ok(res.ok),
res_t::err => Err(res.err),
}
}