How to programmatically add comments to a DRL file

1,015 views
Skip to first unread message

sascha.s...@signavio.com

unread,
Mar 17, 2015, 7:55:40 AM3/17/15
to drools...@googlegroups.com
Hi *,

I am currently building a Java app, that exports our custom decision table format into DRL.
To generate the DRL, I am using the drools fluent API.

Is there any way to add comments anywhere in the generated document? I couldn't find any in the API and the documentation doesn't give much detail.

For instance:

package com.drools

//declarations

declare myType
   field : String
end

//rules
rule myRule
   // rule to do XYZ
when
then
end
...

As for the rule I could just use the AttributeDescrBuilder and give it a String, but how would I go about the other cases where comments are to be added outside of rules?

A use case would be the following:
We can export multiple of our documents into a single DRL file. In order to add traceability, the comments could indicate which file a rule was generated out of.

Any help is greatly appreciated.

Thanks,

- Sascha

Edson Tirelli

unread,
Mar 17, 2015, 11:46:06 AM3/17/15
to drools...@googlegroups.com
Sascha,

Unfortunately, there is no internal representation (neither on the
canonical model, nor the execution model) for comments. Comments in
source files are filtered out by the lexer:

C_STYLE_SINGLE_LINE_COMMENT
: '//' (~('\r'|'\n'))* (EOL|EOF)
{ $channel=HIDDEN; }
;

MULTI_LINE_COMMENT
: '/*' (options{greedy=false;} : .)* '*/'
{ $channel=HIDDEN; }
;


So as of 6.2, unless you generate the DRL using a string template
framework, it is not possible to create comments.

Alternatively, as you already figured, to document/link rules and
types you can use custom annotations.

Edson
> --
> You received this message because you are subscribed to the Google Groups
> "Drools Usage" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to drools-usage...@googlegroups.com.
> To post to this group, send email to drools...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/drools-usage/01869cfa-97fc-4bf1-8067-5ad18ed0463e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Edson Tirelli
Principal Software Engineer
Red Hat Business Systems and Intelligence Group

Arpit Tripathi

unread,
Mar 1, 2019, 2:21:56 AM3/1/19
to Drools Usage
Hello Edson,

I too want something very similar for in-line comments in Business Central guided editors. Does any of the latest Business central versions support this? If yes, kindly guide me on how to use.
Reply all
Reply to author
Forward
0 new messages