dimanche 26 octobre 2014

XText typed literals


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 Declaration has a type of int, then only such a literal can be on the right hand side of an assignment, what matches an integer regex? Same for string?

  • 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

bali182

3,789






XText typed literals

Aucun commentaire:

Enregistrer un commentaire