Search in sources :

Example 1 with ITokenStreamExtension

use of org.eclipse.xtext.parsetree.reconstr.ITokenStreamExtension in project xtext-core by eclipse.

the class NodeModelStreamer method feedTokenStream.

@Override
public ITextRegion feedTokenStream(ITokenStream out, ICompositeNode in, int offset, int length) throws IOException {
    List<INode> nodes = getLeafs(in, offset, offset + length);
    if (nodes.isEmpty())
        return new TextRegion(in.getOffset(), 0);
    if (out instanceof ITokenStreamExtension)
        ((ITokenStreamExtension) out).init(findRootRuleForRegion(nodes.get(0)));
    boolean lastIsTokenOrComment = false;
    for (INode node : nodes) {
        boolean currentIsTokenOrComment = tokenUtil.isCommentNode(node) || tokenUtil.isToken(node);
        if (lastIsTokenOrComment && currentIsTokenOrComment)
            writeHiddenEmpty(out);
        lastIsTokenOrComment = currentIsTokenOrComment;
        if (node instanceof ILeafNode) {
            ILeafNode leaf = (ILeafNode) node;
            if (leaf.isHidden())
                writeHidden(out, leaf);
            else
                writeSemantic(out, leaf);
        } else if (node instanceof ICompositeNode)
            writeSemantic(out, (ICompositeNode) node);
    }
    out.flush();
    int rStart = nodes.get(0).getOffset();
    int rLength = nodes.get(nodes.size() - 1).getEndOffset() - rStart;
    return new TextRegion(rStart, rLength);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) ITokenStreamExtension(org.eclipse.xtext.parsetree.reconstr.ITokenStreamExtension)

Aggregations

ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)1 INode (org.eclipse.xtext.nodemodel.INode)1 ITokenStreamExtension (org.eclipse.xtext.parsetree.reconstr.ITokenStreamExtension)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1 TextRegion (org.eclipse.xtext.util.TextRegion)1