Announcement: CongoCC includes parsers for the latest Java and Python versions!

As the title says: as of this writing, the included grammars for Java and Python both support the latest versions of the respective languages, i.e. JDK 22 and Python 3.12.

New Java Language Features

Java language features that were not supported until quite recently were:

  • Record patterns introduced as a stable feature in JDK 21. See here
  • Unnamed patterns and variables are a stable feature in JDK 22.

New Python Language Features

By far the most important new language feature in Python 3.12 is the specification of a formal grammar for f-strings. Before 3.12, what was inside an f-string was not specified by the formal grammar for the Python language. Thus, the official Python parser simply treated f-strings as regular string literals and then had a separate parser (implemented ad hoc) that went inside the f-strings and broke them down, hardly an optimal situation. And that was how the Python parser in Congo worked as well -- basically, it treated an f-string as a sort of black box. However, that is not the case any more and the Python grammar included in CongoCC specifies the structure inside of the f-strings. You can see the implementation here and here. The implementation of the f-string grammar was quite challenging and is kind of a showcase for the more powerful features of CongoCC. Of course, there is no need to understand the implementation in order to use this. However, I would say that if you did set yourself the task of understanding thoroughly how f-strings are implemented, you would really be well on your way to being a CongoCC power user!

The generated Python parser can now parse the 1700 line test_fstring.py which is, naturally, full of quite tricky cases.

Python 3.11 introduced type parameters and type aliases which the grammar now handles.

Give it a spin!

To try out the Java parser on any java source code:

 git clone https://github.com/congo-cc/congo-parser-generator.git
 cd congo-parser-generator
 ant
 cd examples/java
 ant

And now you can run the Java parser's test harness via:

 java JParse <files or directory root>

If you pass in just a single file, it will dump a flat text representation of the AST that it built in parsing.

If you want to test the Python parser, the last few lines above would be:

 cd examples/python
 ant
 java PyTest <files or directory root>

As has always been the case, you are free to use and adapt either of these grammars, Java or Python, in your own projects. All feedback is welcome. Consider signing up on our discussion forum.