Serializing cross-references with Serializer2 [message #1739018] |
Tue, 26 July 2016 17:56  |
Eclipse User |
|
|
|
The documentation states that the serialization of cross-references can be customized by implementing ICrossReferenceSerializer., but it looks like this is used only by the deprecated Serializer from org.eclipse.xtext.parsetree.reconstr.
How can one customize the serialization of cross-references with the new Serializer2?
|
|
|
|
|
|
|
Re: Serializing cross-references with Serializer2 [message #1739115 is a reply to message #1739097] |
Wed, 27 July 2016 11:07   |
Eclipse User |
|
|
|
from this message i dont see where the cross ref serializer is involved
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID ('from' from=[Greeting])?'!';
public class MyDslCRS extends CrossReferenceSerializer {
@Override
public boolean isValid(EObject semanticObject, CrossReference crossref, EObject target, INode node,
Acceptor errors) {
System.out.println("isValid");
return super.isValid(semanticObject, crossref, target, node, errors);
}
@Override
public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node,
Acceptor errors) {
System.out.println("serialize");
return super.serializeCrossRef(semanticObject, crossref, target, node, errors);
}
}
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
def Class<? extends ICrossReferenceSerializer> bindICrossReferenceSerializer() {
MyDslCRS
}
}
class Main {
def static void main(String[] args) {
val i = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration
val rs = i.getInstance(ResourceSet)
val r = rs.createResource(URI.createURI("demo.mydsl2"))
val model = MyDslFactory.eINSTANCE.createModel => [
val g1 = MyDslFactory.eINSTANCE.createGreeting => [
name = "g1"
]
val g2 = MyDslFactory.eINSTANCE.createGreeting => [
name = "g2"
from = g1
]
greetings += g1
greetings += g2
]
r.contents += model
r.save(SaveOptions.defaultOptions.toOptionsMap)
}
}
the value aboout the resource comes from ???
XMLSaveImpl does not sound like eclipse? sure you did not acidentally called standaloensetup from eclipse?
then it would be interesting: is this called from eclipse or is this called from standalone.
if from eclipse did you use LiveScopeResourceSetInitializer to init your resourceset
|
|
|
Re: Serializing cross-references with Serializer2 [message #1739118 is a reply to message #1739115] |
Wed, 27 July 2016 11:17   |
Eclipse User |
|
|
|
Sorry, I think we got messages posted at the same time.
Yes, the XMLSaveImpl was misleading. I forgot I was serializing the model as an XML resource before invoking the serialization on the XtextResource.
Nevertheless, ignoring that, I still have a problem, as explained in my last message:
The failure occurs very early, in org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(ISerializationContext, EObject), when the EObject is the root element of the model, and it is caused because the call
List<TraceItem> trace = new NfaUtil().backtrack(nfa, co, new NfaUtil.BacktrackHandler<ISemState, TraceItem>() ...
returns null.
So I was wondering if there is a particular pattern in a grammar that makes this backtracking fail, or if there was a description somewhere about this backtracking mechanism in serialization, so I can figure it out.
Thanks
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04779 seconds