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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#![warn(missing_docs)]
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(unused_qualifications)]
#![warn(deprecated_in_future)]
#![warn(unused_lifetimes)]
#![doc = include_str!("../README.md")]

/// A mod with utility methods to build **implementation** of your bindings
///
/// Header can be generated via `generate` function
pub mod helpers;

mod options;
pub use options::Options;

/// Global namespace of all funcionns that are used in bindings
pub const NS: &'static str = "lib_ruby_parser__external";

mod api;

/// Generates a header file for your bindings
pub fn generate(options: &Options) -> String {
    format!(
        "#ifndef {ifndef_name}
#define {ifndef_name}

{pre_code}
{contents}
{post_code}

#endif // {ifndef_name}
",
        ifndef_name = options.ifndef_name,
        pre_code = options.pre_code,
        post_code = options.post_code,
        contents = contents(&options)
    )
}

fn contents(options: &Options) -> String {
    vec![
        api::ptr(options),
        api::maybe(options),
        api::string_ptr(options),
        api::shared_byte_list(options),
        api::list(options),
        api::source_line(options),
        api::bytes(options),
        api::token(options),
        api::comment_type(options),
        api::comment(options),
        api::loc(options),
        api::magic_comment_kind(options),
        api::magic_comment(options),
        api::error_level(options),
        api::message(options),
        api::diagnostic(options),
        api::node(options),
        api::input_error(options),
        api::decoder_result(options),
        api::decoder(options),
        api::token_rewriter(options),
        api::parser_options(options),
        api::decoded_input(options),
        api::parser_result(options),
    ]
    .join("")
}

#[cfg(test)]
mod tests;