|
Re: Xbase and Xtext cross references [message #1699220 is a reply to message #1699214] |
Mon, 22 June 2015 16:44 |
|
On 22/06/2015 17:55, Julien Delange wrote:
> I am trying to define values and assertions in a xtext grammar and
> trying to figure out the best way to resolve variables. I have the
> following grammar (adapted from the domainmodel example and available here:
> Entity:
> 'entity' name=ValidID ('extends'
> superType=JvmParameterizedTypeReference)? '{'
> ('features'
> features+=Feature*)?
> ('vars' '{'
> vars+=XVariableDeclaration* '}')?
> ('check' '{'
> assertExpression+=XExpression* '}')?
> '}';
>
>
> It allows me to declare something like this:
>
> package bla
> {
> entity Foobar {
> vars
> {
> val int foo = 1
> var int bar = 2
> }
> check {foo == bar }
> }
> }
>
> Problem is I would like to be able to resolve foo and bar inside the
> check() method (and ultimately reference variables from other entities).
> As the grammar uses both xtext and xbase, I have several questions:
> 1. What is the best way to do it? Is there any available class/methods I
> just have to inject to resolve? Or should I extend/write a new component
> (tune the scoping of the DSL)? In other words, what is the best way to
> reference the variable inside the XExpression?
> 2. When using this grammar, I got an error in the eclipse instance that
> runs the DSL and an exception in my IDE (see below). Is this is a bug
> and should I fill a bugreport about that?
>
Hi
if you use Xbase you need to implement a model inferrer that maps your
DSL elements into Java elements; in your case you might want to map
variables in "vars" into fields of the class you infer for Foobar; since
you want these variables to be referred to from other entities, the
mapped fields should be public, for example.
Hope this helps
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02564 seconds