Ada-Rapporteur-Group / User-Community-Input

Ada User Community Input Working Group - Github Mirror Prototype
27 stars 1 forks source link

Extend Ada with a language for querying Ada #26

Open pjljvandelaar opened 1 year ago

pjljvandelaar commented 1 year ago

Analysis and manipulation of code is essential to maintain that code.

Regular expressions are a well-known technique to find matching pieces of text. Regular expressions have concepts like back-references (same pieces of text within the match) and wildcards (arbitrary pieces of text in the match). Regular expressions are text based so not a perfect fit for analysis and manipulation of Ada code:

Recently Ada query languages that extend the Ada programming language are proposed (see e.g. Rejuvenation Ada). These extensions exploit that

  1. The Ada programming language only allows $ within character and string literals.
  2. Libadalang (an Ada parser) allows variables to start with $.

However, these extensions are not perfect A. Complex AST nodes, such as a parameter declaration, can't be specified and matched. B. Depend on tools supporting $ extensions that might change in the future. C. Use $S_and $M_ to distinguish between a single AST node and multiple AST nodes, where notations closer to e.g. Kleene star are more user-friendly.

Can the Ada standard be extended with an Ada analysis standard such that analysis and manipulation of Ada code is also standardized? This helps both tool builders/providers and users. In particular, only a single querying language has to be learned (which is very close to the Ada concrete syntax), and it prevents lock-in to a specific tool provider.

ARG-Editor commented 1 year ago

A description of this sort of thing would seem to be as large as the language itself, and as such would make sense as a secondary standard (not part of Ada itself). There is no notion of an AST in the Ada language, for example, one would have to be defined. And existing compilers probably have wildly differing notions of what an AST node looks like (Janus/Ada doesn't use an AST internally at all, it does most of its processing on trees of stack-based intermediate code), it's very unlikely that much could be done without major surgery on implementations.

                                   Randy.
pjljvandelaar commented 1 year ago

I agree that there is no notion of an AST in the Ada language. However, some notion of structure, such as matching brackets and mandatory tokens, in Ada is present in any tool that processes the Ada language.

I disagree that the description would be as large as the Ada language itself: Only the extension of the Ada language needs to be described.

Finally, the specification is implementation independent. Of course, some current implementations might be easier to extend to support the Ada analysis specifications than others, but that is the case for any change to the Ada language.

sttaft commented 1 year ago

It is of course hard to predict the size of such a standard, but in any case, it deserves its own document, rather than adding it to the Ada Language Standard. Note that there is a standard similar to what you propose, namely the Ada Semantic Interface Set (ASIS -- see https://en.wikipedia.org/wiki/Ada_Semantic_Interface_Specification). Some effort was made to keep it up to date with the Ada language standard, but ultimately the effort was abandoned because of the size of the standard (it was quite large), and the fact that no vendor was committed to supporting the proposed extensions.

If you believe strongly in such an interface, you would need to foster the creation of an initial draft of the specification, and probably produce an open-source prototype implementation.

jprosen commented 1 year ago

Le 31/10/2022 à 13:52, S. Tucker Taft a écrit :

It is of course hard to predict the size of such a standard, but in any case, it deserves its own document, rather than adding it to the Ada Language Standard. Note that there is a standard similar to what you propose, namely the Ada Semantic Interface Set (ASIS -- see https://en.wikipedia.org/wiki/Ada_Semantic_Interface_Specification). Some effort was made to keep it up to date with the Ada language standard, but ultimately the effort was abandoned because of the size of the standard (it was quite large), and the fact that no vendor was committed to supporting the proposed extensions.

Note that there was a workshop at the latest AE conference, that showed interest in pursuing and updating the ASIS standard - including interest from one vendor. Proceedings to appear in an upcoming issue of the Ada User Journal.

-- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX https://www.adalog.fr https://www.adacontrol.fr

sttaft commented 1 year ago

Note that there was a workshop at the latest AE conference, that showed interest in pursuing and updating the ASIS standard - including interest from one vendor. Proceedings to appear in an upcoming issue of the Ada User Journal.

Good to know! I'll look forward to seeing the Proceedings.