Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding javadoc like annotation support to a grammar
Adding javadoc like annotation support to a grammar [message #491849] Fri, 16 October 2009 08:07 Go to next message
Christoph Kulla is currently offline Christoph KullaFriend
Messages: 48
Registered: July 2009
Member
Hi,

I'm trying to add javadoc like annotation support to my grammar. I'm having problems to capture the free form text. Atm the grammar looks like:

EntityAnnotation:
"<*"
description=STRING
("@author" authors+=STRING)*
"*>";

Entity :
annotation=EntityAnnotation?
'entity' name=ID ('extends' extends=[Entity])? '{'
properties+=Property*
'}';

This results in:

<*
"The first line of the description.
The second line of the description"
@author "Hans Mustermann"
*>
entity Composite extends Composable {
property content: Composable[]
}

But I do not want to have quotation marks. It should look like

<*
The first line of the description.
The second line of the description
@author Hans Mustermann
*>
entity Composite extends Composable {
property content: Composable[]
}

The STRING rule must replaced by something else which consumes everyhting up the next keyword (@author or *>). Is that possible? Any suggestions?

Regards

Christoph
Re: Adding javadoc like annotation support to a grammar [message #492352 is a reply to message #491849] Tue, 20 October 2009 07:35 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Christoph,

it is definitly possible, but I'm currently not aware of an available
example implementation.

The idea would be, to use a datatype rule that basically can consume
everything on the right hand side of your description-assignment.

Another possibility:
1) Use a terminal rule from <* -> *> and assign the value to the
description field.
2) Implement a value converter that removes the leading and trailing <*
/ *>.
3) Provide a custom IAstFactory and override the #set method of the
default implementation for your description feature and identify the
authors manually and assign them to the authors feature. This approach
has some drawbacks but should work, too.

Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Christoph Kulla schrieb:
> Hi,
>
> I'm trying to add javadoc like annotation support to my grammar. I'm
> having problems to capture the free form text. Atm the grammar looks like:
>
> EntityAnnotation:
> "<*" description=STRING
> ("@author" authors+=STRING)*
> "*>";
>
> Entity :
> annotation=EntityAnnotation?
> 'entity' name=ID ('extends' extends=[Entity])? '{'
> properties+=Property*
> '}';
>
> This results in:
>
> <*
> "The first line of the description. The second line of the
> description" @author "Hans Mustermann"
> *>
> entity Composite extends Composable {
> property content: Composable[]
> }
>
> But I do not want to have quotation marks. It should look like
>
> <*
> The first line of the description. The second line of the description
> @author Hans Mustermann
> *>
> entity Composite extends Composable {
> property content: Composable[]
> }
>
> The STRING rule must replaced by something else which consumes
> everyhting up the next keyword (@author or *>). Is that possible? Any
> suggestions?
>
> Regards
>
> Christoph
Re: Adding javadoc like annotation support to a grammar [message #492775 is a reply to message #492352] Wed, 21 October 2009 16:44 Go to previous messageGo to next message
Christoph Kulla is currently offline Christoph KullaFriend
Messages: 48
Registered: July 2009
Member
Hi Sebastian,

thanks for your suggestions. How would such a datatype rule look like? I've played around with something like: AnnotationString: ANY_OTHER*; or even (ANY_OTHER|ID), But this gives not the expected results. Keywords like "entity" are still recognized as keywords and their corresponding rules. I then tried "AnnotationString hidden (Entity): ANY_OTHER*;" . This gives several NPEs in the xtext editor (content assist and hyperlinking).

I want to stick with the datatype approach, as the parsing is done entirely by xtext.

Regards

Christoph
Re: Adding javadoc like annotation support to a grammar [message #492780 is a reply to message #492775] Wed, 21 October 2009 17:11 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Christoph,

please try something like:

AnnotationString: ('entity' | ID | WS | STRING | ANY_OTHER)*;

You'll have to list basically everything that is allowed as an
AnnotationString.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Christoph Kulla schrieb:
> Hi Sebastian,
>
> thanks for your suggestions. How would such a datatype rule look like?
> I've played around with something like: AnnotationString: ANY_OTHER*; or
> even (ANY_OTHER|ID), But this gives not the expected results. Keywords
> like "entity" are still recognized as keywords and their corresponding
> rules. I then tried "AnnotationString hidden (Entity): ANY_OTHER*;" .
> This gives several NPEs in the xtext editor (content assist and
> hyperlinking).
>
> I want to stick with the datatype approach, as the parsing is done
> entirely by xtext.
> Regards
>
> Christoph
Re: Adding javadoc like annotation support to a grammar [message #492795 is a reply to message #492780] Wed, 21 October 2009 17:50 Go to previous message
Christoph Kulla is currently offline Christoph KullaFriend
Messages: 48
Registered: July 2009
Member
Hi,

thanks. This does the trick. I end up with:

AnnotationString: ('entity' | 'extends' | 'type' | 'property' | '{' | '}' | ID | WS | STRING | ANY_OTHER)*;

It's a bit annoying to repeat all the keywords from the grammar.

Next step is to customize the syntax highlighting to not highlighting keywords in AnnotationString.

Regards

Christoph
Previous Topic:Left factoring
Next Topic:How to build an Interpreter in the best way?
Goto Forum:
  


Current Time: Sat Apr 20 01:59:57 GMT 2024

Powered by FUDForum. Page generated in 0.02566 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top