Java Code Examples for org.antlr.runtime.TokenSource#nextToken()
The following examples show how to use
org.antlr.runtime.TokenSource#nextToken() .
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: DotHtmlLabelIDValueConverter.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override protected void assertTokens(String value, TokenSource tokenSource, String escapedString) { if (tokenSource == null) return; Token token = tokenSource.nextToken(); // customization start if ("ID".equals(getRuleName()) && "TEXT".equals(getRuleName(token))) { return; } // customization end if (!escapedString.equals(token.getText())) { throw createTokenContentMismatchException(value, escapedString, token); } if (!getRuleName().toUpperCase().equals(getRuleName(token))) { throw createTokenTypeMismatchException(value, escapedString, token); } String reparsedValue = toValue(token.getText(), null); if (value != reparsedValue && !value.equals(reparsedValue)) { throw createTokenContentMismatchException(value, escapedString, token); } }
Example 2
Source File: LexerMultiplexer.java From ghidra with Apache License 2.0 | 5 votes |
@Override public Token nextToken() { Integer mode = stack.peekFirst(); TokenSource src = modes[mode]; Token t; do { t = src.nextToken(); //System.out.println("Token(" + mode + "," + src.getSourceName() + "): " + t); } while (!channels.contains(t.getChannel())); return t; }
Example 3
Source File: TokenSequencePreservingPartialParsingHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isSameTokenSequence(TokenSource originalSource, TokenSource newSource, int expectedLength) { Token token = originalSource.nextToken(); int newLength = 0; while(Token.EOF != token.getType()) { Token newToken = newSource.nextToken(); if (token.getType() != newToken.getType()) { return false; } newLength += TokenTool.getLength(newToken); token = originalSource.nextToken(); } return newLength == expectedLength; }
Example 4
Source File: AntlrProposalConflictHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected boolean equalTokenSequence(TokenSource first, TokenSource second) { Token token = null; while(!(token = first.nextToken()).equals(Token.EOF_TOKEN)) { Token otherToken = second.nextToken(); if (otherToken.equals(Token.EOF_TOKEN)) { return false; } if (!token.getText().equals(otherToken.getText())) { return false; } } return true; }
Example 5
Source File: DocumentTokenSource.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.4 */ protected RepairEntryData getRepairEntryData(DocumentEvent e) throws Exception { int tokenStartsAt = 0; int tokenInfoIdx = 0; for(tokenInfoIdx = 0; tokenInfoIdx< getInternalModifyableTokenInfos().size(); ++tokenInfoIdx) { TokenInfo oldToken = getInternalModifyableTokenInfos().get(tokenInfoIdx); if(tokenStartsAt <= e.getOffset() && tokenStartsAt + oldToken.getLength() >= e.getOffset()) break; tokenStartsAt += oldToken.getLength(); } final TokenSource delegate = createTokenSource(e.fDocument.get(tokenStartsAt, e.fDocument.getLength() - tokenStartsAt)); final int offset = tokenStartsAt; TokenSource source = new TokenSource() { @Override public Token nextToken() { CommonToken commonToken = (CommonToken) delegate.nextToken(); commonToken.setText(commonToken.getText()); commonToken.setStartIndex(commonToken.getStartIndex()+offset); commonToken.setStopIndex(commonToken.getStopIndex()+offset); return commonToken; } @Override public String getSourceName() { return delegate.getSourceName(); } }; final CommonToken token = (CommonToken) source.nextToken(); return new RepairEntryData(offset, tokenInfoIdx, token, source); }
Example 6
Source File: AbstractLexerBasedConverter.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void assertTokens(T value, TokenSource tokenSource, String escapedString) { if (tokenSource == null) return; Token token = tokenSource.nextToken(); if (!escapedString.equals(token.getText())) { throw createTokenContentMismatchException(value, escapedString, token); } if (!getRuleName().toUpperCase().equals(getRuleName(token))) { throw createTokenTypeMismatchException(value, escapedString, token); } T reparsedValue = toValue(token.getText(), null); if (value != reparsedValue && !value.equals(reparsedValue)) { throw createTokenContentMismatchException(value, escapedString, token); } }
Example 7
Source File: AntlrProposalConflictHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected boolean equalTokenSequence(TokenSource first, TokenSource second) { Token token = null; while (!(token = first.nextToken()).equals(Token.EOF_TOKEN)) { Token otherToken = second.nextToken(); if (otherToken.equals(Token.EOF_TOKEN)) { return false; } if (!token.getText().equals(otherToken.getText())) { return false; } } return true; }