Java Code Examples for org.eclipse.xtext.serializer.acceptor.ISyntacticSequenceAcceptor

The following examples show how to use org.eclipse.xtext.serializer.acceptor.ISyntacticSequenceAcceptor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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)));
}
 
Example 2
Source Project: xtext-core   Source File: PartialSerializer.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void serialize(ITextRegionDiffBuilder result) {
	ISemanticSequencer semantic = semanticSequencerProvider.get();
	ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
	IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
	semantic.init((ISemanticSequenceAcceptor) syntactic, errorAcceptor);
	syntactic.init(context, root, (ISyntacticSequenceAcceptor) hidden, errorAcceptor);
	ISequenceAcceptor acceptor;
	if (insertAt instanceof IHiddenRegion) {
		IHiddenRegion h = (IHiddenRegion) insertAt;
		acceptor = result.replaceSequence(h, h, context, root);
	} else {
		IHiddenRegion originalFirst = insertAt.getPreviousHiddenRegion();
		IHiddenRegion originalLast = insertAt.getNextHiddenRegion();
		acceptor = result.replaceSequence(originalFirst, originalLast, context, root);
	}
	hidden.init(context, root, acceptor, errorAcceptor);
	if (acceptor instanceof TokenStreamSequenceAdapter)
		((TokenStreamSequenceAdapter) acceptor).init(context);
	semantic.createSequence(context, root);
}
 
Example 3
Source Project: xtext-extras   Source File: SerializerTester.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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 "";
	}
}
 
Example 4
Source Project: xtext-eclipse   Source File: SerializerTester.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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 "";
	}
}
 
Example 5
@Override
@Deprecated
public void init(EObject context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor,
		Acceptor errorAcceptor) {
	ISerializationContext ctx = SerializationContext.fromEObject(context, semanticObject);
	init(ctx, semanticObject, sequenceAcceptor, errorAcceptor);
}
 
Example 6
@Override
public void init(ISerializationContext context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor,
		Acceptor errorAcceptor) {
	INode node = NodeModelUtils.findActualNodeFor(semanticObject);
	syntacticSequencerPDAs = pdaProvider.getSyntacticSequencerPDAs(grammar.getGrammar());
	ISynAbsorberState state = syntacticSequencerPDAs.get(context);
	Preconditions.checkNotNull(state, "Invalid context: " + context);
	SyntacticalContext acceptor = new SyntacticalContext(context, semanticObject, state, node);
	contexts.push(acceptor);
	delegate = sequenceAcceptor;
	this.errorAcceptor = errorAcceptor;
}
 
Example 7
Source Project: xtext-core   Source File: Serializer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example 8
Source Project: xtext-core   Source File: Serializer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source Project: xtext-core   Source File: SerializerTestHelper.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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 "";
	}
}
 
Example 10
Source Project: xtext-core   Source File: FormatterTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example 11
public void init(ISerializationContext context, EObject semanticObject,
			ISyntacticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor) {
	super.init(context, semanticObject, sequenceAcceptor, errorAcceptor);
	if (sequenceAcceptor instanceof ISequenceAcceptor) {
		this.trailingSequenceAcceptor = (ISequenceAcceptor) sequenceAcceptor;
	}
	this.documentedSemanticObjects.clear();
	this.indocumentedSemanticObjects.clear();
	this.lastInnerBlock = null;
}
 
Example 12
Source Project: xtext-core   Source File: ISyntacticSequencer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @deprecated use {@link #init(ISerializationContext, EObject, ISyntacticSequenceAcceptor, ISerializationDiagnostic.Acceptor)}
 */
@Deprecated
void init(EObject context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor,
		ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 13
Source Project: xtext-core   Source File: ISyntacticSequencer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
void init(ISerializationContext context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor,
ISerializationDiagnostic.Acceptor errorAcceptor);