本文整理匯總了Java中org.antlr.v4.runtime.Token.getTokenIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java Token.getTokenIndex方法的具體用法?Java Token.getTokenIndex怎麽用?Java Token.getTokenIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.v4.runtime.Token
的用法示例。
在下文中一共展示了Token.getTokenIndex方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addNonSyntaxTokens
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
private List<SyntaxElement> addNonSyntaxTokens(List<SyntaxElement> syntaxElements, BufferedTokenStream tokens) {
StackLight<SyntaxElement> regularElements = new StackLight<SyntaxElement>(syntaxElements);
List<SyntaxElement> result = new LinkedList<SyntaxElement>();
for (Token t : tokens.getTokens()) {
if (!regularElements.empty() && regularElements.peek().tokenIndex == t.getTokenIndex())
result.add(regularElements.pop());
else {
SyntaxElementType type = getIrregularType(t);
if (type != SyntaxElementType.unknown)
result.add(SyntaxElement.create(t, type));
}
}
return result;
}
示例2: earliestAncestorWithChildStartingAtCharPos
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
/** Walk upwards from node until we find a child of p at t's char position.
* Don't see alignment with self, t, or element *after* us.
* return null if there is no such ancestor p.
*/
public static Pair<ParserRuleContext,Integer> earliestAncestorWithChildStartingAtCharPos(ParserRuleContext node, Token t, int charpos) {
ParserRuleContext p = node;
while ( p!=null ) {
// check all children of p to see if one of them starts at charpos
for (int i = 0; i<p.getChildCount(); i++) {
ParseTree child = p.getChild(i);
Token start;
if ( child instanceof ParserRuleContext ) {
start = ((ParserRuleContext) child).getStart();
}
else { // must be token
start = ((TerminalNode)child).getSymbol();
}
// check that we don't see alignment with self or element *after* us
if ( start.getTokenIndex()<t.getTokenIndex() && start.getCharPositionInLine()==charpos ) {
return new Pair<>(p,i);
}
}
p = p.getParent();
}
return null;
}
示例3: getMatchingSymbolStartsLine
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public static int getMatchingSymbolStartsLine(Corpus corpus,
InputDocument doc,
TerminalNode node)
{
TerminalNode matchingLeftNode = getMatchingLeftSymbol(corpus, doc, node);
if ( matchingLeftNode != null ) {
Token matchingLeftToken = matchingLeftNode.getSymbol();
int i = matchingLeftToken.getTokenIndex();
if ( i==0 ) return 1; // first token is considered first on line
Token tokenBeforeMatchingToken = doc.tokens.getPreviousRealToken(i);
// System.out.printf("doc=%s node=%s, pair=%s, before=%s\n",
// new File(doc.fileName).getName(), node.getSymbol(), matchingLeftToken, tokenBeforeMatchingToken);
if ( tokenBeforeMatchingToken!=null ) {
return matchingLeftToken.getLine()>tokenBeforeMatchingToken.getLine() ? 1 : 0;
}
else { // matchingLeftToken must be first in file
return 1;
}
}
return NOT_PAIR;
}
示例4: getMatchingSymbolEndsLine
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public static int getMatchingSymbolEndsLine(Corpus corpus,
InputDocument doc,
TerminalNode node)
{
TerminalNode matchingLeftNode = getMatchingLeftSymbol(corpus, doc, node);
if ( matchingLeftNode != null ) {
Token matchingLeftToken = matchingLeftNode.getSymbol();
int i = matchingLeftToken.getTokenIndex();
Token tokenAfterMatchingToken = doc.tokens.getNextRealToken(i);
// System.out.printf("doc=%s node=%s, pair=%s, after=%s\n",
// new File(doc.fileName).getName(), node.getSymbol(), matchingLeftToken, tokenAfterMatchingToken);
if ( tokenAfterMatchingToken!=null ) {
if ( tokenAfterMatchingToken.getType()==Token.EOF ) {
return 1;
}
return tokenAfterMatchingToken.getLine()>matchingLeftToken.getLine() ? 1 : 0;
}
}
return NOT_PAIR;
}
示例5: wipeCharPositionInfoAndWhitespaceTokens
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public static void wipeCharPositionInfoAndWhitespaceTokens(CodeBuffTokenStream tokens) {
tokens.fill();
CommonToken dummy = new CommonToken(Token.INVALID_TYPE, "");
dummy.setChannel(Token.HIDDEN_CHANNEL);
Token firstRealToken = tokens.getNextRealToken(-1);
for (int i = 0; i<tokens.size(); i++) {
if ( i==firstRealToken.getTokenIndex() ) continue; // don't wack first token
CommonToken t = (CommonToken)tokens.get(i);
if ( t.getText().matches("\\s+") ) {
tokens.getTokens().set(i, dummy); // wack whitespace token so we can't use it during prediction
}
else {
t.setLine(0);
t.setCharPositionInLine(-1);
}
}
}
示例6: exitDeclaration
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public void exitDeclaration(ObjCParser.DeclarationContext ctx) {
String decl = getCode(ctx.declaration_minus_semi()) + ";\n";
//獲取注釋
Token prior = ctx.getStart();
int indx = prior.getTokenIndex();
List<Token> cmtChannel = tokens.getHiddenTokensToLeft(indx,
ObjCLexer.COMMENT_CHANNEL);
if (cmtChannel != null) {
String txt = "";
for (Token cmt : cmtChannel) {
if (cmt != null) {
txt = txt + cmt.getText() + "\n";
}
}
setComment(ctx, txt);
}
if (getComment(ctx) != null) {
decl = getComment(ctx) + decl;
}
setCode(ctx, decl);
}
示例7: exitInstance_method_definition
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public void exitInstance_method_definition(
ObjCParser.Instance_method_definitionContext ctx) {
String code = ctx.getText();
String.format("s", code);
String call = getCode(ctx.method_definition());
String mDef = call;
//獲取注釋
Token prior = ctx.getStart();
int indx = prior.getTokenIndex();
List<Token> cmtChannel = tokens.getHiddenTokensToLeft(indx,
ObjCLexer.COMMENT_CHANNEL);
if (cmtChannel != null) {
String txt = "";
for (Token cmt : cmtChannel) {
if (cmt != null) {
txt = txt + cmt.getText() + "\n";
}
}
setComment(ctx, txt);
}
if (getComment(ctx) != null) {
mDef = getComment(ctx) + mDef;
}
setCode(ctx, mDef);
}
示例8: exitExpression
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public void exitExpression(ObjCParser.ExpressionContext ctx) {
String message = ctx.getText();
String.format("%s", message);
String exp = getCode(ctx.assignment_expression().get(0));
for (int i = 1; i < ctx.assignment_expression().size(); i++) {
exp += ", " + getCode(ctx.assignment_expression().get(i));
}
//獲取注釋
Token prior = ctx.getStart();
int indx = prior.getTokenIndex();
List<Token> cmtChannel = tokens.getHiddenTokensToLeft(indx,
ObjCLexer.COMMENT_CHANNEL);
if (cmtChannel != null) {
String txt = "";
for (Token cmt : cmtChannel) {
if (cmt != null) {
txt = txt + cmt.getText() + "\n";
}
}
setComment(ctx, txt);
}
if (getComment(ctx) != null) {
exp = getComment(ctx) + exp;
}
if (message == "[") {
setCode(ctx, "[");
} else if (message == "]") {
setCode(ctx, "]");
} else {
setCode(ctx, exp);
}
}
示例9: create
import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public static SyntaxElement create(Token t, SyntaxElementType type) {
return new SyntaxElement(t.getText(), t.getStartIndex(), t.getStopIndex(), t.getTokenIndex(), type);
}