本文整理汇总了Java中org.antlr.runtime.TokenSource.nextToken方法的典型用法代码示例。如果您正苦于以下问题:Java TokenSource.nextToken方法的具体用法?Java TokenSource.nextToken怎么用?Java TokenSource.nextToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.runtime.TokenSource
的用法示例。
在下文中一共展示了TokenSource.nextToken方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRepairEntryData
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
/**
* @since 2.4
*/
@Override
protected RepairEntryData getRepairEntryData(DocumentEvent e) throws Exception {
int tokenStartsAt = 0;
int tokenInfoIdx = 0;
TokenSource source = createTokenSource(e.fDocument.get());
CommonToken token = (CommonToken) source.nextToken();
// find start idx
while (true) {
if (token == Token.EOF_TOKEN) {
break;
}
if (tokenInfoIdx >= getInternalModifyableTokenInfos().size())
break;
TokenInfo tokenInfo = getInternalModifyableTokenInfos().get(tokenInfoIdx);
if (tokenInfo.getAntlrTokenType() != token.getType()
|| token.getStopIndex() - token.getStartIndex() + 1 != tokenInfo.getLength())
break;
if (tokenStartsAt + tokenInfo.getLength() > e.fOffset)
break;
tokenStartsAt += tokenInfo.getLength();
tokenInfoIdx++;
token = (CommonToken) source.nextToken();
}
return new RepairEntryData(tokenStartsAt, tokenInfoIdx, token, source);
}
示例2: assertTokens
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
protected void assertTokens(String value, TokenSource tokenSource, String escapedString) {
if (tokenSource == null)
return;
Token token = tokenSource.nextToken();
if (!escapedString.equals(token.getText())) {
throw createTokenContentMismatchException(value, escapedString, token);
}
String rule1 = getRuleName().toUpperCase();
String rule2 = getRuleName(token);
// workaround:
if ("NAME".equals(rule1) && "ID".equals(rule2)) {
rule2 = "NAME";
} else if ("ID".equals(rule1) && "NAME".equals(rule2)) {
rule1 = "NAME";
}
// Ambiguity between NAME and ID rule
if (!rule1.equals(rule2)) {
throw createTokenTypeMismatchException(value, escapedString, token);
}
String reparsedValue = toValue(token.getText(), null);
if (value != reparsedValue && !value.equals(reparsedValue)) {
throw createTokenContentMismatchException(value, escapedString, token);
}
}
示例3: isSameTokenSequence
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
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;
}
示例4: assertTokens
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
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);
}
}
示例5: equalTokenSequence
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
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;
}
示例6: equalTokenSequence
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
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;
}
示例7: createTokenInfos
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
protected List<TokenInfo> createTokenInfos(String string) {
List<TokenInfo> result = Lists.newArrayListWithExpectedSize(string.length() / 3);
TokenSource source = createTokenSource(string);
CommonToken token = (CommonToken) source.nextToken();
while (token != Token.EOF_TOKEN) {
TokenInfo info = createTokenInfo(token);
result.add(info);
token = (CommonToken) source.nextToken();
}
return result;
}
示例8: getRepairEntryData
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
/**
* @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() {
public Token nextToken() {
CommonToken commonToken = (CommonToken) delegate.nextToken();
commonToken.setText(commonToken.getText());
commonToken.setStartIndex(commonToken.getStartIndex()+offset);
commonToken.setStopIndex(commonToken.getStopIndex()+offset);
return commonToken;
}
public String getSourceName() {
return delegate.getSourceName();
}
};
final CommonToken token = (CommonToken) source.nextToken();
return new RepairEntryData(offset, tokenInfoIdx, token, source);
}
示例9: printTokenStream
import org.antlr.runtime.TokenSource; //导入方法依赖的package包/类
static void printTokenStream(CommonTokenStream tokens, Map tokenToName) {
TokenSource source = tokens.getTokenSource();
Token curr;
do {
curr = source.nextToken();
System.out.println(curr.getText() + " [" + tokenToName.get(String.valueOf(curr.getType())) + "]");
} while (-1 != curr.getType() ); // eof
}