grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

[Ada] Add Ada 2022 grammar

Open ethindp opened this issue 1 year ago • 6 comments

Has anyone considered adding the grammar for Ada 2022? I'm not positive precisely what all the differences are (there are some new keywords and definitely some syntactic rules). I found this grammar but it doesn't seem to lex/parse properly with even decently-valid Ada programs (which is a bit of a problem).

ethindp avatar Aug 08 '24 23:08 ethindp

Assuming we write a new grammar, do you have a test suite of some sources that we can add to make sure the new grammar will work?

kaby76 avatar Aug 09 '24 17:08 kaby76

@kaby76, of course! All Ada 2012 code is valid ada 2022 code, as is ada 2005 and 95 code, and the Ada reference manual has examples for pretty much all syntactic constructs if I'm not mistaken. So even the old test cases will work.

ethindp avatar Aug 09 '24 21:08 ethindp

@kaby76 Do you want me to send in a PR of test cases? (I've got a massive folder of files of test code, some of which isn't meant to be standalone, and a lot of which is, from RosettaCode, and then there's the ACATS as well.) The ultimate goal would just be to provide a parse tree, not do semantic analysis or anything like that.

ethindp avatar Aug 15 '24 15:08 ethindp

@kaby76 Do you want me to send in a PR of test cases?

If you can, post here as .zip (or .tar.gz it GH will accept it), or create a PR for a new grammar for Ada2022 with the tests.

kaby76 avatar Aug 16 '24 09:08 kaby76

@kaby76 Here you go: tests.tar.gz

This archive is divided into two directories. In alphabetical order:

  • The acats directory contains the full Ada Conformity Assessment Test Suite (ACATS), which has many more requirements than just being able to parse, but parsing them is a great way of exercising the generated parser. The docs are also there if you'd like to go through it and pick and choose what we'd like to keep and what we don't want. Class A, C, and D tests (so, those in the A, C*, and D* directories) are supposed to parse successfully with no errors. Class B tests (in directory B*) are supposed to fail. We can probably ignore classes E and L, since these aren't relevant to us; I've included them (and the other ACATS code) for completeness.
  • The rosettacode directory contains a huge number of task code from RosettaCode. I am not 100-percent certain how much of these are supposed to pass and how much are supposed to fail, so I'd say the general rule is the more we can get to pass the better. Obviously, if the licensing concerns are a problem (RosettaCode is under the FDL 1.2/1.3) then we don't need to include these. Some of these files will (always) fail since they're not full compilations, but that's okay. So don't expect a 100-percent pass rate with these.

Looking at the tests FAQ, it doesn't appear at a glance that trgen allows for specifying what is expected to pass and what is expected to fail or things like that. The simplest, I think, is to start with the ACATS, classes A, C and D, and make sure that they at least parse. Feel free to pick and choose what tests you'd like to keep and which ones you don't want. So, I think a good desc.xml might be something like:

<?xml version="1.0" encoding="UTF-8" ?>
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../_scripts/desc.xsd">
   <targets>Antlr4ng;CSharp;Cpp;Dart;Go;Java;JavaScript;PHP;Python3;TypeScript</targets>
   <inputs>acats/A/*.*</inputs>
   <inputs>acats/B*/*.*</inputs>
   <inputs>acats/C*/*.*</inputs>
   <inputs>acats/D/*.*</inputs>
</desc>

(I don't know if you can specify <inputs> multiple times, so...) I hope this isn't too much! If I can help in anyway, let me know! :)

Edit: It's worth noting that some of the tests in class B (if we include those) might pass. I'm not certain which ones are ones that would fail in semantic analysis and which ones just have syntactic errors. I know this complicates things :-( Like I said though, I'm happy to help in anyway.

ethindp avatar Aug 16 '24 17:08 ethindp

Thanks so much!

kaby76 avatar Aug 17 '24 11:08 kaby76