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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#![deny(missing_docs)]
use crate::parse::TypeDeclarations;
use proc_macro2::Ident;
use syn::parse::{Parse, ParseStream};
use syn::{Path, Token};
use crate::parsed_extern_fn::ParsedExternFn;
mod errors;
mod parse;
mod bridged_type;
mod parsed_extern_fn;
mod codegen;
#[cfg(test)]
mod test_utils;
const SWIFT_BRIDGE_PREFIX: &'static str = "__swift_bridge__";
pub struct SwiftBridgeModule {
name: Ident,
types: TypeDeclarations,
functions: Vec<ParsedExternFn>,
swift_bridge_path: Path,
}
impl SwiftBridgeModule {
pub fn set_swift_bridge_path(&mut self, path: Path) {
self.swift_bridge_path = path;
}
}
pub struct SwiftBridgeModuleAttrs {
#[allow(missing_docs)]
pub attributes: Vec<SwiftBridgeModuleAttr>,
}
pub enum SwiftBridgeModuleAttr {
SwiftBridgePath(Path),
}
impl Parse for SwiftBridgeModuleAttrs {
fn parse(input: ParseStream) -> syn::Result<Self> {
if input.is_empty() {
return Ok(SwiftBridgeModuleAttrs { attributes: vec![] });
}
let opts = syn::punctuated::Punctuated::<_, Token![,]>::parse_terminated(input)?;
Ok(SwiftBridgeModuleAttrs {
attributes: opts.into_iter().collect(),
})
}
}
impl Parse for SwiftBridgeModuleAttr {
fn parse(input: ParseStream) -> syn::Result<Self> {
let key: Ident = input.parse()?;
let _equals = input.parse::<Token![=]>()?;
let attr = match key.to_string().as_str() {
"swift_bridge_path" => SwiftBridgeModuleAttr::SwiftBridgePath(input.parse()?),
_ => {
return Err(syn::Error::new(input.span(), "Unknown attribute."));
}
};
Ok(attr)
}
}
#[cfg(test)]
mod tests {
#[test]
fn foo() {
}
}