blob: faba1f4f9dee145b98e40c6176afed644f3a23fc [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2014, 2018 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.redocs.wikitext.r.core.source;
import static org.eclipse.statet.redocs.r.core.source.AbstractRChunkPartitionNodeScanner.R_CHUNK_BASE_TYPE;
import org.eclipse.statet.ecommons.text.core.treepartitioner.ITreePartitionNode;
import org.eclipse.statet.ecommons.text.core.treepartitioner.ITreePartitionNodeType;
import org.eclipse.statet.docmlet.wikitext.core.markup.IMarkupLanguage;
import org.eclipse.statet.docmlet.wikitext.core.source.EmbeddingAttributes;
import org.eclipse.statet.docmlet.wikitext.core.source.extdoc.WikidocPartitionNodeScanner;
import org.eclipse.statet.r.core.source.RPartitionNodeType;
import org.eclipse.statet.redocs.r.core.source.AbstractRChunkPartitionNodeScanner;
public class WikidocRweavePartitionNodeScanner extends WikidocPartitionNodeScanner {
private AbstractRChunkPartitionNodeScanner rScanner;
public WikidocRweavePartitionNodeScanner(final IMarkupLanguage markupLanguage) {
super(markupLanguage);
}
public WikidocRweavePartitionNodeScanner(final IMarkupLanguage markupLanguage,
final int markupLanguageMode) {
super(markupLanguage, markupLanguageMode);
}
@Override
protected void init() {
{ final IMarkupLanguage markupLanguage= getMarkupLanguage();
if (markupLanguage instanceof IRweaveMarkupLanguage) {
final IRweaveMarkupLanguage rweaveLanguage= (IRweaveMarkupLanguage) markupLanguage;
this.rScanner= rweaveLanguage.getRChunkPartitionScanner();
}
else {
throw new IllegalArgumentException("markupLanguage"); //$NON-NLS-1$
}
}
final ITreePartitionNode beginNode= getScan().getBeginNode();
if (beginNode.getType() instanceof RPartitionNodeType) {
assert (false);
// this.rBeginNode= beginNode;
// while (beginNode.getParent().getType() instanceof RPartitionNodeType) {
// beginNode= beginNode.getParent();
// }
// // !(beginNode.getParent().getType() instanceof RPartitionNodeType)
// final RPartitionNodeType rType= (RPartitionNodeType) beginNode.getType();
// if (rType == WikitextRChunkPartitionNodeScanner.R_CHUNK_CONTROL_TYPE) {
// initNode(beginNode, RCHUNK_WIKITEXT_TYPE);
// }
// else {
// initNode(beginNode, RINLINE_WIKITEXT_TYPE);
// }
// return;
}
super.init();
}
@Override
protected void beginEmbeddingBlock(final BlockType type,
final EmbeddingAttributes attributes) {
if (type == BlockType.CODE
&& attributes.getForeignType() == IRweaveMarkupLanguage.EMBEDDED_R) {
addNode(R_CHUNK_BASE_TYPE, getEventBeginOffset());
setEmbedded(getNode(), attributes);
return;
}
super.beginEmbeddingBlock(type, attributes);
}
@Override
protected void endEmbeddingBlock(final ITreePartitionNodeType type,
final EmbeddingAttributes attributes) {
if (type instanceof RPartitionNodeType) {
// this.embeddedContentEndOffset= getScan().getDocument().getLength();
executeForeignScanner(this.rScanner);
exitNode(getEventEndOffset(), 0);
return;
}
super.endEmbeddingBlock(type, attributes);
}
@Override
protected void beginEmbeddingSpan(final SpanType type, final EmbeddingAttributes attributes) {
if (type == SpanType.CODE
&& attributes.getForeignType() == IRweaveMarkupLanguage.EMBEDDED_R) {
addNode(this.rScanner.getDefaultRootType(),
getBeginOffset() + attributes.getContentRegion().getOffset() );
setEmbedded(getNode(), attributes);
return;
}
super.beginEmbeddingSpan(type, attributes);
}
@Override
protected void endEmbeddingSpan(final ITreePartitionNodeType type, final EmbeddingAttributes attributes) {
if (type instanceof RPartitionNodeType) {
if (this.embeddedContentEndOffset < 0) {
this.embeddedContentEndOffset= getEventEndOffset() - 1;
}
exitNode(this.embeddedContentEndOffset, 0);
if (this.embeddingNode.getLength() > 0) {
executeForeignScanner(this.rScanner);
}
return;
}
super.endEmbeddingSpan(type, attributes);
}
}