Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Multiple grammars and example web editor(Multiple grammars and example web editor)
Multiple grammars and example web editor [message #1798163] Tue, 13 November 2018 14:18 Go to next message
Pierre Padovani is currently offline Pierre PadovaniFriend
Messages: 7
Registered: November 2018
Junior Member
I have an XText project with five distinct grammars, and have everything working through the IDE, including cross referencing between grammars. I'm at the point where I'm looking at integrating a web based editor for the grammars.

If I run the web example as generated it works correctly for the first grammar defined in the mwe2 workflow. However, if I change the extension within the index.html of the generated example to point to the second or third grammar the editor fails with an error that looks like:

"Xtext service 'occurrences' failed: Unable to identify the Xtext language for resource 2103f6f5.ed"

Can someone shed some light on why just swapping the extension used would not work? At this point I'm just exploring the code in an attempt to gain insight in order to figure out the best way to integrate it into our existing console code.

Thanks!

Pierre Padovnai
Re: Multiple grammars and example web editor [message #1798243 is a reply to message #1798163] Wed, 14 November 2018 15:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
how does your MyDslServlet.init() look like with respect to calling all standalone setups

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple grammars and example web editor [message #1798249 is a reply to message #1798243] Wed, 14 November 2018 16:39 Go to previous messageGo to next message
Pierre Padovani is currently offline Pierre PadovaniFriend
Messages: 7
Registered: November 2018
Junior Member
I got a chance this morning to debug the init() call and tracing backwards, I found that only the first grammar servlet is initialized/loaded. I believe this might be due to the fact that the annotations of the two generated servlets have the same urlpatterns annotation settings. Changing these and creating new directories for each grammar, causes 404s. To be honest this style of servlet annotation and setup is outside my expertise, and I am unsure what needs to be done to bring this into a workable example.

We are using spring-boot 2, is there an example or thread somewhere that shows how to integrate the servlets/editors into a spring boot service?
Re: Multiple grammars and example web editor [message #1798250 is a reply to message #1798249] Wed, 14 November 2018 16:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
no i have no idea about spring boot. i wonder if you simply use the same servlet for both

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple grammars and example web editor [message #1798254 is a reply to message #1798250] Wed, 14 November 2018 16:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
i mean somehting like

override init() {
super.init()
MyDsl1WebSetup.doSetup()
val injector = new MyDslWebSetup().createInjectorAndDoEMFRegistration()
disposableRegistry = injector.getInstance(DisposableRegistry)
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple grammars and example web editor [message #1798257 is a reply to message #1798254] Wed, 14 November 2018 17:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
see https://github.com/eclipse/xtext-web/blob/master/org.eclipse.xtext.web.example.jetty/src/main/java/org/eclipse/xtext/web/example/jetty/MyXtextServlet.xtend

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple grammars and example web editor [message #1798271 is a reply to message #1798257] Wed, 14 November 2018 18:33 Go to previous messageGo to next message
Pierre Padovani is currently offline Pierre PadovaniFriend
Messages: 7
Registered: November 2018
Junior Member
This is what my servlet code looks like:

@WebServlet(name = 'XtextServices', urlPatterns = '/xtext-service/*')
class DiscoveryPackServlet extends XtextServlet {
	
	DisposableRegistry disposableRegistry
	
	override init() {
		super.init()
		val injector = new DiscoveryPackWebSetup().createInjectorAndDoEMFRegistration()
		disposableRegistry = injector.getInstance(DisposableRegistry)
	}
	
	override destroy() {
		if (disposableRegistry !== null) {
			disposableRegistry.dispose()
			disposableRegistry = null
		}
		super.destroy()
	}
	
}


The only difference between the two generated servlets is the call to the *WebSetup().
Re: Multiple grammars and example web editor [message #1798274 is a reply to message #1798271] Wed, 14 November 2018 19:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
the intention is that you call the standalonsetups of all your languages

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple grammars and example web editor [message #1798280 is a reply to message #1798274] Wed, 14 November 2018 20:27 Go to previous messageGo to next message
Pierre Padovani is currently offline Pierre PadovaniFriend
Messages: 7
Registered: November 2018
Junior Member
Right... I have a servlet class for each, and it looks like the annotation on the class is used to create the ServletHolder which in turn contains the servlet class. However, only the first servlet as defined in the workflow is ever instantiated and initialized. I've tried changing the urlPattern on the annotations to point to different paths, but that just breaks things. :-)

This is easily reproducible, use a workflow file like:

Workflow {

  component = XtextGenerator {
    configuration = {
      project = StandardProjectConfig {
        baseName = "com.civitaslearning.platform.configuration"
        rootPath = rootPath
        runtimeTest = {
          enabled = true
        }
        eclipsePlugin = {
          enabled = true
        }
        eclipsePluginTest = {
          enabled = true
        }
        web = {
          enabled = true
        }
        createEclipseMetaData = true
      }
      code = {
        encoding = "UTF-8"
        lineDelimiter = "\n"
        fileHeader = "/*\n * generated by Xtext \${version}\n */"
      }
    }
    language = StandardLanguage {
      name = "com.civitaslearning.platform.configuration.DiscoveryPack"
      fileExtensions = "dp"
      serializer = {
        generateStub = false
      }
      validator = {
      // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
        generateDeprecationValidation = true
      }
      parserGenerator = {
        options = {
          classSplitting = true
          fieldsPerClass = "500"
          backtrack=true
        }
      }
      formatter = {
        generateStub = true
      }
    }
    language = StandardLanguage {
      name = "com.civitaslearning.platform.configuration.ExtractDescriptor"
      fileExtensions = "ed"
      referencedResource =
      "platform:/resource/com.civitaslearning.platform.configuration/src/com/civitaslearning/platform/configuration/DiscoveryPack.xtext"
      serializer = {
        generateStub = false
      }
      validator = {
      // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
      }
      parserGenerator = {
        options = {
          classSplitting = true
          fieldsPerClass = "500"
        }
      }
      formatter = {
        generateStub = true
      }
    }
  }
}


Set whatever grammar you want into the two grammar xtext files. Generate everything including web example. Edit the index.html in the WebRoot, and change the extension to 'ed' instead of the 'dp' as defined above.

[Updated on: Wed, 14 November 2018 20:31]

Report message to a moderator

Re: Multiple grammars and example web editor [message #1798283 is a reply to message #1798280] Wed, 14 November 2018 22:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Still the questions: did you manually edit the servlet class.
And> do you want to have one servlet or two


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 14 November 2018 22:13]

Report message to a moderator

Re: Multiple grammars and example web editor [message #1798287 is a reply to message #1798283] Wed, 14 November 2018 23:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
the following works for me for the communication

class MyDslAServlet extends XtextServlet {
	
	DisposableRegistry disposableRegistry
	
	override init() {
		super.init()
		new MyDslBWebSetup().createInjectorAndDoEMFRegistration
		val injector = new MyDslAWebSetup().createInjectorAndDoEMFRegistration()
		disposableRegistry = injector.getInstance(DisposableRegistry)
	}


<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Content-Language" content="en-us">
	<title>Example Web Editor</title>
	<link rel="stylesheet" type="text/css" href="xtext/2.15.0/xtext-ace.css"/>
	<link rel="stylesheet" type="text/css" href="style.css"/>
	<script src="webjars/requirejs/2.3.2/require.min.js"></script>
	<script type="text/javascript">
		var baseUrl = window.location.pathname;
		var fileIndex = baseUrl.indexOf("index.html");
		if (fileIndex > 0)
			baseUrl = baseUrl.slice(0, fileIndex);
		require.config({
			baseUrl: baseUrl,
			paths: {
				"jquery": "webjars/jquery/2.2.4/jquery.min",
				"ace/ext/language_tools": "webjars/ace/1.2.3/src/ext-language_tools",
				"xtext/xtext-ace": "xtext/2.15.0/xtext-ace"
			}
		});
		require(["webjars/ace/1.2.3/src/ace"], function() {
			require(["xtext/xtext-ace"], function(xtext) {
				xtext.createEditor({
					baseUrl: baseUrl,
					loadFromServer: false,
					
				});
			});
		});
	</script>
</head>
<body>

	<div class="header">
		<h1>Example MyDslA Web Editor</h1>
	</div>
	<div class="content">
		<div class="xtext-editor" data-editor-resource-id="multi-resource/left.mydsla">
<pre>
HelloA A!
<pre>
		</div>
	</div>
	<div class="content">
		<div class="xtext-editor" data-editor-resource-id="multi-resource/right.mydslb">
<pre>
HelloB B!
</pre>
		</div>
	</div>

</body>
</html>



//needs copy of WebRoot/xtext-resources/generated/* to WebRoot/xtext-resources/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple grammars and example web editor [message #1798288 is a reply to message #1798287] Wed, 14 November 2018 23:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
alternatively you can do it this way(client side)

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Content-Language" content="en-us">
	<title>Example Web Editor</title>
	<link rel="stylesheet" type="text/css" href="xtext/2.15.0/xtext-ace.css"/>
	<link rel="stylesheet" type="text/css" href="style.css"/>
	<script src="webjars/requirejs/2.3.2/require.min.js"></script>
	<script type="text/javascript">
		var baseUrl = window.location.pathname;
		var fileIndex = baseUrl.indexOf("index.html");
		if (fileIndex > 0)
			baseUrl = baseUrl.slice(0, fileIndex);
		require.config({
			baseUrl: baseUrl,
			paths: {
				"jquery": "webjars/jquery/2.2.4/jquery.min",
				"ace/ext/language_tools": "webjars/ace/1.2.3/src/ext-language_tools",
				"xtext/xtext-ace": "xtext/2.15.0/xtext-ace"
			}
		});
		require(["webjars/ace/1.2.3/src/ace"], function() {
			require(["xtext/xtext-ace"], function(xtext) {
				xtext.createEditor({
					baseUrl: baseUrl,
					loadFromServer: false,
					parentClass: "xtext-editora",
					syntaxDefinition: "xtext-resources/generated/mode-mydsla"
				});
				xtext.createEditor({
					baseUrl: baseUrl,
					loadFromServer: false,
					parentClass: "xtext-editorb",
					syntaxDefinition: "xtext-resources/generated/mode-mydslb"
				});
			});
		});
	</script>
</head>
<body>

	<div class="header">
		<h1>Example MyDslA Web Editor</h1>
	</div>
	<div class="content">
		<div class="xtext-editora" data-editor-resource-id="multi-resource/left.mydsla">
<pre>
HelloA A!
<pre>
		</div>
	</div>
	<div class="content">
		<div class="xtext-editorb" data-editor-resource-id="multi-resource/right.mydslb">
<pre>
HelloB B!
</pre>
		</div>
	</div>

</body>
</html>



ps.: here is my css

body {
	width: 100%;
	height: 100%;
	overflow: hidden;
	font: 16px Helvetica,sans-serif;
}

a {
	color: #22a;
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}


.content {
	display: block;
	width: 400px;
	height: 300px;
}

.xtext-editor {
	display: block;
	position: absolute;
	width: 400px;
	height: 300px;
	padding: 4px;
	border: 1px solid #aaa;
}


.xtext-editora {
	display: block;
	position: absolute;
	width: 400px;
	height: 300px;
	padding: 4px;
	border: 1px solid #aaa;
}


.xtext-editorb {
	display: block;
	position: absolute;
	width: 400px;
	height: 300px;
	padding: 4px;
	border: 1px solid #aaa;
}






Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple grammars and example web editor [message #1798333 is a reply to message #1798288] Thu, 15 November 2018 14:28 Go to previous message
Pierre Padovani is currently offline Pierre PadovaniFriend
Messages: 7
Registered: November 2018
Junior Member
You were finally able to hit me with a big enough hammer to get my brain to comprehend this!!!

Got it working!

Thanks!!!

Pierre Padovani
Previous Topic:Implementing dates clashes with simple equations
Next Topic:modifications to imported models
Goto Forum:
  


Current Time: Wed Sep 25 18:24:47 GMT 2024

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

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

Back to the top