当前位置: 首页>>代码示例>>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;未经允许,请勿转载。