说,我有这个伪模型
User fn string 120 chars mandatory ln string 120 chars mandatory address not-mandatory Address street mandatory city mandatory
典型的使用场景:
user opens the IDE creates a new file when content assist invoked,should give options 'user','address' etc If I choose user,furthur ctrl-space should give 'fn','ln','address' as options.
我知道这可以通过xtext或jetbrains mps等来完成.但是,我想了解哪种技术可以满足以下要求.
>模型在运行时被提供给系统(新的,更新的,删除的等).
所以,我不能有静态的语法集.如何构造它以便在运行时解析模型/属性辅助或至少生成语法(可能是其中的一部分)
>当我使用一组’语法’时,如果我将目标服务器指向不同的版本(可能有不同的模型集),我希望编辑器验证我现有的文件并标记错误.
>我以xml,文本或服务器查找方式获取数据文件.
>对我来说,将模型转换为其他格式或在java / groovy中解释它们非常重要.
对于前者,
我可能有以下数据文件
user { fn : Tom ln : Jill hobby : movies }
但是,当我针对不知道’业余爱好’属性的服务器验证此文件时,我希望编辑器在该属性上标记错误.
我计划为这个dsl / toolkit添加更多功能.
任何提示哪种技术更合适?
谢谢
解决方法
I know this can be done by xtext or jetbrains mps etc. But,I want to understand which technology lends for the following requirements.
我认为在您拥有(或可以创建)XML域模型的XML模式的条件下,Xtext可以满足您的要求.
- the models are fed to the system at run time (new,updates,deletes etc). so,I cannot have static set of grammars. How can I structure it so that the model/property assist is resolved at run time or at least the grammar is generated (may be a part of it)
如果我理解正确,您实际上并不需要针对每个XML数据模型的特定语法规则,而只需要交叉引用数据模型.
EMF支持从XSD文件生成EMF Java类,如果使用自定义索引器(Xtext接口IDefaultResourceDescriptionStrategy)将Xxt索引添加到Xtext索引,Xtext可以引用符合XSD架构的XML文件.
因此,您可以为DSL创建具有语法等的普通Xtext项目,并使用引用XML域模型的交叉引用.
- when I am working with one set of ‘grammars’,if I point my target server to a different version (which may have different set of models),I want the editor validate my existing files and flag errors.
- I get the data files in xml,text or via server lookups.
EMF使用URI来识别资源,所以如果你生成像我描述的Ecore模型,应该可以使用http://或file://(或者其他任何,它是可扩展的)URI或者你的东西来导入XML域模型内部解析为URI.
- It is very important for me to transform the models into some other format or interpret them in java/groovy.
在这里,你可以选择制作一个解释器,一个Xbase推理器或一个生成器(每个都可以使用Xtend很好地实现),具体取决于你的要求.
(免责声明:我是itemis的员工,这是Xtext的主要贡献者之一)