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


Java Parser.getInputStream方法代碼示例

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


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

示例1: reportNoViableAlternative

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
@Override
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
	// change error message from default implementation
	TokenStream tokens = recognizer.getInputStream();
	String input;
	if (tokens != null) {
		if (e.getStartToken().getType() == Token.EOF) {
			input = "the end";
		} else {
			input = escapeWSAndQuote(tokens.getText(e.getStartToken(), e.getOffendingToken()));
		}
	} else {
		input = escapeWSAndQuote("<unknown input>");
	}
	String msg = "inadmissible input at " + input;
	recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:18,代碼來源:CapitulatingErrorStrategy.java

示例2: reportNoViableAlternative

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
  TokenStream tokens = recognizer.getInputStream();
  String input;
  if (tokens != null) {
    if (e.getStartToken().getType() == -1) {
      input = "<EOF>";
    } else {
      input = tokens.getText(e.getStartToken(), e.getOffendingToken());
    }
  } else {
    input = "<unknown input>";
  }

  String msg = "no viable alternative at input " + this.escapeWSAndQuote(input);
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
開發者ID:confluentinc,項目名稱:ksql,代碼行數:17,代碼來源:KsqlParserErrorStrategy.java

示例3: reportNoViableAlternative

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e)
{
    TokenStream tokens = recognizer.getInputStream();
    String input;
    if (tokens instanceof TokenStream)
    {
        if (e.getStartToken().getType() == Token.EOF)
            input = "<EOF>";
        else
            input = getText(tokens, e.getStartToken(), e.getOffendingToken());
    }
    else
    {
        input = "<unknown input>";
    }
    String msg = "no viable alternative at input " + escapeWSAndQuote(input);
    recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
 
開發者ID:HuaweiBigData,項目名稱:StreamCQL,代碼行數:23,代碼來源:CQLErrorStrategy.java

示例4: reportInputMismatch

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
@Override
public void reportInputMismatch(Parser recognizer, InputMismatchException e) throws RecognitionException {
	String msg = "mismatched input " + getTokenErrorDisplay(e.getOffendingToken());
	msg += " expecting one of " + e.getExpectedTokens().toString(recognizer.getTokenNames());
	RecognitionException ex = new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
	ex.initCause(e);
	throw ex;
}
 
開發者ID:paypal,項目名稱:digraph-parser,代碼行數:9,代碼來源:GraphParser.java

示例5: reportMissingToken

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
@Override
public void reportMissingToken(Parser recognizer) {
	beginErrorCondition(recognizer);
	Token t = recognizer.getCurrentToken();
	IntervalSet expecting = getExpectedTokens(recognizer);
	String msg = "missing " + expecting.toString(recognizer.getTokenNames()) + " at " + getTokenErrorDisplay(t);
	throw new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
}
 
開發者ID:paypal,項目名稱:digraph-parser,代碼行數:9,代碼來源:GraphParser.java

示例6: noViableAlt

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
public static String noViableAlt(Parser recognizer, NoViableAltException e) {
    TokenStream tokens = recognizer.getInputStream();
    String input = null;
    if (tokens != null) {
        Token startToken = e.getStartToken();
        if (startToken.getType() == Token.EOF) {
            input = "<EOF>";
        } else {
            input = tokens.getText(
                    startToken, e.getOffendingToken()
            );
        }
    }
    return "syntax error at input:" + input;
}
 
開發者ID:kasonyang,項目名稱:kalang,代碼行數:16,代碼來源:AntlrErrorString.java

示例7: recover

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
@Override
		public void recover(Parser recognizer, RecognitionException e) {
			int errIndex = recognizer.getInputStream().index();
			if ( firstErrorTokenIndex == -1 ) {
				firstErrorTokenIndex = errIndex; // latch
			}
//			System.err.println("recover: error at " + errIndex);
			TokenStream input = recognizer.getInputStream();
			if ( input.index()<input.size()-1 ) { // don't consume() eof
				recognizer.consume(); // just kill this bad token and let it continue.
			}
		}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:13,代碼來源:GrammarParserInterpreter.java

示例8: createNoViableAlternativeErrorMessage

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
protected String createNoViableAlternativeErrorMessage(Parser recognizer, NoViableAltException e) {
    TokenStream tokens = recognizer.getInputStream();
    String input;
    if (tokens != null) {
        if (e.getStartToken().getType() == Token.EOF) {
            input = "<EOF>";
        } else {
            input = charStream.getText(Interval.of(e.getStartToken().getStartIndex(), e.getOffendingToken().getStopIndex()));
        }
    } else {
        input = "<unknown input>";
    }

    return "Unexpected input: " + escapeWSAndQuote(input);
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:16,代碼來源:DescriptiveErrorStrategy.java

示例9: reportInputMismatch

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
@Override
public void reportInputMismatch(Parser recognizer, InputMismatchException e) throws RecognitionException {
    String msg = "";
    msg += "In file " + recognizer.getSourceName() + " at line " + recognizer.getContext().start.getLine() + ": ";
    msg += "Mismatched input " + getTokenErrorDisplay(e.getOffendingToken());
    msg += " expecting one of "+e.getExpectedTokens().toString(recognizer.getTokenNames()) + "\n";
    msg += "Line Number " + recognizer.getContext().start.getLine() + ", Column " + recognizer.getContext().start.getCharPositionInLine() + ";";
    RecognitionException ex = new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
    ex.initCause(e);
    throw ex;
}
 
開發者ID:FIWARE-Middleware,項目名稱:KIARA,代碼行數:12,代碼來源:ParserExceptionErrorStrategyImpl.java

示例10: reportMissingToken

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
@Override
public void reportMissingToken(Parser recognizer) {
    beginErrorCondition(recognizer);
    Token t = recognizer.getCurrentToken();
    IntervalSet expecting = getExpectedTokens(recognizer);
    String msg = "";
    msg += "In file " + recognizer.getSourceName() + " at line " + recognizer.getContext().start.getLine() + ": ";
    msg += "Missing "+expecting.toString(recognizer.getTokenNames()) + " at " + getTokenErrorDisplay(t) + ";";
    //msg += "Line Number " + recognizer.getContext().start.getLine() + ", Column " + recognizer.getContext().start.getCharPositionInLine() + ";";
    throw new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
}
 
開發者ID:FIWARE-Middleware,項目名稱:KIARA,代碼行數:12,代碼來源:ParserExceptionErrorStrategyImpl.java

示例11: setProfilerData

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
public void setProfilerData(PreviewState previewState, long parseTime_ns) {
	this.previewState = previewState;
	Parser parser = previewState.parsingResult.parser;
	ParseInfo parseInfo = parser.getParseInfo();
	updateTableModelPerExpertCheckBox(parseInfo);
	long parseTimeMS = (long) (parseTime_ns/(1000.0*1000.0));
	parseTimeField.setText(String.valueOf(parseTimeMS));
	int predTimeMS = (int) (parseInfo.getTotalTimeInPrediction()/(1000.0*1000.0));
	predictionTimeField.setText(
		String.format("%d = %3.2f%%", predTimeMS, 100*((double) predTimeMS)/parseTimeMS)
	                           );
	TokenStream tokens = parser.getInputStream();
	int numTokens = tokens.size();
	Token lastToken = tokens.get(numTokens-1);
	int numChar = lastToken.getStopIndex();
	int numLines = lastToken.getLine();
	if ( lastToken.getType()==Token.EOF ) {
		if ( numTokens<=1 ) {
			numLines = 0;
		}
		else {
			Token secondToLastToken = tokens.get(numTokens-2);
			numLines = secondToLastToken.getLine();
		}
	}
	inputSizeField.setText(String.format("%d char, %d lines",
	                                     numChar,
	                                     numLines));
	numTokensField.setText(String.valueOf(numTokens));
	double look =
		parseInfo.getTotalSLLLookaheadOps()+
			parseInfo.getTotalLLLookaheadOps();
	lookaheadBurdenField.setText(
		String.format("%d/%d = %3.2f", (long) look, numTokens, look/numTokens)
	                            );
	double atnLook = parseInfo.getTotalATNLookaheadOps();
	cacheMissRateField.setText(
		String.format("%d/%d = %3.2f%%", (long) atnLook, (long) look, atnLook*100.0/look)
	                          );
}
 
開發者ID:antlr,項目名稱:intellij-plugin-v4,代碼行數:41,代碼來源:ProfilerPanel.java

示例12: recoverInline

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
@Override
		public Token recoverInline(Parser recognizer) throws RecognitionException {
			int errIndex = recognizer.getInputStream().index();
			if ( firstErrorTokenIndex == -1 ) {
				firstErrorTokenIndex = errIndex; // latch
			}
//			System.err.println("recoverInline: error at " + errIndex);
			InputMismatchException e = new InputMismatchException(recognizer);
			TokenStream input = recognizer.getInputStream(); // seek EOF
			input.seek(input.size() - 1);
			throw e; // throw after seek so exception has bad token
		}
 
開發者ID:antlr,項目名稱:intellij-plugin-v4,代碼行數:13,代碼來源:ParsingUtils.java

示例13: reportNoViableAlternative

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e)
{
	TokenStream tokens = recognizer.getInputStream();
	String input;
	if (tokens instanceof TokenStream)
	{
		if (e.getStartToken().getType() == Token.EOF)
			input = "<文件尾>";
		else
			input = tokens.getText(e.getStartToken(), e.getOffendingToken());
	}
	else
	{
		input = "<未知輸入>";
	}
	BeetlException exception = null;
	if(keys.contains(e.getOffendingToken().getText())){
		 exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR,
					"不允許"+e.getOffendingToken().getText()+"關鍵出現在這裏"+":"+escapeWSAndQuote(input), e);
	}else{
		exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR,
				escapeWSAndQuote(input), e);
	}
	//		String msg = "no viable alternative at input " + escapeWSAndQuote(input);

	exception.pushToken(this.getGrammarToken(e.getOffendingToken()));

	throw exception;
}
 
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:30,代碼來源:BeetlAntlrErrorStrategy.java

