Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xpand/Xtend editor errors
Xpand/Xtend editor errors [message #717164] Fri, 19 August 2011 09:40 Go to next message
Eclipse UserFriend
Hi,
I know this has been discussed already (e.g. http://www.eclipse.org/forums/index.php/m/662163/?srch=xpand+editor+property#msg_662163), but sorry, I cannot really figure out the solution.

Here is a simple grammar
grammar dsl.Crapdsl with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

generate crapdsl "dsl.Crapdsl"

Point:
    name = ID
    coordinate = Coordinate
;
Coordinate:
    x = FLOAT
    y = ID
    z = ID
;
terminal FLOAT returns ecore::EFloat : ('+'?|'-')('0'..'9')*'.'('0'..'9')+;


Why does the Xpand/Xtend editor underline with red 'coordinate.x', complaining that it cannot find such property? y and z are fine, I assume because their type is not EFLoat.
The code generation works perfectly, so it is really an issue with the editor.
In the preferences, I have already selected 'JavaBeans metamodel' and 'EMF metamodel', with no success.
I am using Eclipse Helios, Xtext 1.0.2

Thank you
B
Re: Xpand/Xtend editor errors [message #717165 is a reply to message #717164] Fri, 19 August 2011 09:48 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

first note that the Xtend/Xpand editors *are* buggy and that usually it is good practice to use datatype rules instead of terminal rules for these constructs (preventing lexing/parsing problems in larger grammars). Have you tried other number types as well?

Alex
Re: Xpand/Xtend editor errors [message #717169 is a reply to message #717164] Fri, 19 August 2011 10:02 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i cannot reproduce this using Xtext 1.0.2 / Xpand 1.0.1 using emf metamodel nor using Xtext 2.0.0 / Xpand 1.1.0
using Java Beans Metamodel i can reproduce it in both versions.
can you please file a bug against the editor?
does it work with both metamodels configured in the workflow? if not file a bug for this too

~Christian
Re: Xpand/Xtend editor errors [message #717172 is a reply to message #717165] Fri, 19 August 2011 10:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

yes I tried
terminal MY_ID returns ecore::EInt: ('1'..'9')('0'..'9')*;

and properties of this type seem recognized by the editor (e.g. code completion suggests them).

What would be a possible data type rule to substitute my FLOAT?
Something like
Float returns ecore::EFloat :
      value = ('+'?|'-')('0'..'9')*'.'('0'..'9')+;


would result in an additional indirectness.. i.e. I would need to write coordinate.x.value, instead of coordinate.x ...
Is this a good solution?
Thank you

B

Re: Xpand/Xtend editor errors [message #717184 is a reply to message #717169] Fri, 19 August 2011 10:28 Go to previous messageGo to next message
Eclipse UserFriend
sorry Christian,
I don't see any metamodel configuration in my workflow file. What do you mean?
I thought metamodels are set in the project properties -> Xtend/Xpand. (for the generator project)
There, I set JavaBeans. If I choose EMF, the errors are even more.
Re: Xpand/Xtend editor errors [message #717204 is a reply to message #717184] Fri, 19 August 2011 11:21 Go to previous messageGo to next message
Eclipse UserFriend
you can set the metamodel in the generator component. javabeans is the default. ~Christian
Re: Xpand/Xtend editor errors [message #717252 is a reply to message #717172] Fri, 19 August 2011 13:53 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

no, this is not a datatype rule (see the documentation as well!).
Float returns ecore::EFloat :
      ('+'?|'-')('0'..'9')*'.'('0'..'9')+;


The big difference between a terminal and a data type rule (apart from the "missing" keyword terminal in the grammar) is as follows. Terminal rules (along with keywords) are essential for the lexing phase where the document is chopped up into tokens. This happens regardless of the context (i.e. not taking into account what the grammar would allow at the given position). Datatype rules are evaluated in the parsing phase, so there the grammar context matters.

The main problem with self defined terminal rules is that they often overlap, i.e. the same content could be chopped into tokens using different ways (but only one will be used, frequently not the expected one). So datatype rules allow you reduce the number of terminal rules but at the same time you get "one" simple value (a number, a string...) although it may be composed of multiple tokens.

Alex
Re: Xpand/Xtend editor errors [message #718079 is a reply to message #717252] Tue, 23 August 2011 03:50 Go to previous message
Eclipse UserFriend
I see. Thanks for the explanation.

Unfortunately the problem persists, even if I avoid completely custom terminal rules:
Coordinate:
    x = Float
    y = ID
    z = ID
;
Float returns ecore::EFloat :
    ('+'?|'-')(Digit)*'.'(Digit)+;
Digit:
    ('0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'); 


(I also had to provide a custom ValueConverter to transform a string like -13.093 to a Float)
I'm sure this is not the best neither most elegant way to do what I want; anyway, even though there are no terminal rules, the xpand editor still complains about the property coordinate.x. Looks like the problem is with ecore types.

B

[Updated on: Tue, 23 August 2011 04:52] by Moderator

Previous Topic:When the Xtextmydsl editor plugin is installed
Next Topic:Folding swallowed newlines
Goto Forum:
  


Current Time: Sun Jul 27 15:36:26 EDT 2025

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

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

Back to the top