-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsource.rs
More file actions
65 lines (54 loc) · 1.54 KB
/
source.rs
File metadata and controls
65 lines (54 loc) · 1.54 KB
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
extern crate askama;
use askama::Template;
#[derive(Template)]
#[template(path = "lib.rs.tmpl", escape = "none")]
pub struct LibRs<'a> {
pub file_basename: &'a str,
pub ftypes: &'a [RustFnTemplate<'a>],
pub ftypes_imports: &'a [RustImportFnTemplate<'a>],
}
pub struct RustFnTemplate<'a> {
pub func_name: &'a str,
pub args_decl: &'a str,
pub args_let_vec: &'a str,
pub str_args_converter: &'a str,
pub rettype_decl: &'a str,
pub handle_retval: &'a str,
pub exported_helper_var: &'a str,
}
pub struct RustImportFnTemplate<'a> {
pub func_name: &'a str,
pub args_decl: &'a str,
pub imported_body: &'a str,
pub rettype_decl: &'a str,
pub import_helper_var: &'a str,
}
#[test]
fn test_lib_rs_template() {
use crate::rbs_parser::parse;
let def = "
def foo_bar: (Integer) -> Integer
";
let ret = parse(def).unwrap();
let ftype = ret.1;
let ftypes = vec![RustFnTemplate {
func_name: &ftype[0].name,
args_decl: "a: i32",
args_let_vec: "vec![std::rc::Rc::new(RObject::RInteger(a as i64))]",
rettype_decl: "-> i32",
str_args_converter: "// do nothing",
handle_retval: "5471",
exported_helper_var: "",
}];
let imports = vec![];
let lib_rs = LibRs {
file_basename: "world",
ftypes: &ftypes,
ftypes_imports: &imports,
};
let rendered = lib_rs.render().unwrap();
if std::env::var("VERBOSE").is_ok() {
println!("{}", &rendered);
}
assert!(syn::parse_file(&rendered).is_ok());
}