当前位置: 首页>>代码示例>>Java>>正文


Java Token.getTokenIndex方法代码示例

本文整理汇总了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;
	}
 
开发者ID:curiosag,项目名称:ftc,代码行数:19,代码来源:QueryHandler.java

示例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;
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:27,代码来源:Trainer.java

示例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;
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:22,代码来源:Trainer.java

示例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;
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:21,代码来源:Trainer.java

示例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);
		}
	}
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:18,代码来源:Formatter.java

示例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);
}
 
开发者ID:Consoar,项目名称:Objc2Lua,代码行数:25,代码来源:ParserObjcListener.java

示例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);
}
 
开发者ID:Consoar,项目名称:Objc2Lua,代码行数:29,代码来源:ParserObjcListener.java

示例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);
    }
}
 
开发者ID:Consoar,项目名称:Objc2Lua,代码行数:36,代码来源:ParserObjcListener.java

示例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);
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:4,代码来源:SyntaxElement.java


注:本文中的org.antlr.v4.runtime.Token.getTokenIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。