Parse and create an AST for a new language with SSLR

Hi everyone,

I finally finished to write the grammar for a new language inspiring myself from Python’s grammar here: https://github.com/SonarSource/sonar-python/blob/master/python-squid/src/main/java/org/sonar/python/api/PythonGrammar.java

So according to: https://docs.sonarqube.org/latest/extend/new-languages/ , I should now write a parser. However, I really have no idea on how to do that, and when I go to Python’s parser (https://github.com/SonarSource/sonar-python/blob/master/python-squid/src/main/java/org/sonar/python/parser/PythonParser.java), I don’t understand because it seems there is nothing to write. Can you help me please ?

Hi,

Indeed, using SSLR makes it rather easy to have a parser once you have the grammar. According to the doc you mention:

a parser simply parses an input based on your grammar to yield a parse tree

As you started having a look at the Python analyzer, I suppose that you could check PythonSquidSensor and PythonScanner. That should help you understand how you can use the parser to feed metrics and issues to the SonarQube API.

Does that help you?

2 Likes

Oh I’m sorry, I don’t know why, but I never saw that you replied ! Well, that’s what I did and it is now working, but thank you very much for your answer !

1 Like