SSLR

262 views
Skip to first unread message

Ali el ghourassi

unread,
Aug 10, 2017, 3:39:48 AM8/10/17
to SonarQube
Hello Everybody
 
  i want to developpe a new plugin analytic for NCL language so i shoulde use SSLR but i didn't know how to start can anybody who already used SSLR redircte me 
 and thanks.

Ali el ghourassi

unread,
Aug 10, 2017, 3:41:30 AM8/10/17
to SonarQube
i found example of sslr projet but i don't know what i should change 

G. Ann Campbell

unread,
Aug 10, 2017, 8:37:16 AM8/10/17
to SonarQube
Hi,

There are several old threads in this group about writing new language analyzers. You should look over them and examine the existing open source analyzers. In particular, the Lua analyzer looks fairly lightweight & might be a good one to emulate. (Disclosure: I've never used the Lua analyzer.)


Ann

Ali el ghourassi

unread,
Aug 10, 2017, 12:16:52 PM8/10/17
to SonarQube
Thanks Ann
But what i should change in Lua analyzer for becom NCL analyzer


Le jeudi 10 août 2017 09:39:48 UTC+2, Ali el ghourassi a écrit :

G. Ann Campbell

unread,
Aug 10, 2017, 12:43:58 PM8/10/17
to Ali el ghourassi, SonarQube
Hi,

That's not something I can tell you off-hand. When you study the Lua analyzer what parts of it don't look like they're handling NCL?


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/1PC06SB-x_c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/c0b5af39-6378-4a38-a54f-48cbc7738585%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott B.

unread,
Aug 10, 2017, 1:14:06 PM8/10/17
to SonarQube, elghouras...@gmail.com
Hi.

I would recommend to not dive in plugin development unless you are a experienced developer. There isn't any end-to-end documentation explaining how to develop a SonarQube plugin using SSLR to create a parser, because it's hard to explain.

Anyway, I can try to give you an overview, based on the Lua plugin:

There are 4 modules:
- lua-checks: contains the coding rules
- lua-squid: contains the parser, it will allow you to interpret and "make sense" of your code
- sonar-lua-plugin: the SonarQube specific code to save the issues and metrics
- sslr-lua-toolkit: a simple app to test your parser (implemented in the lua-squid project)

It's easier to start from the lua-squid module. The main class here is LuaGrammar. It basically contains all the instructions to parse a file. You must describe the whole structure of your language here. The SSLR api is very descritive, look at the definition of the IF statement:

b.rule(IF_STATEMENT).is(Keyword.IF, EXP, Keyword.THEN, BLOCK, b.zeroOrMore(Keyword.ELSEIF, EXP, Keyword.THEN, BLOCK), b.optional(Keyword.ELSE, BLOCK), Keyword.END);

I don't know anything about Lua, but I can see that this represent something like this:

if expression then
(...)
elsif expression then
(...)
elsif expression then
(...)
else
(...)
end

See the test code too: https://github.com/SonarQubeCommunity/sonar-lua/tree/master/lua-squid/src/test/java/org/sonar/lua/grammar

After you have a basic parser, study the other classes and modules. The sonar-lua project is almost a giant boilerplate with everything you need to do.

On Thursday, August 10, 2017 at 1:43:58 PM UTC-3, G. Ann Campbell wrote:
Hi,

That's not something I can tell you off-hand. When you study the Lua analyzer what parts of it don't look like they're handling NCL?


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

On Thu, Aug 10, 2017 at 12:16 PM, Ali el ghourassi <elghouras...@gmail.com> wrote:
Thanks Ann
But what i should change in Lua analyzer for becom NCL analyzer

Le jeudi 10 août 2017 09:39:48 UTC+2, Ali el ghourassi a écrit :
Hello Everybody
 
  i want to developpe a new plugin analytic for NCL language so i shoulde use SSLR but i didn't know how to start can anybody who already used SSLR redircte me 
 and thanks.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/1PC06SB-x_c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

Ali el ghourassi

unread,
Aug 24, 2017, 3:50:02 AM8/24/17
to SonarQube, elghouras...@gmail.com
Thanks Ann and Scott for all your explain
i want to creat  Grammar for ncl language for example if i want to get the value of VAR

exp:
        String name="Jack";

      LexerlessGrammarBuilder b = LexerlessGrammarBuilder.create();

b.rule(STR).is("String"); b.rule(NUB).is("Number"); b.rule(VARR).is(b.next(STR));

so in this example VARR='name' ???

and how can i get Jack ???

Ali el ghourassi

unread,
Aug 24, 2017, 5:14:21 AM8/24/17
to SonarQube, elghouras...@gmail.com
example of zeroOrMore, firstOf, next

Ali el ghourassi

unread,
Aug 29, 2017, 6:33:05 AM8/29/17
to SonarQube, elghouras...@gmail.com
Hi
how can i test the lenght of String in this example :
String Name (20)

b.rule(Lenth).is(Punctuator.LPARENTHESES,NUMBER, Punctuator.RPARENTHESES);

it is right  ???

Ali el ghourassi

unread,
Aug 30, 2017, 10:25:23 AM8/30/17
to SonarQube, elghouras...@gmail.com
Hello EveryBody

i want to develope analyzer for Ncl Language so I should make NclGrammar 
but i don't know  how start and with what 
for example in Ncl Language this is how we declare Var :  

String Name (20) 

and for comment is like :

; this is the name of user

and whene we call a function it's like :

CodeRet=FunctionName(Param1,Param2,Param3)

so how can start NclGrammar

public enum NclGrammar implements GrammarRuleKey { 
??????  }

Thanks 
Ali

Ali el ghourassi

unread,
Sep 6, 2017, 3:39:59 AM9/6/17
to SonarQube, elghouras...@gmail.com
Hello everybody

i want to creat Grammar for NCL language 

public enum NclGrammar implements GrammarRuleKey { 
??????  }

but i don't know  how start and with what 
and what (zeroOrMore,firstOf ...) means
please if anybody can helpe
 thanks

G. Ann Campbell

unread,
Sep 6, 2017, 7:28:34 AM9/6/17
to Ali el ghourassi, SonarQube
Hi,

There are not step-by-step instructions for this. The best thing you can do is to look at an existing, open-source analyzer and try to deconstruct it.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/e49405ef-a0c7-49b2-8484-cbe476df690c%40googlegroups.com.

Ali el ghourassi

unread,
Sep 6, 2017, 10:31:26 AM9/6/17
to SonarQube, elghouras...@gmail.com
Thanks Ann Campbell  for your responce 
I have an existing Analyzer Lua and i study all the code source and i understand it  and i change everythings for became analyzer ncl  but when i want to develope  NclGrammar (Grammar for NCL language) i don't know how because i don't find anythings in internet that explain what means (zeroOrMore,firstOf ,next......) and how we can developpe grammar for X Language 
it's the only thing who i can't change  i changed all othere packages and classes .
thanks for anyhelp Ann.

G. Ann Campbell

unread,
Sep 6, 2017, 10:32:55 AM9/6/17
to Ali el ghourassi, SonarQube
Hi Ali,

Do you have any guesses about what those things mean?


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/7d375e19-32f5-4809-94ac-0bf538d85ba3%40googlegroups.com.

Ali el ghourassi

unread,
Sep 6, 2017, 11:26:20 AM9/6/17
to SonarQube, elghouras...@gmail.com
Hi Ann

you mean(zeroOrMore,firstof,next ....) ???

i think these thingts helps the analyzer to describe the architecture of the language 

G. Ann Campbell

unread,
Sep 6, 2017, 11:28:32 AM9/6/17
to SonarQube, elghouras...@gmail.com
Hi Ali,

That sounds like a good start.

But you're not going to get a lot of help unless you make your questions more specific, and start a new thread for each specific question.


Ann

P.S. I've never written a grammar, so I really have no idea what to tell you on this subject.

Ali el ghourassi

unread,
Sep 6, 2017, 11:33:20 AM9/6/17
to SonarQube, elghouras...@gmail.com
Hi Ann thanks
so i should start a new thread that i demande how can create NclGrammar 

G. Ann Campbell

unread,
Sep 6, 2017, 11:38:28 AM9/6/17
to Ali el ghourassi, SonarQube
Hi,

No. First, perhaps this is just an issue of perception of meaning, but I would never "demand" anything in a community forum.

Second. "How can I create an NclGrammer" is not a specific question. You should dive into an attempt, and then come back with something like "I'm trying to create an NclGrammer and I've gotten X far, but I'm stuck on Y. I've tried Z but got AA result, which is not what I expected because of BB."


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/a64c2a3d-cf55-4bb6-9e82-e153cfc73b5a%40googlegroups.com.

Ali el ghourassi

unread,
Sep 6, 2017, 12:04:50 PM9/6/17
to SonarQube, elghouras...@gmail.com
Hi everybody,
I have In my NclGrammar  

b.rule(NAME).is(
        b.nextNot(KEYWORD),
        b.regexp("\\p{javaJavaIdentifierStart}++\\p{javaJavaIdentifierPart}*+"),
        SPACING);

b.rule(SPACING).is(
    b.skippedTrivia(b.regexp("\\s*+")),
    b.zeroOrMore(
    b.commentTrivia(COMMENT),
    b.skippedTrivia(b.regexp("\\s*+")))).skip();

 String[] keywordValues = new String[Keyword.values().length];
    for (int i = 0; i < keywordValues.length; i++) {
      Keyword keyword = Keyword.values()[i];
      b.rule(keyword).is(keyword.value, SPACING);
      keywordValues[i] = keyword.value;
    }
    b.rule(KEYWORD).is(firstOfRules(b, keywordValues), b.nextNot(b.regexp("\\p{javaJavaIdentifierPart}")));

b.rule(COMMENT).is(b.firstOf(
        b.sequence(";", LONGSTRING),
        b.sequence(";", b.regexp("[^\\n\\r]*+"))));

and for example whene i analyser 

FirstName = "ali"

get NclGrammar.NAME give me FirstName 

ok all things is ok

but whene i analyser 
String FirstName = "ali"

error parsing 
so what i should change and where is the error .
thanks
ali

Ali el ghourassi

unread,
Sep 12, 2017, 3:54:51 AM9/12/17
to SonarQube
Hi 
if there is anybody in this groupe who already used  LexerLess Grammar.

Ali el ghourassi

unread,
Oct 4, 2017, 9:43:20 AM10/4/17
to SonarQube
Hi everyBody
i have this message when i want parse my file :

ERROR org.sonar.squidbridge.AstScanner - Unable to parse file: TestAli.txt
ERROR org.sonar.squidbridge.AstScanner - Parse error at line 1 column 1:

what's the probleme and can i skip this error 
Reply all
Reply to author
Forward
0 new messages