is it possible to assign constant values to attributes in xtext rule? -
i have metamodel in have class range
min
max
integer values , want define xtext dsl, in can define range 1..10
, standard defaults ?
, !
stand 0..1
or 1..1
. looked around documentation, couldn't find way define in xtext grammar. far, have rule general case
range: min=int '..' max=int;
however, didn't find way define like
range: '?' min=0 max=1;
range: '!' min=1 max=1;
how achieve similar behavior dsl?
please note not interested in generating metamodel grammar, dsl models should adhere existing metamodel.
i dont know easy solution might able customize xtexts object creation e.g. like
model: ranges+=abstractrange*; abstractrange returns range: explicitrange | zorange | oorange; explicitrange returns range: min=int ".." max=int; zorange returns range: {range} max=zeroone; zeroone returns ecore::eint: "?"; oorange returns range: {range} max=oneone; oneone returns ecore::eint: "!";
and following customizations
class mydslecoreelementfactory extends defaultecoreelementfactory { @inject extension mydslgrammaraccess override set(eobject object, string feature, object value, string rulename, inode node) throws valueconverterexception { if (object instanceof range) { if (rulename == grammar.name+"."+zeroonerule.name) { object.max = 1 object.min = 0 return; } else if (rulename == grammar.name+"."+oneonerule.name) { object.max = 1 object.min = 1 return; } } super.set(object, feature, value, rulename, node) } }
bound this
class mydslruntimemodule extends abstractmydslruntimemodule { override bindiastfactory() { mydslecoreelementfactory } }
unfortunately org.eclipse.xtext.parser.iastfactory.create(eclassifier)
not have second param specifies node or rule in , resist introduce subclasses ranges (in metamodel inherited one) make bit easy (override create only)
Comments
Post a Comment