Search in sources :

Example 1 with IHiddenTokenSequencer

use of org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer 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 2 with IHiddenTokenSequencer

use of org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer 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 3 with IHiddenTokenSequencer

use of org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer 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)

Example 4 with IHiddenTokenSequencer

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

the class HiddenTokenSequencerTest method testSequence.

private void testSequence(String stringModel) throws Exception {
    EObject model = getModel(stringModel);
    ISerializationContext context = nmSequencer.findContexts(model, true, null).iterator().next();
    DebugSequenceAcceptor actual = new NoEnterNodesDebugSequenceAcceptor(false);
    ISemanticSequencer semanticSequencer = semanticSequencerProvider.get();
    ISyntacticSequencer syntacticSequencer = syntacticSequencerProvider.get();
    IHiddenTokenSequencer hiddenTokenSequencer = hiddenTokenSequencerProvider.get();
    semanticSequencer.init((ISemanticSequenceAcceptor) syntacticSequencer, ISerializationDiagnostic.STDERR_ACCEPTOR);
    syntacticSequencer.init(context, model, (ISyntacticSequenceAcceptor) hiddenTokenSequencer, ISerializationDiagnostic.STDERR_ACCEPTOR);
    hiddenTokenSequencer.init(context, model, actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
    semanticSequencer.createSequence(context, model);
    // System.out.println(actual);
    // System.out.println(NodeModelUtils.compactDump(NodeModelUtils.findActualNodeFor(model), true));
    assertEquals(Joiner.on("\n").join(getNodeSequence(model)), Joiner.on("\n").join(actual.getColumn(4)));
}
Also used : ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) EObject(org.eclipse.emf.ecore.EObject) DebugSequenceAcceptor(org.eclipse.xtext.testing.serializer.DebugSequenceAcceptor) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer)

Example 5 with IHiddenTokenSequencer

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

the class FormatterTest method serializeToTokenBuffer.

protected void serializeToTokenBuffer(String model, ITokenStream out) throws Exception {
    EObject semanticObject = get(ParseHelper.class).parse(model);
    ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
    ISemanticSequencer semantic = get(ISemanticSequencer.class);
    ISyntacticSequencer syntactic = get(ISyntacticSequencer.class);
    IHiddenTokenSequencer hidden = get(IHiddenTokenSequencer.class);
    TokenStreamSequenceAdapter tokenstream = new TokenStreamSequenceAdapter(out, getGrammarAccess().getGrammar(), errors);
    semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
    ISerializationContext context = new SerializationContext.RuleContext(null, (ParserRule) get(IGrammarAccess.class).getGrammar().getRules().get(0));
    syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
    hidden.init(context, semanticObject, tokenstream, errors);
    tokenstream.init(context);
    semantic.createSequence(context, semanticObject);
}
Also used : ParseHelper(org.eclipse.xtext.testing.util.ParseHelper) ISerializationDiagnostic(org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic) ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) IGrammarAccess(org.eclipse.xtext.IGrammarAccess) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) EObject(org.eclipse.emf.ecore.EObject) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer) TokenStreamSequenceAdapter(org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)

Aggregations

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