|
|
Re: Mixing up XEpressions and my custom expressions [message #1058390 is a reply to message #1058180] |
Mon, 13 May 2013 20:27 |
Leandro Marques Messages: 11 Registered: July 2009 |
Junior Member |
|
|
Hi Michael B, thanks for your response, but unfortunately it does not work for me. My intention is to mix up XExpresionos lines of code with my custom java based lines of code, for example
XExpression
XIfExpression
--> My custom line of code
--> My custom line of code
XExpression
XForLoopExpression
--> My custom LOC
Your solution considers separated blocks of XExpression and my custom expressions when, in fact, I need to mix them up. Even I use two IFs, instead of If-else block in my Model Inferrer the following LOC
is actually erasing the previous content of the body. In this way, I also verified if the call to:
body [
it.append(param)
]
can be done by using a XExpression as a param, however, you can only add a CharSequence or a JVMType.
Then I have my hands tied up. How can I construct my function (or method) body by adding line by line expressions, considering these expressions being as XExpressions or My Custom Expressions?
Thanks
|
|
|
|
|
|
Re: Mixing up XEpressions and my custom expressions [message #1059256 is a reply to message #1059031] |
Thu, 16 May 2013 16:47 |
Hallvard Traetteberg Messages: 673 Registered: July 2009 Location: Trondheim, Norway |
Senior Member |
|
|
Hi,
Using Xbase is easiest if you can infer a Java model that gets the
scopes right for you. In practice this means inferring a combination of
fields in a class and parameters of methods that provide the appropriate
context for Xbase expressions. If several Xbase expressions need to be
part of the same body, you need to infer a method for each of them, and
generate calls to these methods in the appropriate places in the body.
This is conceptually similar to the closures mentioned below.
E.g. suppose you have a DSL that lets you write variable declarations
and if-like statements:
model a
var int a, int b, int c
when a == b do print(b) otherwise print(c)
This may require inferring something like
class A {
int a;
int b;
int c;
// infer a method with the XExpression a == b as its body
// no need for explicit code generation
boolean bodyExpr1() {
return a == b;
}
// infer a method with the XExpression print(b) as its body
// no need for explicit code generation
void bodyExpr2() {
print(b);
}
// infer a method with the XExpression print(c) as its body
// no need for explicit code generation
void bodyExpr3() {
print(c);
}
// infer a method that combines calls to the above methods
// in place of the XExpressions
void body() {
if (bodyExpr1()) bodyExpr2();
else bodyExpr3();
}
}
Of course, you may also have more local scopes that needs to be added as
parameters of the methods and arguments to corresponding calls.
If the inferred model gets the scoping right, you don't have to make
your own scope provider (unless you need it for other constructs).
Hallvard
On 16.05.13 03.20, Ian McDevitt wrote:
> Also remembered for the above case, in processing each of my own
> expressions I had to generate a closure function for each which I
> collected in a list so I could combine them into the body by using a
> loop of func(i).apply(it) in the body=[]. And then I had to call the
> XbaseCompiler directly to process the XExpressions. All in all it
> diverted me a lot away from the main features I wanted to work on.
>
> That may give you some ideas if you need to progress that way, but in
> the end it was the loss of the scope provider that changed my mind.
|
|
|
Re: Mixing up XEpressions and my custom expressions [message #1059484 is a reply to message #1059030] |
Sun, 19 May 2013 15:21 |
|
On 05/16/2013 12:08 PM, Ian McDevitt wrote:
> I tried something like this once although not mixing the expressions
> quite as closely. I defined my own expression rules, which you can do
> easily enough by looking at how Xbase does it, but I found the biggest
> problem was scoping. I had to subclass the XbaseScopeProvider so that my
> DSL elements could tell what was in scope (and vice versa). This did not
> always work as planned and in fact I believe the Xbase SP is deprecated
> in 2.4 (there is a post from Lorenzo Bettini somewhere on that) and I
> have since decided not to include Xbase in my DSL and enhanced the DSL a
> bit instead.
From what I understand, currently, XbaseScopeProvider is used by the
content assist, while the one that is used by Xbase is
XbaseBatchScopeProvider... what I'm doing is factor out all custom
scoping mechanisms in a common class, e.g., ScopeProviderHelper, and
then have both a custom XbaseScopeProvider and a custom
XbaseBatchScopeProvider which delegate to my ScopeProviderHelper...
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
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.04387 seconds