Java Code Examples for org.antlr.runtime.Token#setType()
The following examples show how to use
org.antlr.runtime.Token#setType() .
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
Source File: InternalHighlightingParser.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected void announce(Token start, Token stop, AbstractElement element) { if (start != null && start != Token.EOF_TOKEN) { if (start == stop) { announce(start, element); } else { CommonToken castedStart = (CommonToken) start; if (stop == null) { // possible error condition if (start.getTokenIndex() == state.lastErrorIndex) { return; } } CommonToken castedEnd = (CommonToken) stop; Integer newType = rewriter.rewrite(castedStart, element); if (newType != null && castedEnd != null && castedEnd != Token.EOF_TOKEN) { LazyTokenStream castedInput = (LazyTokenStream) this.input; for (int i = castedStart.getTokenIndex() + 1; i < castedEnd.getTokenIndex(); i++) { Token token = castedInput.get(i); if (token.getChannel() != Token.HIDDEN_CHANNEL) token.setType(newType); } castedEnd.setType(newType); } } } }
Example 2
Source File: XtendDocumentTokenSource.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override protected TokenSource createTokenSource(String string) { final FlexTokenSource delegate = flexerFactory.createTokenSource(new StringReader(string)); return new TokenSource() { @Override public Token nextToken() { Token token = delegate.nextToken(); if(token.getType() == multilineTokenType) { String text = token.getText(); if(text.startsWith("/**") && !text.startsWith("/***")){ token.setType(JAVA_DOC_TOKEN_TYPE); } } return token; } @Override public String getSourceName() { return delegate.getSourceName(); } }; }