示例14: sync

import org.antlr.v4.runtime.Parser; //導入方法依賴的package包/類
/**
     * Make sure we don't attempt to recover from problems in subrules.
     *
     * @param recognizer
     */
    @Override
    public void sync(Parser recognizer) {
        ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
//		System.err.println("sync @ "+s.stateNumber+"="+s.getClass().getSimpleName());
        // If already recovering, don't try to sync
        if (inErrorRecoveryMode(recognizer)) {
            return;
        }

        TokenStream tokens = recognizer.getInputStream();
        int la = tokens.LA(1);

        // try cheaper subset first; might get lucky. seems to shave a wee bit off
        if (recognizer.getATN().nextTokens(s).contains(la) || la == Token.EOF)
            return;

        // Return but don't end recovery. only do that upon valid token match
        if (recognizer.isExpectedToken(la)) {
            return;
        }

        switch (s.getStateType()) {
            /*case ATNState.BLOCK_START:
            case ATNState.STAR_BLOCK_START:
            case ATNState.PLUS_BLOCK_START:
            case ATNState.STAR_LOOP_ENTRY:
                // report error and recover if possible
                if (singleTokenDeletion(recognizer) != null) {
                    return;
                }

                //throw new InputMismatchException(recognizer);

*/
            case ATNState.PLUS_LOOP_BACK:
            case ATNState.STAR_LOOP_BACK:
//			System.err.println("at loop back: "+s.getClass().getSimpleName());
                reportUnwantedToken(recognizer);
                /*IntervalSet expecting = recognizer.getExpectedTokens();
                IntervalSet whatFollowsLoopIterationOrRule
                        = expecting.or(getErrorRecoverySet(recognizer));
                consumeUntil(recognizer, whatFollowsLoopIterationOrRule);*/
                break;

            default:
                // do nothing if we can't identify the exact kind of ATN state
                break;
        }
    }
 
開發者ID:bengtmartensson,項目名稱:IrpTransmogrifier,代碼行數:55,代碼來源:ErrorStrategy.java


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