Producing multiple objects from one rule [message #1754675] |
Tue, 21 February 2017 08:10  |
Eclipse User |
|
|
|
Hi,
I'm trying to parse things like :
and get a model containing Var objects with type and name, one for each of i, j, d, e.
I'd like to naively write a rule like this:
Model:
vars+=VarDecl*
;
VarDecl:
type=TypeSpec {Var} name=ID (',' {Var} name=ID)*
;
TypeSpec:
{Int} 'int'
| {Double} 'double'
;
But this is incorrect as one can't put two {Var} clauses in the same rule ?
Validation complains about "unassigned action not allowed when the current was already created".
I thought about rewriting my grammar in this way:
Model:
vars+=VarDecl*
;
VarDecl:
type=TypeSpec vars+=Var (',' vars+=Var)*
;
Var:
name=ID
;
TypeSpec:
{Int} 'int'
| {Double} 'double'
;
But now, how to get a type property on Var object ?
How to remove the unwanted VarDecl grouping classifier ?
Is there a solution with XText ?
Cheers,
--Eric
|
|
|
|
|
|
|
|
Re: Producing multiple objects from one rule [message #1754872 is a reply to message #1754866] |
Thu, 23 February 2017 07:05  |
Eclipse User |
|
|
|
it is still supported but might not be forever.
// from here xtext inferrs a Class Var with an attribute name of type String
Var:name=ID;
//uncalled from here Xtext will detect that Var (the returns thing) also has a containment reference name "type" of type TypeSpec
VarWithType returns Var:
type=TypeSpec name=ID;
|
|
|
Powered by
FUDForum. Page generated in 0.04900 seconds