Repository navigation
Add the do_docs compiler pass - #216
Conversation
|
Is there anything blocking this? |
== src/lfe_macro.erl ==
Replace some boolean case statements with ?IF/3.
== src/lfe_comp.hrl ==
Make a few cosmetic tweaks, add the docs field to #module{}
(currently unused), and add #doc{}, doc/0 and pattern/0.
== src/lfe_comp.erl ==
Borrow some elixir_module functions for writing custom BEAM chunks.
Update beam_write/1 to use all_ok/1 instead of inlining its definition.
Add a flag no-docs (or no_docs) to skip doc parsing/BEAM writing.
Add do_docs and add_docs passes.
do_docs => Update modules with their docs
add_docs => Add "LDoc" chunk to module BEAMs
N.B. I had to update lots function signatures in subsequent passes
to account for the added Docs in tuple getting passed around.
{ok,_,_,_} => {ok,_,_,_,Docs}
This might be a good reason to switch to {ok,#module{}} or similar.
Make docstrings binary, using unicode:characters_to_binary/3:
InEncoding = OutEncoding = utf8.
yurrriq@e71a2c6#commitcomment-16840410
== test/{docs,example}.lfe ==
Add doc test cases:
$ lfe test/docs.lfe
Export `add` and `varargs` for future export-macro docs experiments.
TODO:
- Discuss tuple vs #module{} with Robert
- Maybe handle export-macro somehow
- Code cleanup
- lfe_doc:format_error/1
Now I can stop redefining it everywhere.
Use the ?IF/3 macro whenever possible.
Fix #doc.doc type, add default #module.code='none' and inline ?IF/3.
Move make_doc/5 to the bottom and fix its spec, and add patterns/1 spec.
Replace `all_ok/1` with `all_module/1`.
Also affects `lfe_doc:module/1` (which needs work wrt `moduledoc`, etc).
Add a type spec for `lfe_doc:module/1`.
Rework `add_docs_{module,chunk}` to only take a `#module{}`,
instead of also a `#comp{}`. Check `all_module/1` in `add_docs/1`.
Add dummy record for lfe_docs_v1.
- `#lfe_docs_v1.moduledoc` (see Lodox)
- Add `#doc.line`
- ...
Prune obviated lfe_comp:all_ok/1, add and export lfe_doc:exports/1, and rewrite lfe_comp:add_docs_module/1 to be more opaque. N.B. lfe_doc:exports/1 handles function as well as macro docs. The internal, higher-order do_exports/2 is rather unidiomatic, but it's more appealing to me than inlining it or making it quaternary.
- Move docs-related beam functions to lfe_doc (add_docs_module/1)
- Add moduledoc to #lfe_docs_v1{}
- Perform some error checking/collecting for patterns/1
- Implement format_error/1
- Add exclude/1 to exclude generated functions/macros from docs
- Hackily handle moduledoc in add_docs_module/1
Make exports_attributes/1 return {ModDoc,Mod1} where ModDoc
is a given module docstring (default: <<"">>) and 'doc' is
removed from the "Attr" beam chunk in Mod1 (see moduledoc/1)
- `import` all the things for maximum brevity. - Leave `attributes` unchanged to let the `codegen` pass clean up. - Revert back to non-upserting `add_beam_chunk/3` and shorten it. - Turn `test/docs` into a shell script.
- Add #doc.line and update lfe_doc:make_doc accordingly. - Amend make_doc/6 type spec to reflect the string() to binary() conv. - Add forty-two? to example's exported macros (to test Robert's fix)
Fix make_doc/6 comment and pull out string_to_binary/1.
Add PropEr as a test dependency. N.B. This is a first draft of porting the Lodox tests to lfe_doc and I've made several adjustments to try to get it running more smoothly.
Remove unnecessary lfe_doc.hrl include, as well as the unused docs field
added to #comp{}.
Ensure every to-* compiler option works by replacing {ok,...} with
#module{...}
Reduce redundancy and codify implementation. debug_print/3 => ?DEBUG/3 when_opt/3 => ?WHEN_OPT/3
Clean up the implementation too. N.B. You can still make a it explode by passing a compiler option that results in no binary being returned, e.g. to-core.
Add test/prop_lfe_doc.erl for the PropEr tests and use Fred's plugin.
Override its PropEr dependency so we use master, not 1.1.1-beta.
Now you can do:
$ rebar3 eunit # -m lfe_doc
$ rebar3 proper # -m prop_lfe_doc
$ rebar3 proper -m prop_lfe_doc -p prop_define_lambda
$ rebar3 proper -m prop_lfe_doc -p prop_define_match
$ rebar3 proper --any_to_integer --max_size 42
et cetera.
Enable `rebar3 {ct,eunit,proper}`.
N.B. I left the win32 pre_hooks commented out, because I can't test.
... and regenerate docs with Pandoc 1.17.0.3.
Use allow_missing_chunks option to beam_lib:chunks/3 for a slightly cleaner match.
|
This should be good to go now, @rvirding. |
|
The changes to rebar.config may break old The added bonus is the following commands now work: $ rebar3 ct
$ rebar3 eunit
$ rebar3 proper... which may be useful to @arpunk (see his comment), among others. |
|
I'm going to write some macros today that generate record accessors. I'd love to have the resultant functions/docstrings end up in the LDoc chunk. If that's not the case, we should consider moving the |
|
Levaindoc's |
|
I will merge it tonight or tomorrow then we can check where is the best place to put do_docs and I will make any necessary changes to the compiler. This feels good. |
|
Sounds good to me. 😄 |
|
Confirmed. Macro-generated functions show up in the LDoc chunk. |
Add the
do_docscompiler pass, which prepares and writes the"LDoc"beam chunk in every compiled module, unless theno-docsflag is set. Closes #211.N.B. This also includes some tooling updates, mostly w.r.t. rebar3, but that shouldn't affect anything negatively. Famous last words...