Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » -- Comments and accept until new line
-- Comments and accept until new line [message #556772] Thu, 02 September 2010 15:01 Go to next message
No real name is currently offline No real nameFriend
Messages: 16
Registered: September 2010
Junior Member
I need to accept the following:

-- means comment (new line must end the comment: '\r' '\n' ?)

packagename CONSTANT VARCHAR2(30) := 'SYSSTAT';
-- globale Variablen
sql VARCHAR2(10000);
--

I have found comment=LINE("--") should do the trick, but my the grammar-compiler does not know the abstract rule LINE...

so how can I accomplish that?

Best Regards

Anatoli
Re: -- Comments and accept until new line [message #556774 is a reply to message #556772] Thu, 02 September 2010 15:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
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 #556778 is a reply to message #556777] Thu, 02 September 2010 15:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
Hi then just introduce a terminal rule like this

terminal SPECIAL_COMMENT 	: '--' !('\n'|'\r')* ('\r'? '\n')?;


comment=SPECIAL_COMMENT


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: -- Comments and accept until new line [message #556781 is a reply to message #556778] Thu, 02 September 2010 15:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
Btw you can unhide SL_COMMENT and ML_COMMENT using

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden(WS)


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: -- Comments and accept until new line [message #556793 is a reply to message #556778] Thu, 02 September 2010 15:58 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
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 #556794 is a reply to message #556793] Thu, 02 September 2010 16:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
Hi,

can you place file you complete model file?

-- globale Variablen


works fine for me

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 02 September 2010 16:08]

Report message to a moderator

Re: -- Comments and accept until new line [message #556801 is a reply to message #556794] Thu, 02 September 2010 16:28 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 16
Registered: September 2010
Junior Member
here I have my grammar

/*********************************************************** ***/

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals //hidden(WS)

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|';'|is=IS|end=END);

Expression:
ID(ID|INT|STRING|'('|')'|'*'|'/'|'-'|':'|'='|','|'|'|'>'|'<'|'.'|'+')*;

terminal SPECIAL_COMMENT : '--' !('\n'|'\r')* ('\r'? '\n')?;

/*********************************************************** ***/

and this is the test file:

after you told it would work for you, I investigated further and the problem is a different one:

I have CREATE OR REPLACE PACKAGE to introduce the header on the one side and

I have CREATE OR REPLACE PACKAGE BODY to introduce the body on the other side: the problem I think is, that I ignored the warning, that one rule gets disabled:

so the CREATE OR REPLACE PACKAGE BODY is recognized as the header part - not as body part.

though I don't know how to work around(

but the problem with '--' comments is solved!


CREATE OR REPLACE PACKAGE sysstat IS
--
PROCEDURE install_gather_system_stats;
--
PROCEDURE install;
-- global vars works fine
END tvd_sysstat;
/

CREATE OR REPLACE PACKAGE BODY sysstat IS

-- global vars doesnt work

END sysstat;
/

Re: -- Comments and accept until new line [message #556824 is a reply to message #556801] Thu, 02 September 2010 17:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
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
Re: -- Comments and accept until new line [message #556831 is a reply to message #556824] Thu, 02 September 2010 18:03 Go to previous message
No real name is currently offline No real nameFriend
Messages: 16
Registered: September 2010
Junior Member
great!!!!! thanks!!! Christian! Vielmals!
Previous Topic:Validation-Error "An object may not circularly contain itself" validating an gmf-diagram
Next Topic:how to define grammar for: create package ... end; create package body ... end;
Goto Forum:
  


Current Time: Fri Apr 26 19:15:10 GMT 2024

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

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

Back to the top