Search in sources :

Example 1 with InternalN4JSLexer

use of org.eclipse.n4js.ui.contentassist.antlr.lexer.InternalN4JSLexer in project n4js by eclipse.

the class NodeModelTokenSource method toPrefixToken.

/**
 * Produce an Antlr token for the prefix of the given leaf that overlaps the requested region
 *
 * @see #endOffset
 */
private Token toPrefixToken(ILeafNode leaf) {
    Lexer lexer = new InternalN4JSLexer();
    String text = leaf.getText();
    String prefix = text.substring(0, endOffset - leaf.getTotalOffset());
    ANTLRStringStream stream = new ANTLRStringStream(prefix);
    lexer.setCharStream(stream);
    Token nextToken = lexer.nextToken();
    // copy to get rid of the reference to the stream again
    return new CommonToken(nextToken.getType(), nextToken.getText());
}
Also used : InternalN4JSLexer(org.eclipse.n4js.ui.contentassist.antlr.lexer.InternalN4JSLexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Lexer(org.eclipse.xtext.ide.editor.contentassist.antlr.internal.Lexer) InternalN4JSLexer(org.eclipse.n4js.ui.contentassist.antlr.lexer.InternalN4JSLexer) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) CommonToken(org.antlr.runtime.CommonToken)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 CommonToken (org.antlr.runtime.CommonToken)1 Token (org.antlr.runtime.Token)1 InternalN4JSLexer (org.eclipse.n4js.ui.contentassist.antlr.lexer.InternalN4JSLexer)1 Lexer (org.eclipse.xtext.ide.editor.contentassist.antlr.internal.Lexer)1