Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Forcing two values to be equal or force a certain reference?
Forcing two values to be equal or force a certain reference? [message #655403] Sun, 20 February 2011 11:26 Go to next message
Eclipse UserFriend
Hello,

I started converting an existing VHDL grammar to XText. I am completely new to the subject and don't know much about grammars and parsers and lexers apart from what I learned at university.

Here's what I have so far:

entity_name :
	name=ID;

entity_declaration returns entity: 
"entity" entityId=entity_name "is" ED=entity_declarative_part ( "begin" ESP=entity_statement_part )? "end" ( "entity" )? ( ends=entity_reference )? ";"  ;

entity_reference:
	reference=[entity_name];


For example:
entity myName is ...
begin
...
end entity myName;

The requisition is that the value after "end entity" is the name of the entity. How would I do that? Is that some part of linking? Or scoping? Can this be done directly in the grammar?

I got it that the "end entity [reference]" worked, but it only checks for a reference to *any* entity, not to the one just declared. So I either want to make this refer to one particular entity or just force the two values to be equal.

Thanks a lot in advance. I try to find as much information as I can in the documentation and this forum, but haven't found out how to solve this problem.

Simon

[Updated on: Sun, 20 February 2011 11:36] by Moderator

Re: Forcing two values to be equal? [message #655405 is a reply to message #655403] Sun, 20 February 2011 11:37 Go to previous messageGo to next message
Eclipse UserFriend
You can simply check that the values are equal during validation.
It is better to be permissive in the grammar and handle errors with
validation - this way you can produce more meaningful messages, and more
easily offer quick fixes.

- henrik

On 2/20/11 5:26 PM, Simon Stratmann wrote:
> Hello,
>
> I started converting an existing VHDL grammar to XText. I am completely
> new to the subject and don't know much about grammars and parsers and
> lexers apart from what I learned at university.
>
> So, in VHDL an entiy declaration looks something like this:
>
> "entity" entityId=entity_name "is" ED=entity_declarative_part ( "begin"
> ESP=entity_statement_part )? "end" ( "entity" )? ( ends=entity_reference
> )? ";";
>
> For example:
> entity myName is ...
> begin
> ...
> end entity myName;
>
> The requisition is that the value after "end entity" is the name of the
> entity. How would I do that? Is that some part of linking? Or scoping?
> Can this be done directly in the grammar?
>
> Thanks a lot in advance. I try to find as much information as I can in
> the documentation and this forum, but haven't found out how to solve
> this problem.
>
> Simon
Re: Forcing two values to be equal? [message #655406 is a reply to message #655405] Sun, 20 February 2011 11:51 Go to previous messageGo to next message
Eclipse UserFriend
I haven't even gotten that far. Thanks, will try it out.
Re: Forcing two values to be equal or force a certain reference? [message #655420 is a reply to message #655403] Sun, 20 February 2011 13:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

in this use case I'd actually use scoping, i.e. restrict the visible elements of the "ends" feature to the single possible entity_name element.

The scoping method would be simpler (basically a single easy to read line) if the definition would be

ends=[entity_name]

Also you cannot specify that in the grammar. There you only restrict the type of the referred element, but you can give no particulars on which elements are considered visible.

Alex
Re: Forcing two values to be equal or force a certain reference? [message #655421 is a reply to message #655420] Sun, 20 February 2011 13:29 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your help!

How would scoping go with error handling and quick fix? I managed to do a validation check comparing the entity name and the "ends" value and implementing a simple quick fix.
To be honest, that's the first time I even looked at validation, I am only learning step by step and beginning to understand what I would do in the grammar and what in the several generated parts of xtext.

Anyway, I haven't tried out content assist and such. Would that and error handling be similar when I'd use scoping?

Simon
Re: Forcing two values to be equal or force a certain reference? [message #655423 is a reply to message #655421] Sun, 20 February 2011 14:03 Go to previous message
Eclipse UserFriend
Hi,

the error message would be a bit mysterious "could not resolve reference to ..." (in a sense an automatic validation, whether a referrable element exists)
Quick fix is not that much of a problem here (in my opinion), as content assist would immediately yield the only valid element (content assist for references is fed by scoping). So this is indeed a thing to consider.

In a sense, in this use case scoping gives you validation and content assist for free (with the slight drawback of the generic error message).

Alex
Previous Topic:Xtext as RCP but with integration in external JAVA SWT application.
Next Topic:Feature Normalization
Goto Forum:
  


Current Time: Mon Nov 03 21:29:04 EST 2025

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

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

Back to the top