在我当前的项目中,我试图链接用xtext编写的DSL规范和用StringTemplate编写的代码生成器.
例如,我的DSL规范的语法如下.我通过xText提供的很好的编辑器工具输入这些信息.
structs:
TempStruct
tempValue : double;
unitOfMeasurement : String;
abilities :
sensors:
TemperatureSensor
generate tempMeasurement : TempStruct;
attribute responseFormat : String;
Run Code Online (Sandbox Code Playgroud)
上述DSL规范的语法如下:
VocSpec:
'structs' ':'
(structs += Struct)+
'abilities' ':'
('sensors' ':' (sensors += Sensor)+ )+
;
Sensor:
name = ID
((attributes += Attributes ) |
(sources += Sources))*
;
Sources:
'generate' name=ID ':' type = Type ';'
;
Attributes:
'attribute' name=ID ':' type = Type ';'
;
Struct:
name = ID
(fields += Field)+
;
Field:
name=ID ':' …Run Code Online (Sandbox Code Playgroud)