Mixin Xtext with other models [message #1787570] |
Tue, 29 May 2018 09:20 |
Daniel Lipski Messages: 20 Registered: May 2018 |
Junior Member |
|
|
Hi,
currently we are working on our first Xtext project. I've read Xtext docs, "Implementing Domain-Specific Languages with Xtext and Xtend 2ed" book and other Internet articles but I couldn't find answers to my questions.
First let me shortly describe what we would like to achieve. We are building web app (xtext+lsp+monaco) where user can upload a file (xlsx or xml) and have special editor to manipulate/calculate file contents.
For example if I upload a xlsx:
|columnX|columnY|columnZ|
|10 |20 |30 |
and if I write an expression: (row[1].columnX+row[1],columnY)/row[1].columnZ
the evaluator should return: 1; (10+20)/30
We started writing Xtext grammar for our expression language - this part is not so hard because there is a lot of examples (book & internet).
Currently we are working on content assist (if I type "row[1]." the editor should suggest: columnX, columnY, columnZ) and type checking (if I type "row[1].columnTEST" the editor should show error because our sample Excel contains only 3 columns)
Here problems starts :), below are our supposition/assumptions:
1)As far as I understand what we would like to achieve (content assist and type checking) in our case is related with cross-references
2)The expression grammar (or ecore model) should reference ecore objects representing uploaded files (excel columns or xml structure) to let content assist/type checking work properly
3)The xtext index should contain ecore objects for file(xlsx/xml) structures
4)We should provide xtext scope implementation/configuration to limit valid suggestions in specific context.
If someone could briefly describe how to achieve these goals (if they are correct) I will be grateful. Bellow are questions related to above assumptions
Ad2)Our grammar is only for typing expressions, there are no language constructs allowing to define data structures -> generated ecore model does not define classes to describe xlsx/xml file structure (we cannot reference to this object in our grammar). Do we have to add to the generated model such classes and turn of auto-generation of model from our grammar (import instead of generate) or there is another way ? (create separate model for file structure and import this model into grammar - leaving auto-generation of expression model ?)
Ad3)How to fill the Xtext index with ecore objects (EObjectDescription) when user uploads a file (xlsx/xml) describing structure of this file (existing columns in Excel or tags in XML)? This file is not our "source file" - there are no expression to parse, no AST is build, nor xtext index is filled with ecore objects. I suspect we should do this with GlobalScope and some custom ResourceDescription ? This part it the less known for us.
Sorry if this questions are a little chaotic but we don't know Xtext and EMF internals very well and we fell like we are walking around in a fog ;)
Regards
Daniel
|
|
|
|
|
|
|
|
|
Re: Mixin Xtext with other models [message #1790354 is a reply to message #1790346] |
Fri, 08 June 2018 13:52 |
|
i still dont understand which files are physical and which are not.
in the example from the issue it is about physical files.
the magic is done here:
override Result doInitialBuild(CancelIndicator cancelIndicator) {
val uris = newArrayList
projectConfig.sourceFolders.forEach [
fileSystemScanner.scan(path)[uris += it]
]
val r = MyDslLib.classLoader.getResource(MyDslLib.LIB)
uris+=URI.createURI(r.toString)
return doBuild(uris, emptyList, emptyList, cancelIndicator)
}
it loads the files from the classpath.
unfortualtely there is no easy shiny way to do anything here.
you would have to teach the doBuild to be able to work with your other uris
=> i assume you need a custom uri scheme and converter as you would do it outside of lsp (e.g. with InMemoryURIHandler)
=> you then would have to make sure this handler is used with the resourceset org.eclipse.xtext.ide.server.ProjectManager.createNewResourceSet(ResourceDescriptionsData)
=> or you adopt the resource loading org.eclipse.xtext.build.ClusteringStorageAwareResourceLoader.executeClustered(Iterable<URI>, (Resource)=>T)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03162 seconds