【问题标题】:Xtext/EMF how to do model-to-model transform?Xtext/EMF 如何进行模型到模型的转换?
【发布时间】:2012-11-02 12:33:49
【问题描述】:

我在 Xtext 中有一个 DSL,我想重用在我的 .xtext 文件中定义的规则、终端等,为项目中涉及的其他一些工具生成配置文件。配置文件使用类似于 BNF 的语法,因此它与实际的 Xtext 内容非常相似,并且需要最少的转换。从理论上讲,我可以轻松编写一个脚本来解析 Xtext 并吐出我的配置...

问题是,我该如何实施它以适应整个生态系统?换句话说 - 如何在 Xtext/EMF 中进行模型到模型的转换?

【问题讨论】:

    标签: dsl xtext emf


    【解决方案1】:

    如果您同时拥有两个元模型(ecore、xsd、...),最好的办法是使用 ATL (http://www.eclipse.org/atl/)。

    【讨论】:

      【解决方案2】:

      如果我理解你是正确的,你想从 xtext 模型转到它的 EMF 模型。这是实现此目的的代码示例,在必要时替换您的特定模型。

          public static BeachScript loadScript(String file) throws BeachScriptLoaderException { 
          try {
              Injector injector = new BeachStandaloneSetup().createInjectorAndDoEMFRegistration();
              XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
              resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
              Resource resource = resourceSet.createResource(URI.createURI("test.beach"));
              InputStream in = new ByteArrayInputStream(file.getBytes());
              resource.load(in, resourceSet.getLoadOptions());
              BeachScript model = (BeachScript) resource.getContents().get(0);
              return model;
      
          } catch (Exception e) {
              throw new BeachScriptLoaderException("Exception Loading Beach Script " + e.toString(),e );
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-26
        • 1970-01-01
        • 2018-10-13
        • 1970-01-01
        • 2014-07-21
        • 2014-03-13
        • 2015-05-30
        • 1970-01-01
        相关资源
        最近更新 更多