Beginner problems with simple grammar using the eclipse plugin [message #691852] |
Sat, 02 July 2011 15:39 |
Sven Rudolph 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 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02937 seconds