Vote count:
0
Another XText question. While experimenting with XText, i tried to create a language which is capable of a basic variable declaration, and value assignment. My first try was something like this:
Grammar:
elements+=Element*;
Element:
Declaration | ValueAssignment;
Declaration:
type=Type isArray='[]'? name=ID;
enum Type:
int | string;
ValueAssignment:
declaration=[Declaration] '=' ???;
So my questions:
- If we don't take the array part into consideration for now, how could i enforce, that if a
Declarationhas a type ofint, then only such a literal can be on the right hand side of an assignment, what matches an integer regex? Same forstring? - If we TAKE the array part into consideration, how could that be done? Sure i could write a rule, like
ArrayLiteral: {ArrayLiteral}'{' elements+=???* '}';but what would be the type of the elements rule? How could i ensure the type there?
I went through the XText guides, but anywhere, where types came into play, it used XBase elements which were very confusing. Any help, or pointers on where to start would be greatly appreciated!
asked 1 min ago
XText typed literals
Aucun commentaire:
Enregistrer un commentaire