Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Help for grammar(Why im not able to leave WS between of parameters)
icon8.gif  Help for grammar [message #704218] Thu, 28 July 2011 11:53 Go to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Embarrassed Hello

I am in trouble. Please have a look this with fresh eyes , I dont know what i have to do. I have a grammar as below.

While im coding in something.mydsl I want to allow users to give space as much as they want between of parameter while they are declaring the type NonEmtyLine.

I have multiple terminal Rules Because my some parameters contains some strange characters.

file.modern.novel.someoneelse : boookName :languagenumber[%d],languageId, (orginallanguage|translated)byTranslator : ,,,numbers...so on



import "http://www.eclipse.org/emf/2002/Ecore" as ecore

LibModel:
  (types+=Type)*;            

Type:
  LibComment1|NonEmpityLine|AtShell |Version| languages;

  LcfComment1: 
  	text=HASH_COMMENT
  	  ;  
 
  AtShell:
     "@" ShellName=ID ('=' DOUBLE|INT|'-'INT)?
	;
	
  Version:
  	{Version}
  '@logstart' ('='startNumber=(DOUBLE|'X' ))?;	
	
	languages:
		{languages}
		'@translators=' mytrans=(myID ) ;

 NonEmpityLine : 

   	//allow users leave some space between of parameters

   	Writer=Writer  ':'  WritersBooks=WritersBooks':'  NELTranslator=NELTranslator':'  ('store')?   ( isbn=isbn',' pageNumber=pageNumber)?   (',' Amaunt=Amaunt)?     (':')?

(filter=filter ('&&') | ('||') | ('==') filtered=filtered)?
		
   ;

filtered:
	filtered=Words
;


filter:
	filter=Words
;
NELTranslator:
	NELTranslator= Characters 
;

Writer:
	Writer=Words
;

WritersBooks:
	WritersBooks= Words
;

isbn:
	{isbn}
		isbn= ('-')?((INT)|DOUBLE)
;

pageNumber:
	
	{pageNumber}
	pageNumber=('-')?((INT)|DOUBLE)
;

//for new orders it might me negative value
Amaunt:
	{Amaunt}
	Amaunt=('-')?((INT)|DOUBLE)
	
;

 Words hidden ():  	ID (WS ID)*   ;
 
 Characters hidden () :   myID (WS myID)* ;

   
 terminal WS : (' '|'\t'|'\r'|'\n')+     ;
  
 terminal HASH_COMMENT 	:  '#' !('\n'|'\r')* ('\r'? '\n')?      ;
 
 terminal ID :	'^'?('a'..'z'|'A'..'Z'|'_'|'.') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'.')* 	  ;
 	  
 terminal DOUBLE : INT '.' INT;
 
 terminal INT returns ecore::EInt:	('0'..'9')+  ;
	
 terminal myID: '^'?('a'..'z'|'A'..'Z'|'_'|'.') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'%'|'['|']'|'('|')'|'.'|' '|','|'|' )* ;


[Updated on: Thu, 28 July 2011 13:38]

Report message to a moderator

