Producing multiple objects from one rule [message #1754675] |
Tue, 21 February 2017 13:10 |
Eric Lépicier Messages: 25 Registered: October 2013 |
Junior Member |
|
|
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
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06016 seconds