當前位置: 首頁>>代碼示例>>Java>>正文


Java Token.getStartIndex方法代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.Token.getStartIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java Token.getStartIndex方法的具體用法?Java Token.getStartIndex怎麽用?Java Token.getStartIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.antlr.v4.runtime.Token的用法示例。


在下文中一共展示了Token.getStartIndex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: recover

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public void recover(final Parser recognizer, final RecognitionException re) {
    final Token token = re.getOffendingToken();
    String message;

    if (token == null) {
        message = "no parse token found.";
    } else if (re instanceof InputMismatchException) {
        message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
                " was expecting one of [" + re.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
    } else if (re instanceof NoViableAltException) {
        if (token.getType() == PainlessParser.EOF) {
            message = "unexpected end of script.";
        } else {
            message = "invalid sequence of tokens near [" + getTokenErrorDisplay(token) + "].";
        }
    } else {
        message =  "unexpected token near [" + getTokenErrorDisplay(token) + "].";
    }

    Location location = new Location(sourceName, token == null ? -1 : token.getStartIndex());
    throw location.createError(new IllegalArgumentException(message, re));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:ParserErrorStrategy.java

示例2: getAnchor

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
protected int getAnchor(String content) {
	List<Token> tokens = codeAssist.getGrammar().lex(content);
	if (tokens.isEmpty()) {
		return 0;
	} else {
		Token lastToken = tokens.get(tokens.size()-1);
		String contentAfterLastToken = content.substring(lastToken.getStopIndex()+1);
		if (contentAfterLastToken.length() > 0) {
			contentAfterLastToken = StringUtils.trimStart(contentAfterLastToken);
			return content.length() - contentAfterLastToken.length();
		} else {
			return lastToken.getStartIndex();
		}
	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:17,代碼來源:ANTLRAssistBehavior.java

示例3: containsOffset

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
/**
 * @requires token != null
 * @return true iff token contains offset or offset is at the start of token
 *         and forwardBias is true.
 */
private static boolean containsOffset(
        Token token,
        int offset,
        boolean forwardBias) {

    int startIndex;
    int stopIndex;

    if (forwardBias) {
        startIndex = token.getStartIndex();
        stopIndex = token.getStopIndex();
    } else {
        startIndex = token.getStartIndex() + 1;
        stopIndex = token.getStopIndex() + 1;
    }

    return startIndex <= offset && offset <= stopIndex;
}
 
開發者ID:mwillema,項目名稱:protobuf-netbeans-plugin,代碼行數:24,代碼來源:AntlrDocument.java

示例4: underlineError

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
protected static String underlineError(CoqFTParser parser,
		Token offendingToken, int line, int charPositionInLine) {
	StringBuilder sb = new StringBuilder();
	
	CommonTokenStream tokens = (CommonTokenStream)parser.getInputStream();
	String input = tokens.getTokenSource().getInputStream().toString();
	String[] lines = input.split("\n");
	String errorLine = lines[line - 1];
	
	sb.append(errorLine).append('\n');
	
	for (int i=0; i<charPositionInLine; i++) sb.append(" ");
	int start = offendingToken.getStartIndex();
	int stop = offendingToken.getStopIndex();
	if ( start>=0 && stop>=0 ) {
		for (int i=start; i<=stop; i++) sb.append("^");
	}
	return sb.toString();
}
 
開發者ID:jhuapl-saralab,項目名稱:exterminator,代碼行數:20,代碼來源:CoqSyntaxException.java

示例5: getBytes

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
private static byte[] getBytes(Literal_value_binaryContext rule) {
    Token token = rule.STRING_LITERAL().getSymbol();
    byte[] bytes = new byte[token.getStopIndex() - token.getStartIndex() - 1];
    CharStream cs = token.getInputStream();
    int pos = cs.index();
    cs.seek(token.getStartIndex() + 1);
    int j = 0;
    for (int i = 0; i < bytes.length; i++) {
        int ch = cs.LA(i + 1);
        if (ch == '\\') {
            i++;
            ch = cs.LA(i + 1);
            if (ch == '0') {
                ch = 0;
            }
            else if (ch == 'n') {
                ch = '\n';
            }
            else if (ch == 'r') {
                ch = '\r';
            }
            else if (ch == 'Z') {
                ch = '\032';
            }
        }
        bytes[j] = (byte) ch;
        j++;
    }
    cs.seek(pos);
    if (j != bytes.length) {
        // esacpe characters
        byte[] old = bytes;
        bytes = new byte[j];
        System.arraycopy(old, 0, bytes, 0, j);
    }
    return bytes;
}
 
開發者ID:waterguo,項目名稱:antsdb,代碼行數:38,代碼來源:ExprGenerator.java

示例6: recoverInline

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public Token recoverInline(final Parser recognizer) throws RecognitionException {
    final Token token = recognizer.getCurrentToken();
    final String message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
        " was expecting one of [" + recognizer.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";

    Location location = new Location(sourceName, token.getStartIndex());
    throw location.createError(new IllegalArgumentException(message));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:ParserErrorStrategy.java

示例7: AntlrError

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public AntlrError(Token tokenError, int line, int charPositionInLine, String msg) {
    this.line = line;
    this.charPositionInLine = charPositionInLine;
    this.msg = msg;
    this.start = tokenError == null ? -1 : tokenError.getStartIndex();
    this.stop = tokenError == null ? -1 : tokenError.getStopIndex();
    this.text = tokenError == null ? null : tokenError.getText();
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:9,代碼來源:AntlrError.java

示例8: Location

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public Location(ParserRuleContext parserRuleContext) {
  Token start = parserRuleContext.getStart();
  this.start = start.getStartIndex();
  Token stop = parserRuleContext.getStop();
  end = stop.getStopIndex();
  line = start.getLine();
}
 
開發者ID:rockscript,項目名稱:rockscript,代碼行數:8,代碼來源:Location.java

示例9: containsBlockCommentOpeningSymbol

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
/**
 * @requires token != null && token.type = BLOCK_COMMENT
 * @return true iff token contains another block comment opening symbol '/*'
 */
private boolean containsBlockCommentOpeningSymbol(Token token) {
    int startOffset = token.getStartIndex() + 2;
    int stopOffset = token.getStopIndex() - 1;

    if (startOffset > stopOffset) {
        return false;
    }

    return text()
            .substring(startOffset, stopOffset)
            .contains(BLOCK_COMMENT_OPENING_SYMBOL);
}
 
開發者ID:mwillema,項目名稱:protobuf-netbeans-plugin,代碼行數:17,代碼來源:ProtobufDocument.java

示例10: isInString

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public final boolean isInString(int offset) {
    Token rhsToken = tokenAt(offset, FORWARD_BIAS);

    if (isString(rhsToken)) {
        return offset != rhsToken.getStartIndex();
    }

    if (offset <= 0) {
        return false;
    }

    Token lhsToken = tokenAt(offset, BACKWARD_BIAS);
    return isUnclosedString(lhsToken);
}
 
開發者ID:mwillema,項目名稱:protobuf-netbeans-plugin,代碼行數:16,代碼來源:AntlrDocument.java

示例11: isInComment

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
@Override
public final boolean isInComment(int offset) {
    Token rhsToken = tokenAt(offset, FORWARD_BIAS);

    if (isComment(rhsToken)) {
        return offset != rhsToken.getStartIndex();
    }

    if (offset <= 0) {
        return false;
    }

    Token lhsToken = tokenAt(offset, BACKWARD_BIAS);
    return isLineComment(lhsToken);
}
 
開發者ID:mwillema,項目名稱:protobuf-netbeans-plugin,代碼行數:16,代碼來源:AntlrDocument.java

示例12: getOffsetRange

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public static OffsetRange getOffsetRange(Token start, Token stop) {
    OffsetRange offset = new OffsetRange();
    offset.startOffset = start.getStartIndex();
    offset.stopOffset = stop.getStopIndex();
    offset.startLine = start.getLine();
    offset.startLineColumn = start.getCharPositionInLine();
    offset.stopLine = stop.getLine();
    offset.stopLineColumn = stop.getCharPositionInLine();
    return offset;
}
 
開發者ID:kasonyang,項目名稱:kalang,代碼行數:11,代碼來源:OffsetRangeHelper.java

示例13: setTotalBoundaries

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
private void setTotalBoundaries(Token token) {
	if (state.in(NameRecognitionState.NAME1, NameRecognitionState.QUALIFIER, NameRecognitionState.NAME2)) {
		if (totalLo < 0)
			totalLo = token.getStartIndex();
		if (totalHi < token.getStopIndex())
			totalHi = token.getStopIndex();
	}
}
 
開發者ID:curiosag,項目名稱:ftc,代碼行數:9,代碼來源:NameRecognition.java

示例14: underlineError

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
protected <T extends Token> void underlineError(
		Recognizer<T, ?> recognizer, Token offendingToken, int line,
		int charPositionInLine) {
	
	CommonTokenStream tokens = (CommonTokenStream) recognizer
			.getInputStream();
	
	String input = tokens.getTokenSource().getInputStream().toString();
	
	String[] lines = input.split("\n");
	
	String errorLine = lines[line - 1];
	
	System.out.println(errorLine);
	
	for (int i = 0; i < charPositionInLine; i++)
		System.out.print(" ");
	
	int start = offendingToken.getStartIndex();
	int stop = offendingToken.getStopIndex();
	
	if (start >= 0 && stop >= 0) {
		for (int i = start; i <= stop; i++)
			System.out.print("^");
	}
	System.out.println();
}
 
開發者ID:ShapeChange,項目名稱:ShapeChange,代碼行數:28,代碼來源:SbvrErrorListener.java

示例15: setMetadataFromContext

import org.antlr.v4.runtime.Token; //導入方法依賴的package包/類
public void setMetadataFromContext(ParserRuleContext ctx) {

		Token start = ctx.start;
		Token stop = ctx.stop;

		this.offendingTextStartIndex = start.getStartIndex();
		this.offendingTextStopIndex = stop.getStopIndex();
	}
 
開發者ID:ShapeChange,項目名稱:ShapeChange,代碼行數:9,代碼來源:SbvrErrorInfo.java


注:本文中的org.antlr.v4.runtime.Token.getStartIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。