summaryrefslogtreecommitdiffstats
path: root/src/parser
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2019-12-22 18:10:39 +0100
committerMinijackson <minijackson@riseup.net>2019-12-22 18:10:39 +0100
commita71e95bf4f07e044eb3f335929d2adea74247a9e (patch)
tree4aaed2deca529902c2c64e337047fef71aecb1db /src/parser
parente773caea8010b87726ea524d31798fb2e43e12f4 (diff)
downloadposeidoc-a71e95bf4f07e044eb3f335929d2adea74247a9e.tar.gz
poseidoc-a71e95bf4f07e044eb3f335929d2adea74247a9e.zip
Fix TOC links for inline documentation
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/clang/entities.rs61
1 files changed, 27 insertions, 34 deletions
diff --git a/src/parser/clang/entities.rs b/src/parser/clang/entities.rs
index 41fe061..cbc17b7 100644
--- a/src/parser/clang/entities.rs
+++ b/src/parser/clang/entities.rs
@@ -1,4 +1,4 @@
1use crate::types::*; 1use crate::types::{self, *};
2 2
3use clang::{EntityKind, Usr}; 3use clang::{EntityKind, Usr};
4use thiserror::Error; 4use thiserror::Error;
@@ -169,55 +169,48 @@ where
169 } 169 }
170} 170}
171 171
172fn entity_id(usr: Usr) -> EntityId {
173 // This is a somewhat ugly workaround, because Pandoc parses markdown identifiers as alphanum
174 // or one of "-_:.", which means Pandoc can't parse libclang's USRs in title ids and related.
175 //
176 // <https://github.com/jgm/pandoc/blob/2.9/src/Text/Pandoc/Readers/Markdown.hs#L581>
177 EntityId(usr.0.replace("@", "::").replace("#", ".").replace("$", "-"))
178}
179
180fn append_children<T: ClangEntity>(
181 acc: &mut types::Children,
182 to_insert: BTreeMap<Usr, Described<T>>,
183) {
184 for (usr, child) in to_insert {
185 acc.entry(ChildrenKind(String::from(
186 child.entity.kind().to_str_plural(),
187 )))
188 .or_default()
189 .insert(entity_id(usr), child.into());
190 }
191}
192
172impl<T: ClangEntity> From<Described<T>> for Entity { 193impl<T: ClangEntity> From<Described<T>> for Entity {
173 fn from(entity: Described<T>) -> Self { 194 fn from(entity: Described<T>) -> Self {
174 let mut children: BTreeMap<ChildrenKind, BTreeMap<EntityId, Entity>> = BTreeMap::new(); 195 let mut children: types::Children = BTreeMap::new();
175 196
176 let kind = EntityKind(String::from(entity.entity.kind().to_str_singular())); 197 let kind = EntityKind(String::from(entity.entity.kind().to_str_singular()));
177 let clang_children = entity.entity.into_children(); 198 let clang_children = entity.entity.into_children();
178 199
179 if let Some(namespaces) = clang_children.namespaces { 200 if let Some(namespaces) = clang_children.namespaces {
180 for (usr, namespace) in namespaces { 201 append_children(&mut children, namespaces);
181 children
182 .entry(ChildrenKind(String::from(
183 namespace.entity.kind().to_str_plural(),
184 )))
185 .or_default()
186 .insert(EntityId(usr.0), namespace.into());
187 }
188 } 202 }
189 203
190 if let Some(variables) = clang_children.variables { 204 if let Some(variables) = clang_children.variables {
191 for (usr, variable) in variables { 205 append_children(&mut children, variables);
192 children
193 .entry(ChildrenKind(String::from(
194 variable.entity.kind().to_str_plural(),
195 )))
196 .or_default()
197 .insert(EntityId(usr.0), variable.into());
198 }
199 } 206 }
200 207
201 if let Some(structs) = clang_children.structs { 208 if let Some(structs) = clang_children.structs {
202 for (usr, r#struct) in structs { 209 append_children(&mut children, structs);
203 children
204 .entry(ChildrenKind(String::from(
205 r#struct.entity.kind().to_str_plural(),
206 )))
207 .or_default()
208 .insert(EntityId(usr.0), r#struct.into());
209 }
210 } 210 }
211 211
212 if let Some(functions) = clang_children.functions { 212 if let Some(functions) = clang_children.functions {
213 for (usr, function) in functions { 213 append_children(&mut children, functions);
214 children
215 .entry(ChildrenKind(String::from(
216 function.entity.kind().to_str_plural(),
217 )))
218 .or_default()
219 .insert(EntityId(usr.0), function.into());
220 }
221 } 214 }
222 215
223 Entity { 216 Entity {