Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Beginner problems with simple grammar using the eclipse plugin
Beginner problems with simple grammar using the eclipse plugin [message #691852] Sat, 02 July 2011 15:39 Go to next message
Sven Rudolph is currently offline Sven RudolphFriend
Messages: 4
Registered: July 2011
Junior Member
Hello forum members,

this is my first post, so please excuse me if this is a FAQ.

I took my first steps with Xtext two days ago, read the 5 minutes tutorial, read the 15 minutes tutorial and started with my first Xtext project with eclipse (Indigo) using the Xtext plugin.
I chose to start with some simple text files I had to parse a while ago, which look like this:

$Name: This is the title - 1 2 123 - and it may contain special characters, e.g. öüäß
+Description:
"This description may span across
  multiple
        lines."
$end

+Value one: ( "String1" "String2" "etc." )

+Flag: 1


My xtext file looks like this:


Model:
	myname=MyName
	description=Description
	valueone=ValueOne
	myflag=MyFlag

MynName:
	"$Name: " value=IDNG;

IDNG:
	ID(WS(ID|INT|'-'))*
;

Description:
	"+Description:"
	STRING
	"$end";

ValueOne:
	"+Value one: ( "STRING*" )";

MyFlag:
	"+Flag: "INT;


This works very well, I click Run as -> MWE2 Workflow and then Run as -> Eclipse Application, the application starts and I can start adding and editing files in an eclipse editor with syntax highlighting and content assist/auto completion.

But some things don't work and I don't know how to fix it:

The field $Name: is apparently a string, but the value is not inside quotation marks. So I can't use STRING in my grammar definition and thus I can't enter special characters in the eclipse editor.

The field +Flag: does not appear in the content assist/auto completion. If I enter it manually it receives its syntax highlighting but it doesn't appear in the outline tab of eclipse.
Is this caused by the leading plus sign?

The same happens with the field +Value one: which additionally contains a space.

Unlike +Flag: and +Value one: the field +Description: appears in the eclipse outline and it can be expanded and then it contains the field $Name:
If i link the outline tab with the editor and click on Description in the outline the whole text in the editor is marked.

Apparently there is something going wrong here and I think it is caused by the leading $ and + signs and the spaces in the fields.

I hope you can help me with some tips.

Thanks in advance
Sven Rudolph


Re: Beginner problems with simple grammar using the eclipse plugin [message #691864 is a reply to message #691852] Sat, 02 July 2011 16:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
Hi,

just some hints:
If you introduce own DataType rules you may have to care about content assist too.
If you want something extra in the outline you have to customize this or introduce parser rules (assign the stuff)
You could use the -> Operator to get your title stuff running
Blanks in keywords are a bad idea. btw is it neccessary to enforce the blanks?

so maybe you want to have something like

Model:
	myname=MyName
	description=Description
	valueone=ValueOne
	myflag=MyFlag;

terminal MyName:
	"$Name:" -> "\n";


Description:
	"+Description:"
	value=STRING
	"$end";

ValueOne:
	{ValueOne} "+Value" "one:" "(" values+=STRING* ")";

MyFlag hidden():
	"+Flag:" WS value=INT;


public class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	@Override
	public void complete_MyName(EObject model, RuleCall ruleCall,
			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		acceptor.accept(createCompletionProposal("$Name: Das ist der Titel\n", context));
	}

}



public class MyDslLabelProvider extends DefaultEObjectLabelProvider {

	@Inject
	public MyDslLabelProvider(AdapterFactoryLabelProvider delegate) {
		super(delegate);
	}
	
	String text(Description d) {
		return "Description: " + d.getValue();
	}
	
	String text(ValueOne vo) {
		return "ValueOne: " + vo.getValues();
	}
	
	String text(MyFlag mf) {
		return "MyFlag: " + mf.getValue();
	}

}



~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Beginner problems with simple grammar using the eclipse plugin [message #691898 is a reply to message #691864] Sat, 02 July 2011 18:31 Go to previous messageGo to next message
Sven Rudolph is currently offline Sven RudolphFriend
Messages: 4
Registered: July 2011
Junior Member
Hello Christian,

thanks for your quick reply!

(Following quotes not in order)

Quote:

Blanks in keywords are a bad idea. btw is it neccessary to enforce the blanks?


Unfortunately I have no influence on the input files and since I have to write these files as well (later), I have to follow their structure to the letter. At least these difficulties are a good exercise.

Quote:

If you introduce own DataType rules you may have to care about content assist too.
If you want something extra in the outline you have to customize this or introduce parser rules (assign the stuff)


In a first step I just want to achieve that my keywords appear in the content assist at all. And in the outline.


In your reply you introduced two classes: MyDslProposalProvider and MyDslLabelProvider.
Where do I have to put them?

The line
acceptor.accept(createCompletionProposal("$Name: Das ist der Titel\n", context));

defines the String that is inserted by the content assist on selection?


Sven
Re: Beginner problems with simple grammar using the eclipse plugin [message #691899 is a reply to message #691898] Sat, 02 July 2011 18:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
Hi,

both classes you find already defined in yourdsls ui project.

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Beginner problems with simple grammar using the eclipse plugin [message #691913 is a reply to message #691899] Sat, 02 July 2011 19:31 Go to previous messageGo to next message
Sven Rudolph is currently offline Sven RudolphFriend
Messages: 4
Registered: July 2011
Junior Member
Ah, ok, found it.

I applied your recommendations and they work very well. I will play around with them to see how far I can get.

The lines

terminal MyName:
	"$Name:" -> "\n";


result in $Name: being displayed without syntax highlighting at all.

Where could I have looked up the information about MyDslProposalProvider and MyDslLabelProvider myself?


Sven
Re: Beginner problems with simple grammar using the eclipse plugin [message #691918 is a reply to message #691913] Sat, 02 July 2011 19:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
hi

It should be part of the docs
http://www.eclipse.org/Xtext/documentation/2_0_0/140-labelprovider.php
http://www.eclipse.org/Xtext/documentation/2_0_0/150-contentassist.php

and sebastian blogged about this
http://zarnekow.blogspot.com/2011/06/customizing-content-assist-with-xtext.html

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 02 July 2011 19:40]

Report message to a moderator

Re: Beginner problems with simple grammar using the eclipse plugin [message #691927 is a reply to message #691918] Sat, 02 July 2011 20:44 Go to previous message
Sven Rudolph is currently offline Sven RudolphFriend
Messages: 4
Registered: July 2011
Junior Member
Hi Christian,

thanks a lot for these links!
They were very helpfull.

Sven
Previous Topic:Getting an Editor instance/ Resource for a Validator
Next Topic: Get a List<String> in something.mydsl
Goto Forum:
  


Current Time: Tue Oct 27 20:32:32 GMT 2020

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

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

Back to the top