|
Re: -- Comments and accept until new line [message #556774 is a reply to message #556772] |
Thu, 02 September 2010 15:05 |
|
Hi Anatoli,
Quote: |
I have found comment=LINE("--") should do the trick, but my the grammar-compiler does not know the abstract rule LINE...
|
can elaborate a bit more on this?
maybe you stumbled over the pretty old oAW Xtext docu - there was such a TOKEN - this no longer exists
But why don't you just adapt the comment rule from the Terminals grammar e.g.:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden(SPECIAL_COMMENT,WS, ML_COMMENT, SL_COMMENT)
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
elements+=Element*;
Element: "element" name=ID;
terminal SPECIAL_COMMENT : '--' !('\n'|'\r')* ('\r'? '\n')?;
Regards
Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Thu, 02 September 2010 15:21] Report message to a moderator
|
|
|
Re: -- Comments and accept until new line [message #556777 is a reply to message #556774] |
Thu, 02 September 2010 15:16 |
No real name Messages: 16 Registered: September 2010 |
Junior Member |
|
|
Hi Christian, gladly!
normally we have
// this is a comment, I can have ';' inside but the end of the line will finish the comment
var a = '10';
// that was a piece of code
at the moment I only want to be able to use '--' instead of '//' for comments
then I have another similar problem: // and /* */ are skipped as they are SL_COMMENT or ML_COMMENT by default. But I want to have a grammar for the content of the comments too.
[Updated on: Thu, 02 September 2010 15:18] Report message to a moderator
|
|
|
|
|
Re: -- Comments and accept until new line [message #556793 is a reply to message #556778] |
Thu, 02 September 2010 15:58 |
No real name Messages: 16 Registered: September 2010 |
Junior Member |
|
|
thank you Christian! Thanks a lot really - very helpful!!
with this code almost everything works fine except:
-- globale Variablen
mismatched input '-- globale Variablen\r\n' expecting 'END' example.mydsl /example/src line: 47 /example/src/example.mydsl Xtext Check (fast)
do I understand this right:
terminal SPECIAL_COMMENT : '--' !('\n'|'\r')* ('\r'? '\n')?;
means you can have '--' followed by everything except \n or \r and can be finished by \n, so I don't get why the following doesn't work
terminal SPECIAL_COMMENT : '--' !('\n'|'\r')* ('\r'? '\n')?;
PackageHeaderDeclareBlock:
{PackageHeaderDeclareBlock}(lines+=DeclarationLine)*;
DeclarationLine:
{DeclarationLine}(expr=Expression ';' | comment=SPECIAL_COMMENT);
Expression:
ID(ID|INT|STRING|'('|')'|'*'|'/'|'-'|':'|'='|','|'|'|'>'|'<'|'.'|'+')*;
[Updated on: Thu, 02 September 2010 16:02] Report message to a moderator
|
|
|
|
|
Re: -- Comments and accept until new line [message #556824 is a reply to message #556801] |
Thu, 02 September 2010 17:45 |
|
Hi,
your Expression and ANything rules are amigous.
maybe you want something like:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
header=PackageHeader body=PackageBody;
PackageHeader:
literal=CreateOrReplacePackage packagename=ID is=IS content=PackageHeaderContent end=END
packegename=ID ';' ('/')?;
PackageHeaderContent:
declareBlock=PackageHeaderDeclareBlock;
PackageHeaderDeclareBlock:
{PackageHeaderDeclareBlock}(lines+=DeclarationLine)*;
DeclarationLine:
{DeclarationLine}(expr=Expression ';' | comment=SPECIAL_COMMENT);
PackageBody:
literal1=CreateOrReplacePackage literal2=Body packagename1=ID is=IS content=Dummy end=END
packagename2=ID ';' ('/')?;
CreateOrReplacePackage:
sentence='CREATE OR REPLACE PACKAGE';
Body:
sentence='BODY';
Dummy:
{Dummy}(dummy+=Anything)*;
IS:
is='IS';
END:
end='END';
Anything: {Anything}(expr=Expression|';'|inner=Inner);
Inner: is=IS (dummy+=Anything)* end=END;
Expression:
ID(INT|STRING|'('|')'|'*'|'/'|'-'|':'|'='|','|'|'|'>'|'<'|'.'|'+')*;
terminal SPECIAL_COMMENT : '--' !('\n'|'\r')* ('\r'? '\n')?;
a comment in the body won't be allowed since you don't allow it in the grammar
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.05192 seconds