<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">
      <div class="moz-cite-prefix">Hi Guilherme,</div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix">I may understand incorrectly your
        question, but type specs are well-defined in ASTs and stored
        appropriately in them (see
        <a class="moz-txt-link-freetext" href="https://erlang.org/doc/apps/erts/absform.html">https://erlang.org/doc/apps/erts/absform.html</a> for a mostly
        accurately view of the AST grammar), so they can be freely read
        from there and written there as well, either directly (as raw
        terms) or through appropriate, "standard" Erlang API functions.
        <br>
      </div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix">(I preferred the former method and
        apparently it works satisfactorily, for example it is used in
<a class="moz-txt-link-freetext" href="https://github.com/Olivier-Boudeville/Ceylan-WOOPER/blob/712bcc587e73f2da1529b175dfb1d458be36e983/src/wooper_instance_construction.erl#L308">https://github.com/Olivier-Boudeville/Ceylan-WOOPER/blob/712bcc587e73f2da1529b175dfb1d458be36e983/src/wooper_instance_construction.erl#L308</a>
        ; I suppose the AST structure is not likely to change a lot
        anytime soon, and, should this happen, then it will be just a
        matter of updating accordingly the generation logic; I found it
        clearer to generate forms through terms rather than thanks an
        abstracting API)<br>
      </div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix">Hope this helps,</div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix">Olivier.</div>
      <div class="moz-cite-prefix"><br>
      </div>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">Le 12/7/20 à 12:52 AM, Leonard B a
      écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:CAKj1m=Jw3P154MjACYEH+j7k0eFKMwEw7vUreH8ZFa=Y2EDaZQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="auto">Hi Guilherme,
        <div dir="auto"><br>
        </div>
        <div dir="auto">I may be wrong, but I'm pretty sure specs are
          just syntactic sugar for dialyzer (and devs) and are not
          actually included in the AST. Just sounds like you may be
          looking for something that's not there.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Kind regards,</div>
        <div dir="auto">Leonard</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Sun, Dec 6, 2020, 14:13
          Guilherme Andrade <<a href="mailto:g@gandrade.net"
            target="_blank" rel="noreferrer" moz-do-not-send="true">g@gandrade.net</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          <div dir="ltr">
            <div>
              <div>Thanks for the suggestion!<br>
                <br>
              </div>
              After a quick glance, Typer seems to be directly
              generating string representations of the specs - that is,
              not actually manipulating the AST of the modules it works
              on by inserting nodes that represent said specs.<br>
              <br>
            </div>
            That's a shame, but it's what I will also do if I don't find
            a more elegant way to do it through `erl_syntax`. <br>
            <br>
            Oh well.<br>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Sat, 5 Dec 2020 at
              22:29, Fred Hebert <<a href="mailto:mononcqc@ferd.ca"
                rel="noreferrer noreferrer" target="_blank"
                moz-do-not-send="true">mononcqc@ferd.ca</a>> wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div dir="ltr">You might want to look at Typer, since it's
                whole purpose is to generate type specs for code that
                you can directly put in code.<br>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Sat, Dec 5, 2020 at
                  3:25 PM Guilherme Andrade <<a
                    href="mailto:g@gandrade.net" rel="noreferrer
                    noreferrer" target="_blank" moz-do-not-send="true">g@gandrade.net</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">
                  <div dir="ltr">
                    <div>Hello list,</div>
                    <div><br>
                    </div>
                    <div>I've been working on a code-generating tool,
                      leveraging `erl_syntax`[1] to build an AST
                      containing arbitrary Erlang functions; I then use
                      `erl_pp`[2] to generate the corresponding Erlang
                      code and write the result onto a source code file.</div>
                    <div><br>
                    </div>
                    <div>All is well so far, but now I want to generate
                      type specs and function specs with which to
                      annotate the generated code - and I can't for the
                      life of me figure out how to do it within
                      `erl_syntax`.<br>
                      <br>
                      All of the different attempts I've made end up
                      either crashing within `erl_syntax` or `erl_pp`,
                      or at best result in INVALID-FORM literals within
                      the generated code.</div>
                    <div><br>
                    </div>
                    <div>Would any of you be able to point me in the
                      right direction?</div>
                    <div><br>
                    </div>
                    <div>Thanks in advance!<br>
                    </div>
                    <div><br>
                    </div>
                    <div>[1]: <a
                        href="http://erlang.org/doc/man/erl_syntax.html"
                        rel="noreferrer noreferrer" target="_blank"
                        moz-do-not-send="true">http://erlang.org/doc/man/erl_syntax.html</a></div>
                    <div>[2]: <a
                        href="https://erlang.org/doc/man/erl_pp.html"
                        rel="noreferrer noreferrer" target="_blank"
                        moz-do-not-send="true">https://erlang.org/doc/man/erl_pp.html</a></div>
                    <div><br>
                      -- <br>
                      <div dir="ltr">
                        <div dir="ltr">
                          <div>
                            <div dir="ltr">
                              <div>
                                <div dir="ltr">Guilherme<br>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </blockquote>
              </div>
            </blockquote>
          </div>
          <br clear="all">
          <br>
          -- <br>
          <div dir="ltr">
            <div dir="ltr">
              <div>
                <div dir="ltr">
                  <div>
                    <div dir="ltr">Guilherme<br>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <p><br>
    </p>
    <pre class="moz-signature" cols="72">-- 
Olivier Boudeville
</pre>
  </body>
</html>