Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Mixing grammars
Mixing grammars [message #894306] Sun, 08 July 2012 04:06 Go to next message
daniel Ramos is currently offline daniel RamosFriend
Messages: 21
Registered: July 2012
Junior Member
Hi!

I'm trying to mix two simple gramamrs.

Grammar 1 need an element from grammar 2.


I changed the MWE2 to reference the genmodel from grammar 2 but it does not work yet. Can someone help me with this.
Re: Mixing grammars [message #894323 is a reply to message #894306] Sun, 08 July 2012 07:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
Hi,

can you elaborate a bit more (what you are doning exactly, what is the
error msg you get)

~Christian

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@xxxxxxxx


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Mixing grammars [message #894369 is a reply to message #894323] Sun, 08 July 2012 19:30 Go to previous messageGo to next message
daniel Ramos is currently offline daniel RamosFriend
Messages: 21
Registered: July 2012
Junior Member
Here are my 2 grammars' Rules

first one


Dependencies:
	first=OwnRule
	second=ExternalRule
;

OwnRule:
	'Own Rule' rule=ID';'
;


ExternalRule:
	rule=Secondgrammar
;




The second grammar's Rule

Secondgrammar:
'External rule' rule=ID ';'
;


These Rules are just two .xtext files in the same classpath. The first grammar must know the second grammar. So I defined the first grammar
grammar org.xtext.exampl.dependencies.MyDsl1 with org.xtext.exampl.dependecies.MyDsl2
The error appears in the link to the second grammar.

I changed the MWE2 this way:
module org.xtext.exampl.dependencies.GenerateMyDsl

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var grammarURI = "classpath:/org/xtext/exampl/dependencies/MyDsl1.xtext"
var grammarURI2 = "classpath:/org/xtext/exampl/dependencies/MyDsl2.xtext"
var file.extensions.fir = "d1"
var file.extensions.sec="d2"
var projectName = "dependencies"
var runtimeProject = "../${projectName}"

Workflow {
    bean = StandaloneSetup {
        scanClassPath = true
        platformUri = "${runtimeProject}/.."
    }

    component = DirectoryCleaner {
        directory = "${runtimeProject}/src-gen"
    }

    component = DirectoryCleaner {
        directory = "${runtimeProject}.ui/src-gen"
    }

    component = Generator {
        pathRtProject = runtimeProject
        pathUiProject = "${runtimeProject}.ui"
        pathTestProject = "${runtimeProject}.tests"
        projectNameRt = projectName
        projectNameUi = "${projectName}.ui"
        language = {
            uri = grammarURI2
            fileExtensions = file.extensions.sec

            // Java API to access grammar elements (required by several other fragments)
            fragment = grammarAccess.GrammarAccessFragment {}

            // 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
            // "
            }

            // Serializer 2.0
            fragment = serializer.SerializerFragment {}
            
            // the serialization component (1.0)
            // fragment = parseTreeConstructor.ParseTreeConstructorFragment {}

            // a custom ResourceFactory for use with EMF
            fragment = resourceFactory.ResourceFactoryFragment {
                fileExtensions = file.extensions.sec
            }

            // The antlr parser generator fragment.
            fragment = parser.antlr.XtextAntlrGeneratorFragment {
            //  options = {
            //      backtrack = true
            //  }
            }

            // java-based API for validation
            fragment = validation.JavaValidatorFragment {
                composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
                composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
            }

            // scoping and exporting API
            // fragment = scoping.ImportURIScopingFragment {}
            // fragment = exporting.SimpleNamesFragment {}

            // scoping and exporting API
            fragment = scoping.ImportNamespacesScopingFragment {}
            fragment = exporting.QualifiedNamesFragment {}
            fragment = builder.BuilderIntegrationFragment {}

            // generator API
            fragment = generator.GeneratorFragment {
                generateMwe = true
                generateJavaMain = true
            }

            // formatter API
            fragment = formatting.FormatterFragment {}

            // labeling API
            fragment = labeling.LabelProviderFragment {}

            // outline API
            fragment = outline.OutlineTreeProviderFragment {}
            fragment = outline.QuickOutlineFragment {}

            // quickfix API
            fragment = quickfix.QuickfixProviderFragment {}

            // content assist API
            fragment = contentAssist.JavaBasedContentAssistFragment {}

            // generates a more lightweight Antlr parser and lexer tailored for content assist
            fragment = parser.antlr.XtextAntlrUiGeneratorFragment {}

            // generates junit test support classes into Generator#pathTestProject
            fragment = junit.Junit4Fragment {}

            // project wizard (optional)
            // fragment = projectWizard.SimpleProjectWizardFragment {
            //      generatorProjectName = "${projectName}"
            //      modelFileExtension = file.extensions
            // }

            // provides the necessary bindings for java types integration
            fragment = types.TypesGeneratorFragment {}

            // generates the required bindings only if the grammar inherits from Xbase
            fragment = xbase.XbaseGeneratorFragment {}

            // provides a preference page for template proposals
            fragment = templates.CodetemplatesGeneratorFragment {}

            // rename refactoring
            fragment = refactoring.RefactorElementNameFragment {}

            // provides a compare view
            fragment = compare.CompareFragment {
                 fileExtensions = file.extensions.sec
            }

        }
        
         language = {
            uri = grammarURI
            fileExtensions = file.extensions.fir

            // Java API to access grammar elements (required by several other fragments)
            fragment = grammarAccess.GrammarAccessFragment {}

            // generates Java API for the generated EPackages
            fragment = ecore.EcoreGeneratorFragment {
             referencedGenModels = "platform:/resource/dependencies/src-gen/org/xtext/exampl/dependencies/MyDsl2.genmodel"
            }

            // Serializer 2.0
            fragment = serializer.SerializerFragment {}
            
            // the serialization component (1.0)
            // fragment = parseTreeConstructor.ParseTreeConstructorFragment {}

            // a custom ResourceFactory for use with EMF
            fragment = resourceFactory.ResourceFactoryFragment {
                fileExtensions = file.extensions.fir
            }

            // The antlr parser generator fragment.
            fragment = parser.antlr.XtextAntlrGeneratorFragment {
            //  options = {
            //      backtrack = true
            //  }
            }

            // java-based API for validation
            fragment = validation.JavaValidatorFragment {
                composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
                composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
            }

            // scoping and exporting API
            // fragment = scoping.ImportURIScopingFragment {}
            // fragment = exporting.SimpleNamesFragment {}

            // scoping and exporting API
            fragment = scoping.ImportNamespacesScopingFragment {}
            fragment = exporting.QualifiedNamesFragment {}
            fragment = builder.BuilderIntegrationFragment {}

            // generator API
            fragment = generator.GeneratorFragment {
                generateMwe = true
                generateJavaMain = true
            }

            // formatter API
            fragment = formatting.FormatterFragment {}

            // labeling API
            fragment = labeling.LabelProviderFragment {}

            // outline API
            fragment = outline.OutlineTreeProviderFragment {}
            fragment = outline.QuickOutlineFragment {}

            // quickfix API
            fragment = quickfix.QuickfixProviderFragment {}

            // content assist API
            fragment = contentAssist.JavaBasedContentAssistFragment {}

            // generates a more lightweight Antlr parser and lexer tailored for content assist
            fragment = parser.antlr.XtextAntlrUiGeneratorFragment {}

            // generates junit test support classes into Generator#pathTestProject
            fragment = junit.Junit4Fragment {}

            // project wizard (optional)
            // fragment = projectWizard.SimpleProjectWizardFragment {
            //      generatorProjectName = "${projectName}"
            //      modelFileExtension = file.extensions
            // }

            // provides the necessary bindings for java types integration
            fragment = types.TypesGeneratorFragment {}

            // generates the required bindings only if the grammar inherits from Xbase
            fragment = xbase.XbaseGeneratorFragment {}

            // provides a preference page for template proposals
            fragment = templates.CodetemplatesGeneratorFragment {}

            // rename refactoring
            fragment = refactoring.RefactorElementNameFragment {}

            // provides a compare view
            fragment = compare.CompareFragment {
                 fileExtensions = file.extensions.fir
            }

        }
    }
}
Re: Mixing grammars [message #894371 is a reply to message #894369] Sun, 08 July 2012 20:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
Hi,

hi, you still did not say what the error is you get.

ps:
is there a special reason you want to have both grammars in one project.
i thing the referencedGenModels = "platform:/resource/dependencies/src-gen/org/xtext/exampl/dependencies/MyDsl2.genmodel"
is not neccessary in this case



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Mixing grammars [message #894372 is a reply to message #894371] Sun, 08 July 2012 20:59 Go to previous messageGo to next message
daniel Ramos is currently offline daniel RamosFriend
Messages: 21
Registered: July 2012
Junior Member
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri 'C:\trabajo 3'
1513 [main] ERROR ipse.xtext.generator.LanguageConfig - [XtextLinkingDiagnostic: null:1 Couldn't resolve reference to Grammar 'org.xtext.exampl.dependecies.MyDsl2'., XtextLinkingDiagnostic: null:10 ID cannot be resolved to a rule, XtextLinkingDiagnostic: null:15 Secondgrammar cannot be resolved to a rule]
1513 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems instantiating module org.xtext.exampl.dependencies.GenerateMyDsl: java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: Problems instantiating module org.xtext.exampl.dependencies.GenerateMyDsl: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:90)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:64)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:55)
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: org.eclipse.emf.common.util.WrappedException: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:56)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:137)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:112)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:64)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:136)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:64)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:136)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:64)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:64)
at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.create(Mwe2ExecutionEngine.java:60)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:88)
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.emf.mwe2.language.factory.SettingProviderImpl$1$1.setValue(SettingProviderImpl.java:54)
... 37 more
Caused by: java.lang.IllegalStateException: Problem parsing 'classpath:/org/xtext/exampl/dependencies/MyDsl1.xtext':[XtextLinkingDiagnostic: null:1 Couldn't resolve reference to Grammar 'org.xtext.exampl.dependecies.MyDsl2'., XtextLinkingDiagnostic: null:10 ID cannot be resolved to a rule, XtextLinkingDiagnostic: null:15 Secondgrammar cannot be resolved to a rule]
at org.eclipse.xtext.generator.LanguageConfig.setUri(LanguageConfig.java:131)
... 42 more
Re: Mixing grammars [message #894373 is a reply to message #894372] Sun, 08 July 2012 21:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
Hi,

can you share your complete project?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Mixing grammars [message #894374 is a reply to message #894373] Sun, 08 July 2012 22:03 Go to previous messageGo to next message
daniel Ramos is currently offline daniel RamosFriend
Messages: 21
Registered: July 2012
Junior Member
I'm trying to make a simple example to learn how to mix two or more gramamrs. I need it for a project.

Here is my project attached to the message

Re: Mixing grammars [message #1728805 is a reply to message #894374] Thu, 07 April 2016 13:52 Go to previous message
David Hofmann is currently offline David HofmannFriend
Messages: 19
Registered: March 2013
Junior Member
I got the same error message in a Maven environment.
The solution was to include the *.xtext file in the bundle resources:

<build>
  <resources>
    <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.xtext</include>
      </includes>
    </resource>
  </resources>
</build>
Previous Topic:error ATL
Next Topic:[SOLVED] forbit brackets in xbase expression
Goto Forum:
  


Current Time: Fri Sep 24 19:29:15 GMT 2021

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

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

Back to the top