From bc48b5d62ffa1e8347acd15716e19720715fd249 Mon Sep 17 00:00:00 2001 From: radrow Date: Tue, 8 Jun 2021 11:43:36 +0200 Subject: [PATCH] Styling in doc gen --- src/aeb_fate_generate_docs.erl | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/aeb_fate_generate_docs.erl b/src/aeb_fate_generate_docs.erl index e69a77c..a80e188 100644 --- a/src/aeb_fate_generate_docs.erl +++ b/src/aeb_fate_generate_docs.erl @@ -7,14 +7,13 @@ , gen_protocol_description_of_operations/1 ]). +-define(LIMA_PROTOCOL_VSN, 4). +-define(IRIS_PROTOCOL_VSN, 5). + generate_documentation(Filename, Fields) -> generate_documentation(Filename, Fields, fun(_) -> true end). generate_documentation(Filename, Fields, Filter) when is_function(Filter, 1) -> {ok, File} = file:open(Filename, [write]), - Instructions = - lists:flatten( - [gen_doc_for_op(Op, [F || F <- Fields]) - ++ "\n" || Op <- aeb_fate_generate_ops:get_ops(), Filter(Op)]), Header = lists:flatten( "|" ++ [" " ++ header_name(F) ++ " |" || F <- Fields] ++ "\n" @@ -23,6 +22,10 @@ generate_documentation(Filename, Fields, Filter) when is_function(Filter, 1) -> lists:flatten( "|" ++ [" " ++ ["-" || _ <- header_name(F)] ++ " |" || F <- Fields] ++ "\n" ), + Instructions = + lists:flatten( + [gen_doc_for_op(Op, Fields) + ++ "\n" || Op <- aeb_fate_generate_ops:get_ops(), Filter(Op)]), io:format(File, "~s~s~s\n", [Header, Separator, Instructions]), file:close(File). @@ -81,14 +84,28 @@ gen_doc_for_op(#{ opname := OpName lists:seq(0,length(FateFormat)-1))]) end; doc -> Doc; - gas -> io_lib:format("~p", [Gas]); + gas when is_integer(Gas) -> io_lib:format("~p", [Gas]); + gas when is_list(Gas) -> + lists:flatten( + string:join( + [ io_lib:format( + "~p (~s)", + [GasVal, protocol_name(Prot)] + ) + || {Prot, GasVal} <- Gas + ], ", ")); arg_types -> io_lib:format("~p", [ArgTypes]); res_type -> io_lib:format("~p", [ResType]) end - || Field <- Fields + || Field <- Fields ], " | ") ++ " |". +protocol_name(?LIMA_PROTOCOL_VSN) -> + "lima"; +protocol_name(?IRIS_PROTOCOL_VSN) -> + "iris". + format_arg_doc({a, N}) -> io_lib:format("Arg~w", [N]); format_arg_doc({is,_N}) -> "Identifier"; format_arg_doc({ii,_N}) -> "Integer";