1
votes

I want a Xtext grammar that allows me to write MIME media types this way:

mediaType application/atom+xml 
specURL "http://www.rfc-editor.org/rfc/rfc4287.txt",

This is not a problem, but the following is:

mediaType application/* 
specURL "http://www.iana.org/assignments/media-types/application",

You can guess of the troubles ahead with the /* characters that usually define a multi-line comment. The terminal for it is defined in the default Terminals provided by Xtext, more specifically in the ML_COMMENT terminal:

terminal ML_COMMENT : '/*' -> '*/';

I customized it by copying the default terminals to a new one of my own, where the ML_COMMENT terminal is defined this way instead:

terminal ML_COMMENT : '"""' -> '"""';

This produces a more Pythonistic way to have multi-line comments. It works fine in the generated DSL. But the /* characters still pose problem when I try to define the media type for application/*, as shown above. I get an error message of mismatched input '/*' expecting '}' (the } character would specify the end of the media types listing).

Even more troubling is that the content assist of the Xtext editor still auto-fill an ending */ multi-line comment characters when I type a (supposedly obsolete) /* combo characters. As I overrode the multi-line comment terminal, I am wondering why the auto-complete still flirts with the older ML_COMMENT definition. Do I need to override something else?

Here are some fragments for the media type grammar:

MediaType returns restapi::MediaType:
{restapi::MediaType}
'mediaType' name=MediaTypeQualifier ('specURL' specURL=EString)?;

MediaTypeQualifier:
    MediaTypeFragment ('/' MediaTypeFragment)?(';' MediaTypeFragment'='MediaTypeFragment)*; 

MediaTypeFragment:
    (ID ( ('-'|'+'|'.') ID )* ) | '*'

I am using Xtext version 2.3.1 within Eclipse 4.2.2. Does anyone have experience with overriding the multi-line comment terminal? Is there something that I missed?

1

1 Answers

0
votes

It's hard to tell from the grammar snippet that you provided, but it appears to me that you still have a keyword /* somewhere in your grammar.