Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Two similar rules, but with different cross-references
Two similar rules, but with different cross-references [message #1114364] Sun, 22 September 2013 12:27 Go to next message
Joe I is currently offline Joe I
Messages: 28
Registered: May 2013
Junior Member
Hi,

consider following grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	examples+=Example*;
	
Example:
	Object|Var|ObjectCall|VarAssignment
;	

Object:
	'object' name=ID
;

Var:
	'var' name=ID
;

ObjectCall:
	object=[Object]'.'method=ID('('(arguments+=[Var](','arguments+=[Var])*)?')')?
;

VarAssignment:
	var=[Var]('.'attribute=ID)? '=' int=INT
;


The problem is, that the ProposalProvider and the Validator always assume that a VarAssignment is an ObjectCall until '=' is entered.

Now my question is, is there an elegant way to specify these rules, keep the benefit of cross-references and get correct proposals?

Thanks!
Re: Two similar rules, but with different cross-references [message #1114457 is a reply to message #1114364] Sun, 22 September 2013 15:29 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4026
Registered: July 2009
Senior Member
Hi

You could use backtracking; hardly elegant.

You could restructure your grammar so that the conflicting syntaxes are
unified and resolved later semantically.

You could change to an LALR technology.

Regards

Ed Willink


On 22/09/2013 17:27, Joe I wrote:
> Hi,
>
> consider following grammar:
>
> grammar org.xtext.example.mydsl.MyDsl with
> org.eclipse.xtext.common.Terminals
>
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> Model:
> examples+=Example*;
>
> Example:
> Object|Var|ObjectCall|VarAssignment
> ;
>
> Object:
> 'object' name=ID
> ;
>
> Var:
> 'var' name=ID
> ;
>
> ObjectCall:
> object=[Object]'.'method=ID('('(arguments+=[Var](','arguments+=[Var])*)?')')?
>
> ;
>
> VarAssignment:
> var=[Var]('.'attribute=ID)? '=' int=INT
> ;
>
>
> The problem is, that the ProposalProvider and the Validator always
> assume that a VarAssignment is an ObjectCall until '=' is entered.
> Now my question is, is there an elegant way to specify these rules,
> keep the benefit of cross-references and get correct proposals?
> Thanks!
Previous Topic:What's necessary for using uml2 within xtext plugin?
Next Topic:Value Converters in Xtext
Goto Forum:
  


Current Time: Wed Aug 20 18:42:24 EDT 2014

Powered by FUDForum. Page generated in 0.01538 seconds