Search in sources :

Example 1 with ISemanticSequencer

use of org.eclipse.xtext.serializer.sequencer.ISemanticSequencer in project xtext-eclipse by eclipse.

the class SerializerTester method serialize.

/**
 * @since 2.3
 */
protected String serialize(EObject semanticObject, DelegatingSequenceAcceptor... acceptors) {
    ISequenceAcceptor debug = null;
    try {
        ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
        ISemanticSequencer semantic = semanticSequencerProvider.get();
        ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
        IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
        ISequenceAcceptor result = new StringBufferSequenceAcceptor();
        ISequenceAcceptor out = result;
        for (DelegatingSequenceAcceptor delegate : acceptors) {
            delegate.setDelegate(out);
            out = delegate;
        }
        out = debug = new DebugSequenceAcceptor(out);
        semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
        ISerializationContext context = getContext(semanticObject);
        syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
        hidden.init(context, semanticObject, out, errors);
        semantic.createSequence(context, semanticObject);
        return result.toString();
    } catch (Exception t) {
        if (debug != null) {
            System.out.println("Serializer debug output:");
            System.out.println(debug.toString());
        }
        Exceptions.sneakyThrow(t);
        return "";
    }
}
Also used : ISerializationDiagnostic(org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic) ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) StringBufferSequenceAcceptor(org.eclipse.xtext.serializer.acceptor.StringBufferSequenceAcceptor) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) ISequenceAcceptor(org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor) DelegatingSequenceAcceptor(org.eclipse.xtext.serializer.acceptor.DelegatingSequenceAcceptor) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer)

Example 2 with ISemanticSequencer

use of org.eclipse.xtext.serializer.sequencer.ISemanticSequencer in project xtext-core by eclipse.

the class SyntacticSequencerTest method testSequence.

private void testSequence(EObject inObj, String outModel) throws Exception {
    EObject outObj = getModel(outModel);
    ISerializationContext context = nmSequencer.findContexts(inObj, true, null).iterator().next();
    Acceptor actual = new Acceptor();
    ISemanticSequencer semanticSeq = semanticSequencerProvider.get();
    ISyntacticSequencer syntacticSeq = syntacticSequencerProvider.get();
    semanticSeq.init((ISemanticSequenceAcceptor) syntacticSeq, ISerializationDiagnostic.STDERR_ACCEPTOR);
    syntacticSeq.init(context, inObj, actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
    semanticSeq.createSequence(context, inObj);
    assertEquals(Joiner.on("\n").join(getNodeSequence(outObj)), Joiner.on("\n").join(actual.getResult()));
}
Also used : ISequenceAcceptor(org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor) ISemanticSequenceAcceptor(org.eclipse.xtext.serializer.acceptor.ISemanticSequenceAcceptor) ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) EObject(org.eclipse.emf.ecore.EObject) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer)

Example 3 with ISemanticSequencer

use of org.eclipse.xtext.serializer.sequencer.ISemanticSequencer in project xtext-core by eclipse.

the class SerializerTestHelper method serialize.

protected String serialize(EObject semanticObject, DelegatingSequenceAcceptor... acceptors) {
    ISequenceAcceptor debug = null;
    try {
        ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
        ISemanticSequencer semantic = semanticSequencerProvider.get();
        ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
        IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
        ISequenceAcceptor result = new StringBufferSequenceAcceptor();
        ISequenceAcceptor out = result;
        for (DelegatingSequenceAcceptor delegate : acceptors) {
            delegate.setDelegate(out);
            out = delegate;
        }
        out = debug = new DebugSequenceAcceptor(out);
        semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
        ISerializationContext context = getContext(semanticObject);
        syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
        hidden.init(context, semanticObject, out, errors);
        semantic.createSequence(context, semanticObject);
        return result.toString();
    } catch (Exception t) {
        if (debug != null) {
            System.out.println("Serializer debug output:");
            System.out.println(debug.toString());
        }
        Exceptions.sneakyThrow(t);
        return "";
    }
}
Also used : ISerializationDiagnostic(org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic) ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) StringBufferSequenceAcceptor(org.eclipse.xtext.serializer.acceptor.StringBufferSequenceAcceptor) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) ISequenceAcceptor(org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor) DelegatingSequenceAcceptor(org.eclipse.xtext.serializer.acceptor.DelegatingSequenceAcceptor) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer)

Example 4 with ISemanticSequencer

use of org.eclipse.xtext.serializer.sequencer.ISemanticSequencer in project xtext-core by eclipse.

the class Serializer method serialize.

protected void serialize(ISerializationContext context, EObject semanticObject, ISequenceAcceptor tokens, ISerializationDiagnostic.Acceptor errors) {
    ISemanticSequencer semantic = semanticSequencerProvider.get();
    ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
    IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
    semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
    syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
    hidden.init(context, semanticObject, tokens, errors);
    if (tokens instanceof TokenStreamSequenceAdapter)
        ((TokenStreamSequenceAdapter) tokens).init(context);
    semantic.createSequence(context, semanticObject);
}
Also used : ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer) TokenStreamSequenceAdapter(org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)

Example 5 with ISemanticSequencer

use of org.eclipse.xtext.serializer.sequencer.ISemanticSequencer in project xtext-core by eclipse.

the class Serializer method serialize.

/**
 * @deprecated use {@link #serialize(ISerializationContext, EObject, ISequenceAcceptor, ISerializationDiagnostic.Acceptor)}
 */
@Deprecated
protected void serialize(EObject semanticObject, EObject context, ISequenceAcceptor tokens, ISerializationDiagnostic.Acceptor errors) {
    ISemanticSequencer semantic = semanticSequencerProvider.get();
    ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
    IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
    semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
    syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
    hidden.init(context, semanticObject, tokens, errors);
    if (tokens instanceof TokenStreamSequenceAdapter)
        ((TokenStreamSequenceAdapter) tokens).init(context);
    semantic.createSequence(context, semanticObject);
}
Also used : ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer) TokenStreamSequenceAdapter(org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)

Aggregations

ISemanticSequencer (org.eclipse.xtext.serializer.sequencer.ISemanticSequencer)8 ISyntacticSequencer (org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer)7 IHiddenTokenSequencer (org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer)6 EObject (org.eclipse.emf.ecore.EObject)4 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)3 ISequenceAcceptor (org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor)3 TokenStreamSequenceAdapter (org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)3 ISerializationDiagnostic (org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic)3 DelegatingSequenceAcceptor (org.eclipse.xtext.serializer.acceptor.DelegatingSequenceAcceptor)2 StringBufferSequenceAcceptor (org.eclipse.xtext.serializer.acceptor.StringBufferSequenceAcceptor)2 DebugSequenceAcceptor (org.eclipse.xtext.testing.serializer.DebugSequenceAcceptor)2 IGrammarAccess (org.eclipse.xtext.IGrammarAccess)1 ISemanticSequenceAcceptor (org.eclipse.xtext.serializer.acceptor.ISemanticSequenceAcceptor)1 SequencerTestLanguageSemanticSequencer (org.eclipse.xtext.serializer.serializer.SequencerTestLanguageSemanticSequencer)1 ParseHelper (org.eclipse.xtext.testing.util.ParseHelper)1