parsing - How to implement command-line variables in Xtext -
i want domain specific language (dsl) accept command-line arguments variables in bash scripts. example: user might issue command runmydsl mydslfile.dsl -args 10 15
or runmydsl mydslfile.dsl -nvargs arg1=10 arg2=15
. capture these values variables $1, $2 first command or $arg1, $arg2 second command. these variables can treated other read-only variables in dsl:
val somevariable = $1
since new xtext/parser field, looking best practices people follow dealing situation. simplicity, let's assume, working on simplified dsl addition (based on expression language described in http://blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html):
expression : variable '+' variable; variable: ('val' id '=' int) | commandlinevariable; commandlinevariable: ??;
my first idea following:
1.) parse dsl file , access ast, store refence in locally definded variable of corresponding eclass.
2.) use 'mydslfactory' class create new 'variable' instance, set value, given command line , put somewhere ast.
to should define attribute names in 'variable' parser rule:
variable: 'val' name=id '=' value=int;
'variable' creation (more or less):
variable newvar = mydslfactory.einstance.createvariable(); newvar.setname(args[2].split("=")[0]); newvar.setvalue(new integer(args[2].split("=")[1]));
then put ast , modified ast either create temporary dsl file processed before or process ast directly.
Comments
Post a Comment