|
|
Re: Not quite understanding how x-referencing works [message #1460404 is a reply to message #1457843] |
Mon, 03 November 2014 14:34 |
Arsenij Solovjev Messages: 9 Registered: October 2014 |
Junior Member |
|
|
Thanks for the reply Christian, however that doesn't seem to work.
This is what I tried to do:
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
Injector injector = new ArchnemesisStandaloneSetup().createInjectorAndDoEMFRegistration();
resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
...
Resource resource = resourceSet.createResource(URI.createURI("dummy:/inmemory.chralx"));
resource.load(in, resourceSet.getLoadOptions());
linker.linkModel(resource.getContents().get(0), consumer);
return resource.getContents().get(0);
The reference
architecture.getConnectors().get(0).getFrom()
is still null though :/
EDIT architecture.getConnectors().get(0) isn't null
[Updated on: Mon, 03 November 2014 14:53] Report message to a moderator
|
|
|
|
|
|
Re: Not quite understanding how x-referencing works [message #1460475 is a reply to message #1460441] |
Mon, 03 November 2014 16:00 |
Arsenij Solovjev Messages: 9 Registered: October 2014 |
Junior Member |
|
|
Gladly. In case of confusion I have two parse() methods and I'm only using parse2().
Grammar:
grammar de.fu_berlin.inf.archnemesis.Archnemesis with org.eclipse.xtext.common.Terminals
generate archnemesis "http //www.fu_berlin.de/inf/archnemesis/Archnemesis"
Architecture:
rootComponent=RootComponent
(components+=Component)+
(connectors+=Connector)*;
Element:
Component | Connector | Constraint;
RootComponent:
'root' name=ID ':' namespace=PackageName;
Component:
'component' name=ID ':' namespace=PackageName;
Connector:
from=[Component] '=>' to=[Component]
;
Model File:
root saros: de.fu_berlin.dpp
component session_management: de.fu_berlin.dpp.project
component operational_transformation: de.fu_berlin.dpp.concurrent
component network: de.fu_berlin.dpp.net
session_management => operational_transformation
//session_management => network
//invitation => network
Main class:
public class XtextParser {
// @Inject
// private IParser parser;
//
// @Inject
// private ILinker linker;
// @Inject
private XtextResourceSet resourceSet;
public XtextParser() {
setupParser();
}
private void setupParser() {
new org.eclipse.emf.mwe.utils.StandaloneSetup()
.setPlatformUri("../");
Injector injector = new ArchnemesisStandaloneSetup()
.createInjectorAndDoEMFRegistration();
resourceSet = injector.getInstance(XtextResourceSet.class);
}
/**
* Parses data provided by an input reader using Xtext and returns the
* root node of the resulting object tree.
*
* @param reader
* Input reader
* @return root object node
* @throws IOException
* when errors occur during the parsing process
*/
public EObject parse(Reader reader) throws IOException {
IParseResult result = parser.parse(reader);
if (result.hasSyntaxErrors()) {
throw new ParseException(
"Provided input contains syntax errors.");
}
return result.getRootASTElement();
}
public EObject parse2(InputStream in) throws IOException {
Resource resource = resourceSet.createResource(URI
.createURI("dummy:/inmemory.chralx"));
// EcoreUtil.resolveAll(resourceSet);
resource.load(in, resourceSet.getLoadOptions());
IDiagnosticConsumer consumer = new IDiagnosticConsumer() {
@Override
public void consume(Diagnostic diagnostic, Severity severity) {
// TODO Auto-generated method stub
}
@Override
public boolean hasConsumedDiagnostics(Severity severity) {
// TODO Auto-generated method stub
return true;
}
};
EcoreUtil.resolveAll(resourceSet);
return resource.getContents().get(0);
}
}
[Updated on: Mon, 03 November 2014 16:01] Report message to a moderator
|
|
|
Re: Not quite understanding how x-referencing works [message #1460486 is a reply to message #1460475] |
Mon, 03 November 2014 16:13 |
|
Hi,
unfortunately your grammar ist not complete
i asume the following one
Architecture:
rootComponent=RootComponent
(components+=Component)+
(connectors+=Connector)*;
Element:
Component | Connector;
RootComponent:
'root' name=ID ':' namespace=PackageName;
Component:
'component' name=ID ':' namespace=PackageName;
Connector:
from=[Component] '=>' to=[Component]
;
PackageName:
ID ("." ID)*
;
then the follonging test works fine for me
package org.xtext.example.mydsl2.tests
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.junit.Test
import org.xtext.example.mydsl2.MyDslStandaloneSetup
import org.xtext.example.mydsl2.myDsl.Architecture
class SampleTest {
@Test
def void testIt() {
val i = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration()
val rs = i.getInstance(ResourceSet)
val r = rs.getResource(URI.createURI("test.mydsl2"), true)
r.load(null)
val root = r.contents.get(0)
if (root instanceof Architecture) {
println('''
«FOR c : root.connectors»
«c.from.namespace» «c.to.namespace»
«ENDFOR»
''')
}
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Not quite understanding how x-referencing works [message #1460495 is a reply to message #1460486] |
Mon, 03 November 2014 16:21 |
|
or to be a biote more xtendish
@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class SampleTest {
@Inject extension ParseHelper<Architecture>
@Test
def void testIt() {
val a = '''
root saros: de.fu_berlin.dpp
component session_management: de.fu_berlin.dpp.project
component operational_transformation: de.fu_berlin.dpp.concurrent
component network: de.fu_berlin.dpp.net
session_management => operational_transformation
//session_management => network
//invitation => network'''.parse
println('''
«FOR c : a.connectors»
«c.from.namespace» «c.to.namespace»
«ENDFOR»
''')
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04094 seconds