| 63 | }; |
| 64 | |
| 65 | pub fn parse_file<T>(path: T) -> Result<Vec<FunctionDef>> |
| 66 | where |
| 67 | T: AsRef<Path>, |
| 68 | { |
| 69 | let path = path.as_ref(); |
| 70 | let mut file = std::fs::File::open(path) |
| 71 | .with_context(|| format!("Fail to open file: `{}`", path.display()))?; |
| 72 | let mut source_code = String::new(); |
| 73 | file.read_to_string(&mut source_code) |
| 74 | .with_context(|| format!("Fail to read file: `{}`", path.display()))?; |
| 75 | let res = syn::parse_file(&source_code) |
| 76 | .with_context(|| format!("Fail to parse file: `{}`", path.display()))? |
| 77 | .items |
| 78 | .into_iter() |
| 79 | .fold(Vec::new(), |mut acc, item| { |
| 80 | acc.extend(item.parse()); |
| 81 | acc |
| 82 | }); |
| 83 | Ok(res) |
| 84 | } |
| 85 | |
| 86 | pub fn parse_directory<T>(directory: T) -> Result<Vec<File>> |
| 87 | where |