Home » Modeling » TMF (Xtext) » two file extenstions with slightly different grammar(Do I need two Xtext projects for two file extenstions with slightly different grammar)
| | | |
Re: two file extenstions with slightly different grammar [message #693484 is a reply to message #693369] |
Wed, 06 July 2011 14:48 |
alex.ren2006 Messages: 46 Registered: June 2011 |
Member |
|
|
I tried to devide grammar into 3 parts. Here's what I did. I create 9 projects for 3 grammars.
In project "org.xtext.example.mydsl", I have the grammar file "MyDsl.xtext" with the following content
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
decl_base:
'int' fun_name=funname '(' 'int' arg=argname ')';
funname:
name=ID;
argname:
name=ID;
In project "org.xtext.example.mydslA", I have the grammar file "MyDslA.xtext" with the following content
grammar org.xtext.example.mydsl.MyDslA with org.xtext.example.mydsl.MyDsl
import "http://www.xtext.org/example/mydsl/MyDsl"
generate myDslA "http://www.xtext.org/example/mydsl/MyDslA"
program:
body+=statement+;
statement:
m_decl=decl
| m_impl=imple;
decl:
'extern' m_base=decl_base;
imple:
'implement' fun_name=[funname] '(' arg_name=[argname] ')'
'=' '{' 'return' arg_name1=[argname] '+' '3' '}';
In project "org.xtext.example.mydslB", I have the grammar file "MyDslB.xtext" with the following content
grammar org.xtext.example.mydsl.MyDslB with org.xtext.example.mydsl.MyDsl
generate myDslB "http://www.xtext.org/example/mydsl/MyDslB"
program:
m_dec+=decl_base+
;
To stop the xtext editor from generating error, I also add the "org.xtext.example.mydsl/src" to the class folder of the projects "org.xtext.example.mydslA" and "org.xtext.example.mydslB".
There is no problem of running "GenerateMyDsl.mwe2" in project "org.xtext.example.mydsl". But running "GenerateMyDslA.mwe2" never stops at all. The console shows the following message
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri 'G:\WORKSPACE\Xtext\workspace_old'
1157 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner - Cleaning G:\WORKSPACE\Xtext\workspace_old\org.xtext.example.mydslA\..\org.xtext.example.mydslA\src-gen
1188 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner - Cleaning G:\WORKSPACE\Xtext\workspace_old\org.xtext.example.mydslA\..\org.xtext.example.mydslA.ui\src-gen
1313 [main] INFO ipse.xtext.generator.LanguageConfig - generating infrastructure for org.xtext.example.mydsl.MyDslA with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, SerializerFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, GeneratorFragment, FormatterFragment, LabelProviderFragment, OutlineTreeProviderFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment, Junit4Fragment, TypesGeneratorFragment, XbaseGeneratorFragment, CodetemplatesGeneratorFragment, RefactorElementNameFragment, CompareFragment
It seems something is blocked since the CPU usage is very low.
I checked the manual of xtext and add the following to the mwe2 file
fragment = ecore.EcoreGeneratorFragment {
referencedGenModels = "
platform:/resource/org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.genmodel
"
Then I can run "GenerateMyDslA.mwe2" successfully with the following message
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri 'G:\WORKSPACE\Xtext\workspace_old'
1078 [main] WARN erator.ecore.EcoreGeneratorFragment - The property 'referencedGenModels' is deprecated. Please use 'StandaloneSetup.registerGenModelFile' instead.
1109 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner - Cleaning G:\WORKSPACE\Xtext\workspace_old\org.xtext.example.mydslA\..\org.xtext.example.mydslA\src-gen
1109 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner - Cleaning G:\WORKSPACE\Xtext\workspace_old\org.xtext.example.mydslA\..\org.xtext.example.mydslA.ui\src-gen
1234 [main] INFO ipse.xtext.generator.LanguageConfig - generating infrastructure for org.xtext.example.mydsl.MyDslA with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, SerializerFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, GeneratorFragment, FormatterFragment, LabelProviderFragment, OutlineTreeProviderFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment, Junit4Fragment, TypesGeneratorFragment, XbaseGeneratorFragment, CodetemplatesGeneratorFragment, RefactorElementNameFragment, CompareFragment
2468 [main] INFO clipse.emf.mwe.utils.GenModelHelper - Registered GenModel 'http://www.xtext.org/example/mydsl/MyDsl' from 'platform:/resource/org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.genmodel'
2500 [main] INFO clipse.emf.mwe.utils.GenModelHelper - Registered GenModel 'http://www.xtext.org/example/mydsl/MyDslA' from 'file:/G:/WORKSPACE/Xtext/workspace_old/org.xtext.example.mydslA/src-gen/org/xtext/example/mydsl/MyDslA.genmodel'
[b]2500 [main] [color=crimson]WARN clipse.emf.mwe.utils.GenModelHelper - There is already a GenModel registered for NamespaceURI 'http://www.xtext.org/example/mydsl/MyDsl'. It will be overwritten from 'platform:/resource/org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.genmodel' [/color][/b]to 'file:/G:/WORKSPACE/Xtext/workspace_old/org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.genmodel'
2500 [main] INFO clipse.emf.mwe.utils.GenModelHelper - Registered GenModel 'http://www.xtext.org/example/mydsl/MyDsl' from 'file:/G:/WORKSPACE/Xtext/workspace_old/org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.genmodel'
4562 [main] INFO or.validation.JavaValidatorFragment - generating Java-based EValidator API
5046 [main] INFO text.generator.junit.Junit4Fragment - generating Junit4 Test support classes
5078 [main] INFO text.generator.junit.Junit4Fragment - generating Compare Framework infrastructure
5218 [main] INFO .emf.mwe2.runtime.workflow.Workflow - Done.
This time the generated Java code in src-gen folders has errors (e.g.
org.xtext.example.mydsl.MyDslStandaloneSetup cannot be resolved to a type ).
I am not familiar with the ecore, genmodel stuff. What's the proper procedure for importing another grammar in a xtext project? Thanks a lot.
|
|
| | | |
Re: two file extenstions with slightly different grammar [message #693826 is a reply to message #693730] |
Thu, 07 July 2011 09:22 |
alex.ren2006 Messages: 46 Registered: June 2011 |
Member |
|
|
Thank you so much, Christian. It works like breeze.
Honestly speaking, at first I don't understand what you are talking about. I've never done any serious projects in eclipse, let alone plug-in development. But after playing with eclipse for a while I think I get the point from your words.
I write down the whole process using the following example. I have two grammars: commonLang and branchLangA. The latter one depends on the previous one. Also I have to import the ecore model (I am still not very clear about this concept) into grammar branchLangA since I want to use cross-reference.
BTW: I am currently using xtext 2 which seems much better than xtext 1.
1. Create Xtext project
Project name: commonlang
Language name: org.CommonLang
Extensions: comlang
2. The content of CommonLang.xtext goes as follows.
=================
grammar org.CommonLang with org.eclipse.xtext.common.Terminals
generate commonLang "http://www.CommonLang.org"
decl_base:
'int' fun_name=funname '(' 'int' arg=argname ')';
funname:
name=ID;
argname:
name=ID; =================
3. Run "GenerateCommonLang.mwe2"
4. Create Xtext project
Project name: branchlanga
Language name: org.BranchLangA
Extensions: brlanga
5. The content of BranchLangA.xtext goes as follows.
=================
grammar org.BranchLangA with org.CommonLang
generate branchLangA "http://www.BranchLangA.org"
import "http://www.CommonLang.org"
program:
body+=statement+;
statement:
m_decl=decl
| m_impl=imple;
decl:
'extern' m_base=decl_base;
imple:
'implement' fun_name=[funname] '(' arg_name=[argname] ')'
'=' '{' 'return' arg_name1=[argname] '+' '3' '}'; =================
6. Open META-INF->MANIFEST.MF of project branchlanga, click "Dependencies" in "Plug-in Content", and add commlang to the "Required Plug-ins".
7. Modify "GenerateBranchLangA.mwe2", change
==================
// generates Java API for the generated EPackages
fragment = ecore.EcoreGeneratorFragment {
// referencedGenModels = "
// platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel,
// platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel
// "
}
==================
to
==================
// generates Java API for the generated EPackages
fragment = ecore.EcoreGeneratorFragment {
referencedGenModels = "
platform:/resource/commonlang/src-gen/org/CommonLang.genmodel
"
} =================
8. Run "GenerateBranchLangA.mwe2"
9. At this moment the eclipse editor shows errors in the project "branchlanga", e.g. "BranchLangAScopeProvider.java". Open the file and move the mouse over the error. The popup says as follows
================
Access restriction: The type CommonLangScopeProvider is not accessible due to restriction on required project commonlang
2 quick fixes available
Export the 'org.scoping' package from the 'commonlang' plug-in
Search repositories for 'org.scoping' ================
Just click on "Export the 'org.scoping' package from the 'commonlang' plug-in"
Clicking on popups seems not that official. Later I find out that this can be done by openning
META-INF->MANIFEST.MF of project commonlang, click "Runtime" in "Plug-in Content", and add org.scoping to the "Exported Packages".
10. Open META-INF->MANIFEST.MF of project branchlanga.ui, click "Dependencies" in "Plug-in Content", and add commlang.ui to the "Required Plug-ins".
11. Open META-INF->MANIFEST.MF of project commonlang.ui, click "Runtime" in "Plug-in Content", and add org.ui.contentassist to the "Exported Packages".
12. Right click on project branchlanga, choose "Run as" -> "Eclipse Application".
Then I can create file yy.brlanga, and type in code like follows
================
extern int ff (int x)
implement ff(x) =
{
return x + 3
} ================
It seems that MANIFEST.MF is much more powerful than classpath or project dependency. (I tried setting classpath and project dependency in "Java Build Path" last night. But it didn't work.) I would like to know more about the machenism beneath. Any suggestion for good book on Java plug-in?
By using xtext, I am befuddled by terms like xtend, xbase, ecore, EMF, mwe and etc. So far I manage to use xtext based on the instinct of programmer and my limited knowledge of Java and of course help from you guys here (thank you once again). Any suggestion for good books on these topics.
Thanks for your help.
|
|
|
Goto Forum:
Current Time: Mon Sep 23 05:05:38 GMT 2024
Powered by FUDForum. Page generated in 0.04974 seconds
|