Re: Help for grammar [message #704222 is a reply to message #704218] Thu, 28 July 2011 11:57 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

NonEmpityLine hidden (WS):...

should be the first thing you try.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Help for grammar [message #704226 is a reply to message #704222] Thu, 28 July 2011 11:58 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Alexander
Nice to hear you ,I have tried that before i posted, it didnt helped

[Updated on: Thu, 28 July 2011 12:13]

Report message to a moderator

Re: Help for grammar [message #704268 is a reply to message #704218] Thu, 28 July 2011 12:15 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
For starters, the terminals ID and myID overlap, you will never get a
myID token if ID matches the input.

To solve the issue use a data rule and have a terminal for only the
additional special characters.

myID = ID (ExtID | ID)* ;
terminal ID = ...as is...;
terminal ExtID = ('%'|'['|']'|'('|')'|'.'|' '|','|'|' )+ ;

Regarding hidden WS - you have to state what to hide for the root node
if you want hiding of WS to take place.

LibModel hidden(WS) : ..... ;

Hope that helps.
Regards
- henrik

On 7/28/11 1:53 PM, Caner wrote:
> Hello
> I am in trouble. Please have a look this with fresh eyes , I dont know
> what i have to do. I have a grammar as below.
>
> While im coding in something.mydsl I want to give allow users to give
> space as much as they want between of parameter while they are typing
> the for NonEmtyLine.
>
> I have multiple terminal Rules Because my some parameters contains some
> strange characters.
>
> file.modern.novel.someoneelse : boookName
> :languagenumber[%d],languageId, (orginallanguage|translated)byTranslator
> ,,,so on
>
>
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> LibModel:
> (types+=Type)*;
> Type:
> LibComment1|NonEmpityLine|AtShell |Version| languages;
>
> LcfComment1: text=HASH_COMMENT
> ;
> AtShell:
> "@" ShellName=ID ('=' DOUBLE|INT|'-'INT)?
> ;
>
> Version:
> {Version}
> '@logstart' ('='startNumber=(DOUBLE|'X' ))?;
>
> languages:
> {languages}
> '@translators=' mytrans=(myID ) ;
>
> NonEmpityLine :
> //allow users leave some space between of parameters
>
> Writer=Writer ':' WritersBooks=WritersBooks':'
> NELTranslator=NELTranslator':' ('store')? ( isbn=isbn','
> pageNumber=pageNumber)? (',' Amaunt=Amaunt)? (':')?
> ;
>
> NELTranslator:
> NELTranslator= Characters ;
>
> Writer:
> Writer=Words
> ;
>
> WritersBooks:
> WritersBooks= Words
> ;
>
> isbn:
> {isbn}
> isbn= ('-')?((INT)|DOUBLE)
> ;
>
> pageNumber:
>
> {pageNumber}
> pageNumber=('-')?((INT)|DOUBLE)
> ;
>
> //for new orders it might me negative value
> Amaunt:
> {Amaunt}
> Amaunt=('-')?((INT)|DOUBLE)
>
> ;
>
> Words hidden (): ID (WS ID)* ;
>
> Characters hidden () : myID (WS myID)* ;
>
> terminal WS : (' '|'\t'|'\r'|'\n')+ ;
>
> terminal HASH_COMMENT : '#' !('\n'|'\r')* ('\r'? '\n')? ;
>
> terminal ID : '^'?('a'..'z'|'A'..'Z'|'_'|'.')
> ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'.')* ;
> terminal DOUBLE : INT '.' INT;
>
> terminal INT returns ecore::EInt: ('0'..'9')+ ;
>
> terminal myID: '^'?('a'..'z'|'A'..'Z'|'_'|'.')
> ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'%'|'['|']'|'('|')'|'.'|' '|','|'|' )* ;
>
>
>
Re: Help for grammar [message #704276 is a reply to message #704268] Thu, 28 July 2011 12:57 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Thank you so much, According your explanations ,I have modified my grammar and I still have the same problem
I am not able to leave white space between of parameters at NonEmptyline here What i did


the interesting thing is Iam able to leave WS before Writer or book names like " Writer: BookName:.."
but I m not allowed to type as " Writer : BookName :.."


[Updated on: Wed, 03 August 2011 20:28]

Report message to a moderator

Re: Help for grammar [message #704297 is a reply to message #704276] Thu, 28 July 2011 13:26 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Does
Writer hidden(WS): ...
help?


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Help for grammar [message #704304 is a reply to message #704297] Thu, 28 July 2011 13:33 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Well, It doesnt help because writer consist of just one type, as I understood
hidden (WS) allows white space between of types while they are part of an absract type
if Im not wrong Smile
Caner

[Updated on: Thu, 28 July 2011 13:33]

Report message to a moderator

Re: Help for grammar [message #704342 is a reply to message #704304] Thu, 28 July 2011 14:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

can you give us a testcase too?
and a vlid grammar?
what is the error you get?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #704414 is a reply to message #704276] Thu, 28 July 2011 15:21 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
I think you need to turn *on* hiding for the *entire grammar* i.e.

LibModel hidden(WS) :

and then turn it *off* with hidden() where WS plays a semantic role.

Regards
- henrik

On 7/28/11 2:57 PM, Caner wrote:
> Thank you so much, According your explanations ,I have modified my
> grammar and I still have the same problem I am not able to leave white
> space between of parameters at NonEmptyline here What i did
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> LibModel:
> (types+=Type)*;
> Type:
> LibComment1|NonEmpityLine|AtShell |Version| languages;
>
> LcfComment1: text=HASH_COMMENT
> ;
> AtShell:
> "@" ShellName=ID ('=' DOUBLE|INT|'-'INT)?
> ;
>
> Version:
> {Version}
> '@logstart' ('='startNumber=(DOUBLE|'X' ))?;
>
> languages:
> {languages}
> '@translators=' mytrans=(myID ) ;
>
> NonEmpityLine hidden (WS) :
> //allow users leave some space between of parameters
>
> Writer=Writer ':' WritersBooks=WritersBooks':'
> NELTranslator=NELTranslator':' ('store')? ( isbn=isbn','
> pageNumber=pageNumber)? (',' Amaunt=Amaunt)? (':')?
>
> (filter=filter ('&&') | ('||') | ('==') filtered=filtered)?
>
> ;
>
> filtered:
> filtered=Words
> ;
>
>
> filter:
> filter=Words
> ;
> NELTranslator:
> NELTranslator= Characters ;
>
> Writer:
> Writer=Words
> ;
>
> WritersBooks:
> WritersBooks= Words
> ;
>
> isbn:
> {isbn}
> isbn= ('-')?((INT)|DOUBLE)
> ;
>
> pageNumber:
>
> {pageNumber}
> pageNumber=('-')?((INT)|DOUBLE)
> ;
>
> //for new orders it might me negative value
> Amaunt:
> {Amaunt}
> Amaunt=('-')?((INT)|DOUBLE)
>
> ;
>
> Words hidden (): ID (WS ID)* ;
>
> Characters hidden () : myID (WS myID)* ;
>
> terminal WS : (' '|'\t'|'\r'|'\n')+ ;
>
> terminal HASH_COMMENT : '#' !('\n'|'\r')* ('\r'? '\n')? ;
>
> terminal ID : '^'?('a'..'z'|'A'..'Z'|'_'|'.')
> ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'.')* ;
> terminal DOUBLE : INT '.' INT;
>
> terminal INT returns ecore::EInt: ('0'..'9')+ ;
>
> myID = ID (ExtID | ID)* ;
>
> terminal ExtID = ('%'|'['|']'|'('|')'|'.'|' '|','|'|' )+ ;
>
>
>
> the interesting thing is Iam able to leave WS before Writer or book
> names like " Writer: BookName:.."
> but I m not allowed to type as " Writer : BookName :.."
>
Re: Help for grammar [message #704882 is a reply to message #704414] Fri, 29 July 2011 07:05 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hello
@Hendrik, I have tried your adviced;

I took away hidden(WS) from NonEmptiyLine ( NonEmptiyLine hidden(WS):....etc; -----> NonEmptiyLine :___etc;
and modified LibModel as you said, I dont know why it is not working

And Christian here my sample grammar, what i am trying to type in mydsl file
(space)= is white space


Thanks
caner

[Updated on: Wed, 03 August 2011 20:29]

Report message to a moderator

Re: Help for grammar [message #704885 is a reply to message #704882] Fri, 29 July 2011 07:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

why then is WS explicit in word and character? if you want to allow ws there?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #704922 is a reply to message #704885] Fri, 29 July 2011 08:11 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Christian
I thought (WS)has a propose which allows users leave some white space thats why I had WS there,
now I change the Words and Characters
library.discC.my.smo.ElementaryUserInfo.selectedBook(Space):
highlights under colon and says
 Words hidden ():  	ID   ;
 
 Characters hidden () :   myID ;


However while now im typing a colon i get errors
for example if Type ;
library.discC.my.smo.ElementaryUserInfo.selectedBook(Space): ---> high light the colon and says
"extraneous input ':' expecting EOF"
Re: Help for grammar [message #704936 is a reply to message #704922] Fri, 29 July 2011 08:43 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi again
well,I created new runtime-new configuration
now It works , Thanks God,
The new issue is when I am typing NonEmptyline if the

NELTranslator:
NELTranslator= Characters
;

if Character does not contain my special characters it give error, I want to able to type for example "...etc..: name% :" this is ok
"...etc..:name):" is ok
but "...etc..:name:" error "no viable alternative at input ' '"

Caner
Re: Help for grammar [message #704943 is a reply to message #704936] Fri, 29 July 2011 08:47 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
file.pl.tc.oEy.Perday:somename :otherName .subcriber(A|B),isDl :21,22.5,0.005

here also isDl does not any strange character so it give errors

and I modified Characters like this;

Characters hidden () : ID (myID |ID );


and I had "Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input"


caner

[Updated on: Fri, 29 July 2011 09:03]

Report message to a moderator

Re: Help for grammar [message #705023 is a reply to message #704943] Fri, 29 July 2011 10:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Unite Characters and myid Wink they do the same

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #705035 is a reply to message #705023] Fri, 29 July 2011 10:59 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Smile all right i changed it

Words hidden (): ID ;
Characters hidden () : (myID ) ;
Hi Christian Smile thanks

but now if a parameter doesnt not contain one of ExtID it gives error
such as

[Updated on: Wed, 03 August 2011 20:30]

Report message to a moderator

Re: Help for grammar [message #705072 is a reply to message #705035] Fri, 29 July 2011 11:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
As I said: unite the stuff

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #705073 is a reply to message #705035] Fri, 29 July 2011 11:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
As I said: unite the stuff

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #705079 is a reply to message #705073] Fri, 29 July 2011 12:05 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
//Words hidden (): ID ;

Characters hidden () : myID (myID|ID ) ;

You mean like this? if its not can you show me how to do that please?
BR
Caner

[Updated on: Fri, 29 July 2011 12:06]

Report message to a moderator

Re: Help for grammar [message #705085 is a reply to message #705073] Fri, 29 July 2011 12:10 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
// Words hidden (): ID ;

Characters hidden () : myID (myID | WS)* ;

i thought you mean like this, and i got errors, can you show me how to do that?
Re: Help for grammar [message #705090 is a reply to message #705085] Fri, 29 July 2011 12:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi, what about taking a pen and a paper and drawing the graphs for
myid and character and finding a solution?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #705174 is a reply to message #705090] Fri, 29 July 2011 14:35 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi

I confused little bit, i missed understood what you pointed out,

you said Characters and myID Smile I tired and missed understood I was focused on Characters and Words

Now I am not sure is that what you wanted to light on, but i deleted Characters now and replaced references of characters with myID.

So far im able to leave space but stil get error for a line which is like ;



if i dont type "(space)" for the line i get error like this;

mismatched input '] ,' expecting ':'
- mismatched input '[%' expecting ':'
- mismatched input '|' expecting ':'
- mismatched input ' , (' expecting ':'
- mismatched input '),' expecting ':'
- no viable alternative at input ','

BR
Caner

[Updated on: Wed, 03 August 2011 20:30]

Report message to a moderator

Re: Help for grammar [message #705182 is a reply to message #705174] Fri, 29 July 2011 14:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

what is your grammar now?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #705195 is a reply to message #705182] Fri, 29 July 2011 14:56 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
No Message Body

[Updated on: Wed, 03 August 2011 20:31]

Report message to a moderator

Re: Help for grammar [message #705230 is a reply to message #705195] Fri, 29 July 2011 15:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

be careful with your keywords

myID : ID (',' | ExtID | ID)* ;

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #707049 is a reply to message #705230] Mon, 01 August 2011 07:08 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Christian
thanks a lot for your support.

So far i came over with target errors. However there is an unexpected error
when I type like;

something.file.writer.somefile.anywriter: attend:accord

now in second field and third field if the types starts with "a" i get error. This is so weird.
Why do you think
BR
caner

[Updated on: Mon, 01 August 2011 07:09]

Report message to a moderator

Re: Help for grammar [message #707053 is a reply to message #707049] Mon, 01 August 2011 07:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No I have no idea what is the error message you get? Christian

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #707077 is a reply to message #707053] Mon, 01 August 2011 07:59 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
for example if I type like this without space;
something.file.writer.somefile.anywriter:(no_WS)attempt :(no_WS)arqAtt:1,1:
if the second and third type initiated with "a" I get this error,

Multiple markers at this line
- extraneous input 'tempt' expecting ':'
- mismatched character 't' expecting 'l'
- missing RULE_ID at '1'

[Updated on: Mon, 01 August 2011 08:06]

Report message to a moderator

Re: Help for grammar [message #707110 is a reply to message #707077] Mon, 01 August 2011 08:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

cannot reproduce this with you last grammar.
what is this (no_wes) in your sample model?

guess you introduced a new crappy keyword you did not add to myid

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #707117 is a reply to message #707110] Mon, 01 August 2011 08:59 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
no_ws is just to indicate that there is no white space,

i mean i typed without space
something.file.writer.somefile.anywriter:attempt :arqAtt:1,1:

caner
Re: Help for grammar [message #707122 is a reply to message #707117] Mon, 01 August 2011 09:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
AS said before: works nice like a charm for me with the grammar above and the myid change

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help for grammar [message #707321 is a reply to message #707122] Mon, 01 August 2011 13:56 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
thanks Christian you were right, it was my mistakes
sorry
BR
caner
Re: Help for grammar [message #708830 is a reply to message #707321] Wed, 03 August 2011 07:55 Go to previous messageGo to next message
Caner Friend
Messages: 98
Registered: July 2011
Member
Hi Christian


Hello
I hope you are fine, I faced with a problem while I was trying to add syntax coloring feature for my each type.

I have created a OurDefaultHighlightingConfiguration class (in com.example.mydsl.ui same packet with DslUIModel)which implements ISemanticHighlightingCalculator and overridden

following method

However, when I want to call NodeUtil, there is not such a NodeUtil class?
If you can help, I will appreciate

BR
Caner




@Override
	public void provideHighlightingFor(XtextResource resource,
			IHighlightedPositionAcceptor acceptor) {

/*
    if(resource==null)
      return;	
    
     Iterable<AbstractNode> allNode= NodeUtil.getAllContents(resource.getParseResult().getRootNode());

  
*/
}






Re: Help for grammar [message #708883 is a reply to message #708830] Wed, 03 August 2011 08:56 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No double posts please

http://www.eclipse.org/forums/index.php/mv/msg/229976/708881/#msg_708881


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to find the closest reference?
Next Topic:Reindexing of resources in archives
Goto Forum:
  


Current Time: Fri Apr 19 07:22:30 GMT 2024

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

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

Back to the top