Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xtext] Split grammar (multiple grammars) in 1 project?
[xtext] Split grammar (multiple grammars) in 1 project? [message #629107] Mon, 27 September 2010 08:34 Go to next message
Eclipse UserFriend
Originally posted by: albert.ystad.ons-huis.net

Hello All,

In a researchproject (called CC/Castle) I have two related grammars. Or actually two extensions:
*.Moat and *.Caste. The (allowed) syntax in a .Moat-file is a subset of that in a Caste-file. So,
I wanted to define two grammars, one including the other, to generare two eclipse-editors (and
compilers) But I run into problems. So some advice is welcome.

I assumed I should create 1 project-set (ccCastle, ccCastle.ui, ccCastle.generator; as made by the
xtext(1.0.1) project-wizzard. And define both grammars there.

I started by the Moat grammar. And was able to build a editor for it. Great. But adding the Castle
grammer didn't worked, at least not as I expected. Writing a Castle.xtext file is not a problem
but getting it working in the project...

As the grammars are related, I defined the Castle one to extent the Moat one, which starts typical,
as shown below:
CASTLE.XTEXT
grammar nl.softwareBeterMaken.ccCastle.Castle with nl.softwareBeterMaken.ccCastle.Moat
MOAT.XTEXT
grammar nl.softwareBeterMaken.ccCastle.Moat with org.eclipse.xtext.common.Terminals
Q: Correct? Or should I use import?

Next, I assumed I needed a second .mwe2 file, so I created one by copying the existing one and
replaced the strings 'moat' with 'castle'.
Q: Is that correct?

I was able to run that mwe2 file (mouse, run as ...), but it doesn't really work. I get errors,
stange messages and such. So I assume I make some fundamentel mistake.
Q: Which one?
Q: Is it even possible/supported/earlierDone to build 2 editors out of 1 project?


I tried several options; all of which I could think of. But I never got it really working.

Now I'm wondering: is it possible to define two extensions/grammars in 1 project? Or did I change
so many items, Eclispe is out of sync (I see some java file appearing in src/ too. Is that correct,
should they be in src-gen?) Are I mad?


Some messages are collected below:
* PROBLEM: AbstractCastleProposalProvider can not resolved to a type (CastleProposalProvider.java)
* PROBLEM: The import nl.softwareBeterMaken.ccCastle.ui.contentassist.AbstractCast leProposalProvider cannot be resolved (CastleProposalProvider.java)
* PROLEM: Package 'nl.softwareBeterMaken.ccCastle.castle.impl' does not exist in this plug-in (MANIFEST.MF)
* BUILD ERROR: org.eclipse.emf.mwe.core.WorkflowInterruptedException: The generated EPackage references an external EPackage, but 'referencedGenModels' hasn't been registered.
See below for full log.


Any advice is welcome. Please ask for details when needed.

Note: I'm not really a java-expert, nor a Eclipse-guru. But I assume I don't have to, to design a language.
I do no about languages, compilers parsers and stuff. I did use yacc/bison, C and Emacs in the past. I assume that would to to..


--Groetjes
ALbert Mietus
Send prive mail to: ALbert at ons-huis dot net
Don't send spam mail!
http://albert.mietus.nl http://SoftwareBeterMaken.nl


Console log
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri '/Users/albert/work/CC.Castle'
956 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner - Cleaning /Users/albert/work/CC.Castle/nl.softwareBeterMaken.ccCastle/ ../nl.softwareBeterMaken.ccCastle/src-gen
966 [main] INFO ipse.emf.mwe.utils.DirectoryCleaner - Cleaning /Users/albert/work/CC.Castle/nl.softwareBeterMaken.ccCastle/ ../nl.softwareBeterMaken.ccCastle.ui/src-gen
1157 [main] INFO ipse.xtext.generator.LanguageConfig - generating infrastructure for nl.softwareBeterMaken.ccCastle.Castle with fragments : ImplicitRuntimeFragment, ImplicitUiFragment, GrammarAccessFragment, EcoreGeneratorFragment, ParseTreeConstructorFragment, ResourceFactoryFragment, XtextAntlrGeneratorFragment, JavaValidatorFragment, ImportNamespacesScopingFragment, QualifiedNamesFragment, BuilderIntegrationFragment, FormatterFragment, LabelProviderFragment, TransformerFragment, OutlineNodeAdapterFactoryFragment, QuickOutlineFragment, QuickfixProviderFragment, JavaBasedContentAssistFragment, XtextAntlrUiGeneratorFragment
org.eclipse.emf.mwe.core.WorkflowInterruptedException: The generated EPackage references an external EPackage, but 'referencedGenModels' hasn't been registered.
at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.che ckGenModelExists(EcoreGeneratorFragment.java:222)
at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.pro xifyExternalReferences(EcoreGeneratorFragment.java:214)
at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.gen erate(EcoreGeneratorFragment.java:158)
at org.eclipse.xtext.generator.CompositeGeneratorFragment.gener ate(CompositeGeneratorFragment.java:81)
at org.eclipse.xtext.generator.LanguageConfig.generate(Language Config.java:69)
at org.eclipse.xtext.generator.Generator.generate(Generator.jav a:296)
at org.eclipse.xtext.generator.Generator.invokeInternal(Generat or.java:106)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invok e(AbstractWorkflowComponent.java:126)
at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.ja va:34)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invok e(AbstractWorkflowComponent.java:201)
at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkf lowComponent.invoke(AbstractCompositeWorkflowComponent.java: 31)
at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow. java:19)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:80)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:52)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Lau ncher.java:74)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2La uncher.java:35)
10715 [main] INFO or.validation.JavaValidatorFragment - executing generate for org.eclipse.xtext.generator.validation.JavaValidatorFragment
14802 [main] INFO .emf.mwe2.runtime.workflow.Workflow - Done.
Re: [xtext] Split grammar (multiple grammars) in 1 project? [message #629232 is a reply to message #629107] Mon, 27 September 2010 14:16 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 9/27/10 10:34 AM, schrieb ALbert Mietus:
> Hello All,
>
> In a researchproject (called CC/Castle) I have two related grammars. Or actually two extensions:
> *.Moat and *.Caste. The (allowed) syntax in a .Moat-file is a subset of that in a Caste-file. So,
> I wanted to define two grammars, one including the other, to generare two eclipse-editors (and
> compilers) But I run into problems. So some advice is welcome.
>
> I assumed I should create 1 project-set (ccCastle, ccCastle.ui, ccCastle.generator; as made by the
> xtext(1.0.1) project-wizzard. And define both grammars there.
>

You could have both grammars in one set of projects or one set per grammar.

> I started by the Moat grammar. And was able to build a editor for it. Great. But adding the Castle
> grammer didn't worked, at least not as I expected. Writing a Castle.xtext file is not a problem
> but getting it working in the project...
>
> As the grammars are related, I defined the Castle one to extent the Moat one, which starts typical,
> as shown below:
> CASTLE.XTEXT
> grammar nl.softwareBeterMaken.ccCastle.Castle with nl.softwareBeterMaken.ccCastle.Moat
> MOAT.XTEXT
> grammar nl.softwareBeterMaken.ccCastle.Moat with org.eclipse.xtext.common.Terminals
> Q: Correct? Or should I use import?

Correct.

>
> Next, I assumed I needed a second .mwe2 file, so I created one by copying the existing one and
> replaced the strings 'moat' with 'castle'.
> Q: Is that correct?

No, one is sufficient.
See the mwe2 file in org.eclipse.xtext.xbase for an example.

>
> I was able to run that mwe2 file (mouse, run as ...), but it doesn't really work. I get errors,
> stange messages and such.

The message "The generated EPackage references an external EPackage, but
'referencedGenModels' hasn't been registered." means you should provide
a URI to the generated *.genmodel.

In the mwe2 configuration of the extending language provide the
following configuration:

fragment = ecore.EcoreGeneratorFragment {

referencedGenModels=" platform:/resource/my.project/src-gen/my/pack/Extending.genm odel "
}

So I assume I make some fundamentel mistake.
> Q: Which one?
> Q: Is it even possible/supported/earlierDone to build 2 editors out of 1 project?

Yes, it is.

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: [xtext] Split grammar (multiple grammars) in 1 project? [message #629242 is a reply to message #629107] Mon, 27 September 2010 15:09 Go to previous messageGo to next message
Thomas Delissen is currently offline Thomas DelissenFriend
Messages: 11
Registered: September 2010
Location: Eindhoven
Junior Member
From one newbie to the other (no offence Wink ), I would advice you to take the 'easy' way out and create two projects, in which you use grammar mixins from Moat to Castle (don't forget to register the dependency in the Manifest file). It is not very trivial to understand how the MWE2 workflow works, and it is hard to find documentation for it. If you really want to modify the workflow, the best way is to do this is to use examples and modify them until they work.

You mention you are no Java expert, me neither. If you are going to modify workflows, you will need some Java knowledge tough. In my (limited) experience, using Xtext is like walking down a small dirtroad in a big forest. If you follow the well-trodden path you will get where you want, but if you wander off, you will need to be able to read the signs of nature (Java) to escape the jungle of error messages.


Kind regards,

Thomas
Re: [xtext] Split grammar (multiple grammars) in 1 project? [message #696483 is a reply to message #629232] Thu, 14 July 2011 05:12 Go to previous message
irfan  is currently offline irfan Friend
Messages: 16
Registered: July 2011
Junior Member
hi sven,
as per your rply in order to deal with the Epackage missing error,we need to use the following code:
In the mwe2 configuration of the extending language provide the
following configuration:
fragment = ecore.EcoreGeneratorFragment {

referencedGenModels=" platform:/resource/my.project/src-gen/my/pack/Extending.genmodel "
}

but as we have both the files CASTLE.XTEXT and MOAT.XTEXT in the same project how can we have to genmodel in it so that the other can refer it... Confused
In the example you have mention that castle is using moat grammar,so we need to refer to moat genmodel but as both are in same project we can't create the artifacts for it.
i have also tried to keep them in two separate projects and the adding the dependencies of moat in to castle project and the referencing moat genmodel to castle,but cause the following errors:
38703 [main] ERROR enerator.CompositeGeneratorFragment  - java.lang.reflect.InvocationTargetException
org.eclipse.emf.common.util.WrappedException: java.lang.reflect.InvocationTargetException
	at org.eclipse.xtext.generator.parser.antlr.AntlrToolFacade.runWithParams(AntlrToolFacade.java:127)
	at org.eclipse.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment.generate(XtextAntlrGeneratorFragment.java:44)
	at org.eclipse.xtext.generator.CompositeGeneratorFragment.generate(CompositeGeneratorFragment.java:81)
	at org.eclipse.xtext.generator.LanguageConfig.generate(LanguageConfig.java:69)
	at org.eclipse.xtext.generator.Generator.generate(Generator.java:296)
	at org.eclipse.xtext.generator.Generator.invokeInternal(Generator.java:106)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:31)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:80)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.xtext.generator.parser.antlr.AntlrToolFacade.runWithParams(AntlrToolFacade.java:125)
	... 14 more
Caused by: java.lang.OutOfMemoryError: Java heap space
	at org.antlr.misc.IntervalSet.toArray(IntervalSet.java:598)
	at org.antlr.analysis.DFA.createTransitionTableEntryForState(DFA.java:626)
	at org.antlr.analysis.DFA.createStateTables(DFA.java:502)
	at org.antlr.codegen.CodeGenerator.genLookaheadDecision(CodeGenerator.java:618)
	at org.antlr.codegen.CodeGenTreeWalker.block(CodeGenTreeWalker.java:974)
	at org.antlr.codegen.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:753)
	at org.antlr.codegen.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:544)
	at org.antlr.codegen.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:486)
	at org.antlr.codegen.CodeGenTreeWalker.grammar(CodeGenTreeWalker.java:297)
	at org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:406)
	at org.antlr.Tool.processGrammar(Tool.java:347)
	at org.antlr.Tool.process(Tool.java:311)
	at de.itemis.xtext.antlr.toolrunner.AntlrToolRunner.runWithParams(AntlrToolRunner.java:40)
	... 19 more
38781 [main] INFO  or.validation.JavaValidatorFragment  - executing generate for org.eclipse.xtext.generator.validation.JavaValidatorFragment

It would be a great if you could help here..

thanks in advance
Irfan
Previous Topic:Validator error method and EStructuralFeature
Next Topic:Unordered Groups and cardinality
Goto Forum:
  


Current Time: Fri Apr 26 11:29:14 GMT 2024

Powered by FUDForum. Page generated in 0.03462 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top