-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_readme.ex
executable file
·40 lines (37 loc) · 1.01 KB
/
generate_readme.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env elixir
IO.puts "<!-- AUTOMATICALLY GENERATED DO NOT EDIT -->"
IO.puts ""
Path.join(__DIR__, "libforks.h")
|> File.read!
|> String.split("\n")
|> Enum.reject(fn l -> String.ends_with?(l, "// no doc") end)
|> Enum.chunk_while(
{:code, ""},
fn line, {state, acc} ->
if String.starts_with?(line, "//") do
comment = String.trim(String.slice(line, 2, String.length(line)))
case state do
:comment -> {:cont, {:comment, acc <> "\n" <> comment}}
:code -> {:cont, {state, acc}, {:comment, comment}}
end
else
case state do
:comment -> {:cont, {state, acc}, {:code, line}}
:code -> {:cont, {:code, acc <> "\n" <> line}}
end
end
end,
fn {state, acc} ->
{:cont, {state, acc}}
end
)
|> Enum.map(fn {kind, text} -> {kind, String.trim(text)} end)
|> Enum.filter(fn {_kind, text} -> text !== "" end)
|> Enum.map(
fn
{:code, text} -> "```c\n" <> text <> "\n```\n"
{:comment, text} -> text <> "\n"
end
)
|> Enum.join("\n")
|> IO.puts()