-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
73 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Zig.Doc.Sema do | ||
@type type :: atom | ||
|
||
@type fun :: %{ | ||
name: atom, | ||
return: type, | ||
args: [type], | ||
} | ||
|
||
@type const :: %{ | ||
name: atom, | ||
type: type | ||
} | ||
|
||
@type file :: %{ | ||
functions: [function], | ||
consts: [const], | ||
types: [type] | ||
} | ||
|
||
def new(addin \\ []) do | ||
Enum.into(addin, %{functions: [], consts: [], types: []}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
defmodule Zig.Doc.Spec do | ||
@spec from_sema(term) :: Macro.t | ||
def from_sema(sema) do | ||
alias Zig.Doc.Sema | ||
|
||
name = :function_name_placeholder | ||
return_type = {:placeholder, [], Elixir} | ||
args = [] | ||
@spec function_from_sema(Sema.fun) :: Macro.t | ||
|
||
args = Enum.map(args, fn type -> {type, [], Elixir} end) | ||
def function_from_sema(fun) do | ||
name = fun.name | ||
return_type = {fun.return, [], Elixir} | ||
args = Enum.map(fun.args, fn type -> {type, [], Elixir} end) | ||
|
||
spec = {:"::", [], [{name, [], args}, return_type]} | ||
{:ok, spec} | ||
{:"::", [], [{name, [], args}, return_type]} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
defmodule ZigDocTest.Documentation.ModuleTest do | ||
defmodule ZigDocTest.Documentation.FunctionTest do | ||
use Zig.Doc.Case, async: true | ||
|
||
alias Zig.Doc.Sema | ||
|
||
test "function-level documentation is generated" do | ||
expect_sema({:ok, %{}}) | ||
expect_sema({:ok, Sema.new(functions: [%{name: :foo, return: :i32, args: [:i32]}])}) | ||
|
||
assert %{docs: [function]} = | ||
get_module("test/_sources/function.zig") | ||
|
||
assert [{:p, [], [" this is the function foo"], %{}}] = function.doc | ||
assert "foo(value: i32) i32" = function.signature | ||
|
||
assert_code(""" | ||
foo(i32) :: i32 | ||
""", | ||
function.specs) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters