aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lkn/core/specs.ex
blob: 4a62820eb4b9e639342403471304440b98f110bd (plain)
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
defmodule Lkn.Core.Specs do
  @moduledoc false

  def parse_specs(block, casts, calls, legit) do
    case block do
      [{:@, _, [{:doc, _, [docstring]}]},
       {:@, _, [{:cast, _, [fun]}]}
        |rest] ->
        cast = %Cast{Cast.parse(fun)|doc: docstring}
        parse_specs(rest, [cast|casts], calls, legit)
      [{:@, _, [{:doc, _, [docstring]}]},
       {:@, _, [{:call, _, [fun]}]}
        |rest] ->
        call = %Call{Call.parse(fun)|doc: docstring}
        parse_specs(rest, casts, [call|calls], legit)
      [{:@, _, [{:cast, _, [fun]}]}
        |rest] ->
        cast = Cast.parse(fun)
        parse_specs(rest, [cast|casts], calls, legit)
      [{:@, _, [{:call, _, [fun]}]}
        |rest] ->
        call = Call.parse(fun)
        parse_specs(rest, casts, [call|calls], legit)
      [x|rest] ->
        parse_specs(rest, casts, calls, [x|legit])
      [] -> {casts, calls, Enum.reverse(legit)}
    end
  end
end