Skip to main content



      Home
Home » Modeling » TMF (Xtext) » generate with multiple independent grammars(generation fails for multiple grammars)
generate with multiple independent grammars [message #1814171] Thu, 05 September 2019 04:44 Go to next message
Eclipse UserFriend
Hello,

I try to use two independent grammars in Xtext. I updated the mwe2-file and copied the grammar, validation and generator into existing folders. I Changed names so there are no conflicts and it builds without errors.
When i want to edit in Eclipse, I just have autocompletion for the first grammar (hello world) and it doesn't generate. Second grammar doesn't work at all.
I'm not sure how to setup multiple independent grammars and how to spread the files. Both generators/validators in one folder or make extra folders for the new language?.
Is there somewhere a project to checkout?
I found https://www.eclipse.org/forums/index.php/t/1079008/ but doesn't solve my problem.
Probably it doesn't find my generator file.

Thanks
Markus
Re: generate with multiple independent grammars [message #1814172 is a reply to message #1814171] Thu, 05 September 2019 05:02 Go to previous messageGo to next message
Eclipse UserFriend
I don't know about your concrete languages but the use case is quite common.

First of all, code generation support is built in and should work out of the box. Just create a new sample language, or take one of the examples, and they should work. Then compare to yours.

Next, having multiple languages that depend on each other is also normal. There is nothing special about that. Whether you have your languages in separate plugins or prefer just one set of bundles for all languages is a matter of taste. For the latter, simply add another "language" to the XtextGenerator component in the mwe2 script.

You can find for every scenario samples in Xtext's code base. Look for example at the standard examples, or at the org.eclipse.xtext.testlanguages bundle's source.
Re: generate with multiple independent grammars [message #1814174 is a reply to message #1814172] Thu, 05 September 2019 05:34 Go to previous messageGo to next message
Eclipse UserFriend
The Eclipse GEF DOT component also covers such use cases.

https://github.com/eclipse/gef/blob/master/org.eclipse.gef.dot/src/org/eclipse/gef/dot/internal/language/GenerateDot.mwe2

Maybe it is a good starting point for you.
Re: generate with multiple independent grammars [message #1814236 is a reply to message #1814174] Fri, 06 September 2019 05:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
thanks for the nice hints.

I tried org.eclipse.xtext.testlanguages but have the same problem. I added the mwe2-files and compiled. Same Problem.

I returned to the example in https://www.eclipse.org/forums/index.php/t/1079008/, it's more simple. As you said, just add a new "language".

At least it generates and autocompletes with the first language (hello world). The second, which i turned to be a hello world too doesn't work.
Actually my language worked as standalone but I tried with hello world.
It compiles, plugin.xml_gen looks fine, the model is created but Eclipse does nothing with the file-extension 'red'.

module org.xtext.example.mydsl.TestGen

import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*

var rootPath = ".."

Workflow {

component = XtextGenerator {
	configuration = {
		project = StandardProjectConfig {
		baseName = "org.xtext.example.mydsl"
		rootPath = rootPath
		runtimeTest = {
			enabled = true
		}
		eclipsePlugin = {
			enabled = true
		}
		eclipsePluginTest = {
			enabled = true
		}
		createEclipseMetaData = true
	}
	
	code = {
		encoding = "windows-1252"
		fileHeader = "/*\n * generated by Xtext \${version}\n */"
	}
}

language = StandardLanguage {
	name = "org.xtext.example.mydsl.MyDsl"
	fileExtensions = "mydsl"

	serializer = {
	generateStub = false
	}

	validator = {
		// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
	}
	parserGenerator = {
	options = {
	ignoreCase = true
	backtrack=true
	}
	}
}

language = StandardLanguage {
	name = "org.xtext.example.mydsl.Test"
	fileExtensions = "red"

	serializer = {
		generateStub = false
	}
	validator = {
	// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
	parserGenerator = {
		options = {
		ignoreCase = true
		backtrack=true
		}
	}
}
}
}
Re: generate with multiple independent grammars [message #1814240 is a reply to message #1814236] Fri, 06 September 2019 06:03 Go to previous messageGo to next message
Eclipse UserFriend
did you merge(copy) plugin.xml_gen -> plugin.xml ???
Re: generate with multiple independent grammars [message #1814241 is a reply to message #1814240] Fri, 06 September 2019 06:08 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
no!!!
Re: generate with multiple independent grammars [message #1814242 is a reply to message #1814241] Fri, 06 September 2019 06:16 Go to previous messageGo to next message
Eclipse UserFriend
I doesn't help.
I copied it.
Eclipse doesn't do anything with the second file extension 'red'
Re: generate with multiple independent grammars [message #1814245 is a reply to message #1814242] Fri, 06 September 2019 06:29 Go to previous messageGo to next message
Eclipse UserFriend
can you please provide a complete hello world project
Re: generate with multiple independent grammars [message #1814246 is a reply to message #1814245] Fri, 06 September 2019 06:44 Go to previous messageGo to next message
Eclipse UserFriend
File: /org.xtext.example.mydsl/src/org/xtext/example/mydsl/MyDsl.xtext
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';



File: /org.xtext.example.mydsl/src/org/xtext/example/mydsl/Test.xtext
grammar org.xtext.example.mydsl.Test with org.eclipse.xtext.common.Terminals

generate test "http://www.xtext.org/example/mydsl/Test"

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';


File: /org.xtext.example.mydsl/plugin.xml
<?xml version="1.0" encoding="windows-1252"?>
<?eclipse version="3.0"?>
<plugin>
	<extension point="org.eclipse.emf.ecore.generated_package">
		<package 
			uri = "http://www.xtext.org/example/mydsl/MyDsl"
			class = "org.xtext.example.mydsl.myDsl.MyDslPackage"
			genModel = "model/generated/MyDsl.genmodel" />
	</extension>
	<extension point="org.eclipse.emf.ecore.generated_package">
		<package 
			uri = "http://www.xtext.org/example/mydsl/Test"
			class = "org.xtext.example.mydsl.test.TestPackage"
			genModel = "model/generated/Test.genmodel" />
	</extension>
</plugin>



The Mwe2 File is from above
Re: generate with multiple independent grammars [message #1814248 is a reply to message #1814246] Fri, 06 September 2019 06:54 Go to previous messageGo to next message
Eclipse UserFriend
i want something that i can try out
Re: generate with multiple independent grammars [message #1814298 is a reply to message #1814248] Mon, 09 September 2019 02:50 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
here is the link. I zipped the parent directory
https://we.tl/t-XN3HB2SWgJ
Re: generate with multiple independent grammars [message #1814302 is a reply to message #1814298] Mon, 09 September 2019 03:31 Go to previous messageGo to next message
Eclipse UserFriend
you did not merge plugin.xml_gen -> plugin.xml

[Updated on: Mon, 09 September 2019 03:32] by Moderator

Re: generate with multiple independent grammars [message #1814303 is a reply to message #1814302] Mon, 09 September 2019 03:46 Go to previous messageGo to next message
Eclipse UserFriend
I deleted plugin.xml and renamed xml_gen.
Both languages are in plugin.xml
Re: generate with multiple independent grammars [message #1814305 is a reply to message #1814303] Mon, 09 September 2019 04:14 Go to previous messageGo to next message
Eclipse UserFriend
yes but if you do it for both mydsl and mydsl.ui it works perfectly fine
Re: generate with multiple independent grammars [message #1814306 is a reply to message #1814305] Mon, 09 September 2019 04:33 Go to previous message
Eclipse UserFriend
yes, thanks, it works.
Previous Topic:Cannot create resource...A Registered resource factory is needed
Next Topic:From EMF model to DSL
Goto Forum:
  


Current Time: Mon Mar 17 11:48:18 EDT 2025

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

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

Back to the top