moodymudskipper / flow

View and Browse Code Using Flow Diagrams
https://moodymudskipper.github.io/flow/
Other
395 stars 26 forks source link

Draw c functions #60

Open moodymudskipper opened 3 years ago

moodymudskipper commented 3 years ago

Note : build_plantuml_code_from_c was unexported for CRAN, access it as an Easter egg with flow:::build_plantuml_code_from_c *


I think we can't get the code from the function alone, we need a path.

Then we need to parse the code. Building a complete parser is not necessary as we just need to deal with control flow. However it is hard to do with pure regex as we find nested brackets, and brackets might be protected by quotes or double quotes.

Using regex + heuristics I could get a satisfying draft, pushed to the branch named "C".

do while is not supported yet, returns and stops are not highlighted yet.

This would be a neat feature for flow_doc, but flow_doc would need to access the code files.

There is also code outside the functions, this should be stored somewhere.

Macros should be supported too.


digression on flow_doc

In particular, I think I would really like a big report containing all base R C and R functions. On top of each diagram are links to all functions used (we can display dependencies and reverse deps) so it's easy to navigate between them.

deps and revdeps would be assessed by looking at symbols only. If we find too many false positives we can think of heuristics, like having no assignment to the symbol or not finding the symbol in args (could lead to false negative as we can have a var overridden by a num and still work as a function), or focus on calls only (but lots of false negative due to usage of apply funs, unless we create heuristics for them). We can check how yonicd did it in his efforts on graphing a pkg.

The report would be quite big, possibly something in the hundreds of megabytes. So not so convenient to share/put online. But if it looks really good there is probably a way to use js to display and hide images on demand so it can be browsed online.

This idea can be generalized, we could document the tidyverse together, or a package and all it's dependencies, or recursive dependencies, this makes it comfortable to navigate through the code in a single document without exploring github for C or getting lost within tabs.