生成模型

时间:2015-08-01 12:45:49

标签: eclipse xtext

我想学习xtext,多年来我学习xpand和xtend并且工作得很好,但xtext似乎取代了另外两者。 xtext方式看起来很好。

首先我开始阅读以下教程:http://www.eclipse.org/Xtext/documentation/101_five_minutes.html,包括" 15分钟教程"和" 15分钟教程 - 扩展"和别的。所以我创建了一个简单的"模型"

grammar org.bs.test.Test with org.eclipse.xtext.common.Terminals

generate Test "http://www.bs.org/test/Test"

Test:
    main=TMain;

TMain:
    'main' name=ID 
    'done';

按以下方式生成:" GenerateTest.mwe2" >右键单击> ' Run As' →' MWE2工作流程'。

然后制作了一份项目副本。我第二次或第三次试图找出我做错了什么。

现在我改变了以下行中的模型:" main = TMain;" to" main = TMain ?;"。然后我用了#MWE2工作流程'再次,运行成功,但运行后发生: 在' src-gen / org / bs / test / Test /'下覆盖文件以及子文件夹中的文件' impl'和' util'被删除。所以他们被删除了,然后我复制了保存的项目并尝试按照" Test.xtext" >右键单击> ' Run As' →'生成Xtext工件',结果相同。

我有两个问题: 1)"生成Xtext工件"之间的区别是什么?和" MWE2工作流程"我什么时候需要它们。我无法在教程中找到它,特别是何时使用它们。 2)我错了什么,以及我需要做些什么来创建从更改的模型中生成元素

我在这方面找不到多少,我希望有人可以帮助我。我没有找到任何问题。

编辑1:

当我创建一个完整的新测试项目时,它可以工作:

项目名称:org.test

name:org.test.MyTest

扩展:mytest

使用以下xtext:

grammar org.test.MyTest with org.eclipse.xtext.common.Terminals

generate myTest "http://www.test.org/MyTest"

Test:
    main=TMain;

TMain:
    'main' name=ID 
    'done'

但是当我按照以下输入做同样的事情时:

项目名称:org.bs.craass

姓名:org.bs.craass.CraAss

扩展:克拉斯

XTEXT:

grammar org.bs.craass.CraAss with org.eclipse.xtext.common.Terminals

generate craAss "http://www.bs.org/craass/CraAss"

CraAss:
    main=CAMain;

CAMain:
    'main' name=ID 
    'done';

稍后我将尝试以下操作:安装新的eclispe emf并创建一个新的工作区。

EDIT2:

所以我测试了一个新工作区,它看起来很好,它正在工作。也许是旧工作区的东西。就像评论一样,在原始工作空间中,在我得到一个好的"版本"之后,我想把它放在git上(学习理由)。从那时起,这不再适用了。这里有一些产生的输出:

0    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering platform uri 'C:\workspaces\emf_01'
401  [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass at 'file:/C:/workspaces/emf_01/org.bs.craass/' and using 'file:/C:/workspaces/emf_01/error_01/org.bs.craass/' instead.
926  [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass at 'file:/C:/workspaces/emf_01/error_01/org.bs.craass/' and using 'file:/C:/workspaces/emf_01/org.bs.craass/' instead.
939  [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass.sdk at 'file:/C:/workspaces/emf_01/error_01/org.bs.craass.sdk/' and using 'file:/C:/workspaces/emf_01/org.bs.craass.sdk/' instead.
970  [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass.tests at 'file:/C:/workspaces/emf_01/error_01/org.bs.craass.tests/' and using 'file:/C:/workspaces/emf_01/org.bs.craass.tests/' instead.
1090 [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass.ui at 'file:/C:/workspaces/emf_01/error_01/org.bs.craass.ui/' and using 'file:/C:/workspaces/emf_01/org.bs.craass.ui/' instead.
1749 [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass at 'file:/C:/workspaces/emf_01/org.bs.craass/' and using 'file:/C:/workspaces/emf_01/save_01/org.bs.craass/' instead.
1762 [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass.sdk at 'file:/C:/workspaces/emf_01/org.bs.craass.sdk/' and using 'file:/C:/workspaces/emf_01/save_01/org.bs.craass.sdk/' instead.
1820 [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass.tests at 'file:/C:/workspaces/emf_01/org.bs.craass.tests/' and using 'file:/C:/workspaces/emf_01/save_01/org.bs.craass.tests/' instead.
2082 [main] WARN  lipse.emf.mwe.utils.StandaloneSetup  - Skipping conflicting project org.bs.craass.ui at 'file:/C:/workspaces/emf_01/org.bs.craass.ui/' and using 'file:/C:/workspaces/emf_01/save_01/org.bs.craass.ui/' instead.
2577 [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'org.eclipse.xtext.xbase.XbasePackage'
4253 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/Xtext/Xbase/XAnnotations' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
4265 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/xbase/Xtype' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
4335 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/xbase/Xbase' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
4335 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/common/JavaVMTypes' from 'platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel'
6234 [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'org.eclipse.xtext.common.types.TypesPackage'
6267 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf_01\org.bs.craass\..\org.bs.craass\src-gen
6326 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf_01\org.bs.craass\..\org.bs.craass\model\generated
6330 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf_01\org.bs.craass\..\org.bs.craass.ui\src-gen
6378 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf_01\org.bs.craass\..\org.bs.craass.tests\src-gen
9146 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.bs.org/craass/CraAss' from 'file:/C:/workspaces/emf_01/org.bs.craass/model/generated/CraAss.genmodel'
15709 [main] INFO  text.generator.junit.Junit4Fragment  - generating Junit4 Test support classes
15731 [main] INFO  text.generator.junit.Junit4Fragment  - generating Compare Framework infrastructure
15973 [main] INFO  .emf.mwe2.runtime.workflow.Workflow  - Done.

我与其他工作区中的运行进行比较,并且WARN没有到达那里。为了呐喊,我首先忽略了,因为它只是"只有"警告。运行成功的运行:

0    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering platform uri 'C:\workspaces\emf'
541  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'org.eclipse.xtext.xbase.XbasePackage'
1020 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/Xtext/Xbase/XAnnotations' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
1031 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/xbase/Xtype' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
1064 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/xbase/Xbase' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
1064 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/common/JavaVMTypes' from 'platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel'
2307 [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'org.eclipse.xtext.common.types.TypesPackage'
2355 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf\org.bs.craass\..\org.bs.craass\src-gen
2382 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf\org.bs.craass\..\org.bs.craass\model\generated
2390 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf\org.bs.craass\..\org.bs.craass.ui\src-gen
2407 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf\org.bs.craass\..\org.bs.craass.tests\src-gen
4446 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.bs.org/craass/CraAss' from 'platform:/resource/org.bs.craass/model/generated/CraAss.genmodel'
11647 [main] INFO  text.generator.junit.Junit4Fragment  - generating Junit4 Test support classes
11719 [main] INFO  text.generator.junit.Junit4Fragment  - generating Compare Framework infrastructure
11997 [main] INFO  .emf.mwe2.runtime.workflow.Workflow  - Done.

到目前为止我的故障排除工作。

编辑3:

我不知道为什么,但它现在接受我创建的旧xtext文件,并且在运行它时发生错误(但似乎没有太大影响),完成日志:

0    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering platform uri 'C:\workspaces\emf'
664  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'org.eclipse.xtext.xbase.XbasePackage'
1864 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/Xtext/Xbase/XAnnotations' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
1882 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/xbase/Xtype' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
1987 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/xbase/Xbase' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
1987 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.eclipse.org/xtext/common/JavaVMTypes' from 'platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel'
3982 [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'org.eclipse.xtext.common.types.TypesPackage'
4018 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf\org.bs.craass\..\org.bs.craass\src-gen
4061 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf\org.bs.craass\..\org.bs.craass\model\generated
4064 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf\org.bs.craass\..\org.bs.craass.ui\src-gen
4087 [main] INFO  ipse.emf.mwe.utils.DirectoryCleaner  - Cleaning C:\workspaces\emf\org.bs.craass\..\org.bs.craass.tests\src-gen
7153 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.bs.org/craass/CraAss' from 'platform:/resource/org.bs.craass/model/generated/CraAss.genmodel'
error(208): ../org.bs.craass/src-gen/org/bs/craass/parser/antlr/internal/InternalCraAss.g:1199:1: The following token definitions can never be matched because prior tokens match the same input: RULE_INT
error(208): ../org.bs.craass.ui/src-gen/org/bs/craass/ui/contentassist/antlr/internal/InternalCraAss.g:2688:1: The following token definitions can never be matched because prior tokens match the same input: RULE_INT
16642 [main] INFO  text.generator.junit.Junit4Fragment  - generating Junit4 Test support classes
16661 [main] INFO  text.generator.junit.Junit4Fragment  - generating Compare Framework infrastructure
16804 [main] INFO  .emf.mwe2.runtime.workflow.Workflow  - Done.

麻烦似乎是,我有以下几点:

grammar org.bs.craass.CraAss with org.eclipse.xtext.common.Terminals

但另一方面:

terminal INTEGER : '-'?('0'..'9')+;

terminal VAR_TERMINAL       : '_' ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;

terminal REGISTER_TERMINAL  : ('ax' | 'bx' );

terminal FUNCTION_TERMINAL  : (('a'..'z'|'_'|'0'..'9')*'.')?('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;

org.eclipse.xtext.common.Terminals

terminal INT returns ecore::EInt: ('0'..'9')+;

但我不知道如何处理它。

问题本身,在 srce-gen / 中生成everthing,但 src-gen / org.bs.craass.craAss 和子文件夹下生成的java文件除外。现在也创造了。所以我试图找出更多,因此错误可重现性更低。好吧,我会看到,当我再次将它推到git时,也许会出现错误。

到目前为止,谢谢

1 个答案:

答案 0 :(得分:0)

直接运行工作流程或调用生成语言工件也是如此。工作流程读取您的Xtext文件并生成为您的语言提供的所有基础结构Xtext。因此,如果您更改语法或工作流程本身,则必须调用它。如果您的语言配置错误或语法损坏,则生成可能会失败。此外,工作流程也可能涉及可能必须采用的项目名称(不知道如何进行复制和粘贴 - 您应该使用Xtext项目向导来创建项目以确保安全)