<div dir="ltr"><div>Hello Olivier,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 7 Dec 2020 at 08:34, Olivier Boudeville <<a href="mailto:olivier.boudeville@online.fr">olivier.boudeville@online.fr</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 bgcolor="#FFFFFF">
    <div>
      <div>Hi Guilherme,</div>
      <div><br>
      </div>
      <div>I may understand incorrectly your
        question, but type specs are well-defined in ASTs and stored
        appropriately in them (see
        <a href="https://erlang.org/doc/apps/erts/absform.html" target="_blank">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></div></blockquote><div><br></div><div>Ahh, true! I encountered that document a few years ago - but I had forgotten about it entirely.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><div><div>
      </div>
      <div><br>
      </div>
      <div>(I preferred the former method and
        apparently it works satisfactorily, for example it is used in
<a href="https://github.com/Olivier-Boudeville/Ceylan-WOOPER/blob/712bcc587e73f2da1529b175dfb1d458be36e983/src/wooper_instance_construction.erl#L308" target="_blank">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></div></blockquote><div><br></div><div>Indeed, I now remember generating specs like this in the past. Thanks!<br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><div><div>
      </div>
      <div><br>
      </div>
      <div>Hope this helps,</div>
      <div><br>
      </div>
      <div>Olivier.</div>
      <div><br>
      </div>
    </div>
    <div><br>
    </div>
    <div><br>
    </div>
    <div>Le 12/7/20 à 12:52 AM, Leonard B a
      écrit :<br>
    </div>
    <blockquote type="cite">
      
      <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" rel="noreferrer" target="_blank">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>
              <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">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">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">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">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 cols="72">-- 
Olivier Boudeville
</pre>
  </div>

</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Guilherme<br></div></div></div></div></div></div></div>