Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Beginner grammar problem
Beginner grammar problem [message #692143] Sun, 03 July 2011 13:48 Go to next message
Eclipse UserFriend
Hello EveryBody!
I have some problems with definition of mydsl grammar

I have several Lists<String> which are Writers, Books PageNumber, Isb respectively in my ProposalProvider class

in myDsl I will create a text line which is called NonEmptyline which consists of the lists of Writers, Books PageNumber, Isbn respectively

for example: in my DSL, each line has to be just like this

Stefen_King:Full_Dark_No_Stars:789:1234567

each element will be called from a different List by content assist. Here my code is below, when i run as .MWE2 i get errors



Librarymodel:
	(elements+=NonEmptyline)*;
	
NonEmptyline:
	Writers':' Books ':'PageNumber ':' IsbnNumber
;

Writers:
	 name=WriterName ':';
	WriterName hidden(): ID (WS ID)* ;

Books:
	name=BookName ':'
	BookName hidden (): ID (WS ID)* ;

PageNumber:
	name=Page ':'
	Page hidden (): ID (WS ID)* ;
	
	;
IsbnNumber:
	name=Isbn ':'
	Isbn hidden (): ID (WS ID)* ;





I look forward to hear your solutions

Sincerely

[Updated on: Sun, 03 July 2011 13:49] by Moderator

Re: Beginner grammar problem [message #692147 is a reply to message #692143] Sun, 03 July 2011 13:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

there a lots of complicated stuff in your grammar. its way to complicated. what about something like

in parser rules you should always assign stuff.
each rule must be closed with a semicolon.

Librarymodel:
	(elements+=NonEmptyline)*;
	
NonEmptyline:
	writer=Words ':' book=Words ':'pageNumber=INT ':' isbn=INT
;

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


~Christian

[Updated on: Sun, 03 July 2011 14:00] by Moderator

Re: Beginner grammar problem [message #692155 is a reply to message #692147] Sun, 03 July 2011 14:35 Go to previous messageGo to next message
Eclipse UserFriend
Thanks you so much again, this works,

I have one more question if when Stefen_King has been chosen as a writer from content assist, how can i display just Stefen_King 's books intstead of all books?

Best
Re: Beginner grammar problem [message #692157 is a reply to message #692155] Sun, 03 July 2011 14:39 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

what about a filtered content assist for the books? just query the Context (downcasting EObject model to NonEmptyline andf ask it for the writer)

but what i do not understand is: if you have all the data why to do the modeling stuff at all???

~Christian

~Christian
Re: Beginner grammar problem [message #692158 is a reply to message #692157] Sun, 03 July 2011 14:43 Go to previous messageGo to next message
Eclipse UserFriend
well i have an existing language for my data, we have used this language on text file for a long time
Now we decided to have a simple editor which is capable for coloring and error checking and content assist
Re: Beginner grammar problem [message #692159 is a reply to message #692158] Sun, 03 July 2011 14:46 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

just to make this clear: you have files/models for the master data as well? why don't you use a dsl for these to and use cross refs for the Librarymodel?

~Christian
Re: Beginner grammar problem [message #692160 is a reply to message #692159] Sun, 03 July 2011 15:01 Go to previous messageGo to next message
Eclipse UserFriend
Hi again
Thanks again and again for advance suggestion, this is explicitly what i need for my librarymodel, However I need to study on it Smile
Re: Beginner grammar problem [message #692391 is a reply to message #692160] Mon, 04 July 2011 07:06 Go to previous messageGo to next message
Eclipse UserFriend
hello Christian

can you give me any sample for this reference linking based on my Librarymodel ,
Re: Beginner grammar problem [message #692396 is a reply to message #692391] Mon, 04 July 2011 07:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

since i do not know you masterdata dsl: no

~Christian
Re: Beginner grammar problem [message #692405 is a reply to message #692396] Mon, 04 July 2011 07:47 Go to previous messageGo to next message
Eclipse UserFriend
Librarymodel:
	(elements+=CrossReference)*;

CrossReference:
	referencedObjct=[NonEmpityLine];

NonEmptyline:
	writer=Words ':' book=Words ':'pageNumber=INT ':' isbn=INT
;

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




is this right as grammar?




~ProposalProvider extends Abstract~..~ProposalProvider implements ILinkingService {
......

ArrayList<String> writers = new ArrayList<String>();
writers.add("writer1"); 
writers.add("writer2"); 
writers.add("writer3"); 

....
@Override
	public void complete_writers(EObject model, RuleCall ruleCall,
			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		for(String writer: writers){
			acceptor.accept(createCompletionProposal(writer,context));
		}
		// TODO Auto-generated method stub
		super.complete_LogItem(model, ruleCall, context, acceptor);
	}

.....


// Actually, I dont know how to context this with writer 
@Override
	public List<EObject> getLinkedObjects(EObject context,
			EReference reference, INode node) throws IllegalNodeException {
		// TODO Auto-generated method stub
		return null;
	}

}//class end

[Updated on: Mon, 04 July 2011 08:32] by Moderator

Re: Beginner grammar problem [message #692427 is a reply to message #692405] Mon, 04 July 2011 08:20 Go to previous messageGo to next message
Eclipse UserFriend
No,

if you want to crossref something you need the something somewhere. where is that in your case? where are the "Books" master data defined?

~Christian
Re: Beginner grammar problem [message #692433 is a reply to message #692427] Mon, 04 July 2011 08:33 Go to previous messageGo to next message
Eclipse UserFriend
All i have above , in the class

some more array such as

ArrayList<String>writer1sbooks;
writer1sbooks== new ArrayList<String>();
writer1sbooks.add.....
.....

[Updated on: Mon, 04 July 2011 08:36] by Moderator

Re: Beginner grammar problem [message #692438 is a reply to message #692433] Mon, 04 July 2011 08:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

then it is a missunderstanding that you can use references

~CVhr
Re: Beginner grammar problem [message #692440 is a reply to message #692438] Mon, 04 July 2011 08:45 Go to previous messageGo to next message
Eclipse UserFriend
Thank anyway for you help Wink

I just wonder when I typed
writer1:"HERE!!"
how can I display in the content assit window the writer1s book as proposal, do u know any otherway?
Re: Beginner grammar problem [message #692442 is a reply to message #692440] Mon, 04 July 2011 08:47 Go to previous messageGo to next message
Eclipse UserFriend
As i said before, customize content assist. by downcasting EObject model and check the writers name. ~Christian
Re: Beginner grammar problem [message #692760 is a reply to message #692442] Tue, 05 July 2011 03:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian, Please can you explain what you mean with by downcasting EObject model based on my Proposal provider?

Re: Beginner grammar problem [message #692789 is a reply to message #692760] Tue, 05 July 2011 04:33 Go to previous message
Eclipse UserFriend
see you other post
Previous Topic:pdf of xtext 2 documentation
Next Topic:Inject a different StaticMethodsFeatureForTypeProvider
Goto Forum:
  


Current Time: Tue Nov 04 03:19:07 EST 2025

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

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

Back to the top