This post comes in the last week of my GSoC’18 journey !
At the time of writing this post, I have completed the goals mentioned in my project proposal, and am quite satisfied with the outcome as well. Hope my evaluators too find it up to the mark :D.
This post will summarize over what
coantlib is, how is it useful, and what all features it provides, along with some relevant links.
My project, aptly named as
coala-antlr is about integrating ANTLRv4 with coala, so that bear writers can utilise ANTLR based parse tree.
If you aren’t familiar with ANTLR, or have no idea what it is, I have written an introductory post about ANTLR, feel free to read through.
coantlib is the core library package within
coala-antlr and this package is responsible for providing useful utilities for writing ANTLR-parse tree based bears.
coantbears is the library package within
coala-antlr which comprises of bears written with the help of
coantlib. These bears leverage the power of parse-trees in addition to
coala, which means it makes it easier to write code analysis routines.
coala could only provide source lines to a bear, and it was difficult to use these lines to write complicated code-analysis routines. With
coantlib, now bear writers can use these source lines to get a parse tree, which can be traversed and returns relevant information to the bear-writers which makes it easy to focus on writing the code-analysis.
Why parse trees ?
Parse trees are more powerful than simple linear traversal of source line-by-line, and helps do advanced analysis, such as branch analysis of conditional statements and much more.
Thus it is a powerful tool to have when designing / writing linters.
coantlib work ?
coantlib has a concept of
walkers. These walkers are grammar dependent pieces of codes, which need to be written for a given grammar. Once a
walker for a language is written, a bear writer can simply use this
walker to get important information without worrying about how it is extracted from the parse tree.
Thus over time, a walker for a given language will accumulate several useful functions and then a new bear writer can re-use these functions, which drastically reduces the efforts done on part of a bear writer.
A more complete design of
coantlib can be found here
What all is possible after addition of
Since the addition of
coantlib, one can use any arbitrary grammar, create a walker for it and it’s ready to be used to write bears for
This opens a vast array of languages that can be used with coala, since ANTLR already provides lots of grammars already, located in a github repository : https://github.com/antlr/grammars-v4 .
As a part of this project, I’ve already created walkers for two languages –
XML. Find them at: Python3Walker and XMLWalker.
And out of these, I have created three bears, to demonstrate how these walkers can be used:
Out of these,
XMLIndentBear are capable of fixing the errors that they report, and the fixes suggested by
XMLIndentBear are really good.
I encourage the reader to try and hack around (and possibly create a bear as well) in the library which is now available at https://gitlab.com/coala/bears/coala-antlr .
Also docs for this library are currently available at https://virresh.gitlab.io/coala-antlr/ . Although consider this as a mirror, these would soon be hosted officially with coala’s namespace :D.
A big thanks to coala for providing me the opportunity to create this library as their GSoC’18 student, and also a big thanks to my mentors Dong-hee Na for providing guidance and help in shaping this library.
Thanks for reading !