Guest User

Untitled

a guest
Dec 12th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. [Important terminology: __roc__ is short for roxygen comment block, __rocblock__ and for combination of roc and object that's being documented]
  2.  
  3. # Roxygen design
  4.  
  5. The __roccer__ is the object in charge of processing a tag. It is made up of two components:
  6.  
  7. * A `parser`, which is in charge of converting the raw text string into an intermediate object that can be used by other roccers and is turned into output
  8.  
  9. * An `rocout` object, which takes the intermediate format (after it's potentially been modified by other roccers) and turns it into an output format
  10.  
  11. Each of these is described in turn below.
  12.  
  13. Each roccer has a name, and a set of dependencies (currently stored in `base_prereqs`. Before the roccers are called, a topological sort is performed to ensure that they are run in the correct order. This makes sure (e.g.) that `@title` is processed before the intro paragraphs, and that `@param` is processed before `@inheritParams`.
  14.  
  15. In the future roccers may gain some sort of keyword or tag field, to make it more easy to flexibly select subsets of the roccers to run.
  16.  
  17. ## Parser
  18.  
  19. The parser implements one method: `parse_rocblocks`, which takes a list of rocblocks as input and returns a list of rocblocks as output.
  20.  
  21. There are currently three types of parser:
  22.  
  23. * `null_parser`: does nothing (useful when the text is used as is)
  24.  
  25. * `roc_parser`: modifies only the roc component of the rocblock. It has two arguments: `tag` and `one`. These are both functions: `tag` called will just a single tag, and `one` will be called with the entire rocblock (broken down using `do.call` into `roc`, `obj` etc). These both return list which are combined with the original roc using `modifyList`.
  26.  
  27. * `rocblock_parser`: has only a single argument, `all`, which is a function that is called with the list of all rocblocks and should return a list of rocblocks. This means it can modify anything: it can add or delete rocblocks, or modify any component of the rocblock.
  28.  
  29. This makes it possible for tags to be very flexible - in roxygen2 they were basically limited to local action, but many tags (like `@include`, `@family`, and `@inheritParams` need a more global perspective. It also makes it possible to write other specialised parsers that might operate on particular types of object and extract more information to add to the roc.
  30.  
  31. The other advantage of multiple parsers is for caching: the more locally a parser operates the easier it is to cache between subsequent runs. Globally operating tags depend on all roccers, so will generally need to be recomputed every time, but roccers that work with a single tag should only need to be recomputed if that tag changes.
  32.  
  33.  
  34. ## Rocout
  35.  
  36. The `rocout` object has three methods:
  37.  
  38. * `output_build`: this is given a single tag from the rocblock, and should return an `output` object which describes where and what to write.
  39.  
  40. * `output_postproc`: this combines multiple tags and does any other postprocessing data modification work before the final output. (Mainly separated out from `output_write` to make it easier to test)
  41.  
  42. * `output_write`: this basically calls `format` on the output object representing each file and then `write_if_different` to provide an informative message.
  43.  
  44. ## Output objects
  45.  
  46. Output objects represent the various possible types of output. There are currently 3:
  47.  
  48. * rd commands in an rd file
  49. * lines in the `NAMESPACE` file
  50. * fields in the `DESCRIPTION` file
Add Comment
Please, Sign In to add comment