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


Java InputMismatchException类代码示例

本文整理汇总了Java中org.antlr.v4.runtime.InputMismatchException的典型用法代码示例。如果您正苦于以下问题:Java InputMismatchException类的具体用法?Java InputMismatchException怎么用?Java InputMismatchException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InputMismatchException类属于org.antlr.v4.runtime包,在下文中一共展示了InputMismatchException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recover

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的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: recoverInline

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
/**
 * Make sure we don't attempt to recover inline; if the parser successfully
 * recovers, it won't throw an exception.
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    InputMismatchException e = new InputMismatchException(recognizer);

    String policies = recognizer.getInputStream().getText();
    StringTokenizer tk = new StringTokenizer(policies, ";");
    String policy = "";
    int idx = 0;
    while (tk.hasMoreElements()) {
        policy = (String) tk.nextElement();
        idx += policy.length();
        if (idx >= e.getOffendingToken().getStartIndex()) {
            break;
        }
    }

    String message = Messages.get(Messages.DEFAULT_LOCALE,
            "error_invalid_firewallconfig", new Object[] {
                    e.getOffendingToken().getText(), policy });
    throw new RuntimeException(message);
}
 
开发者ID:servicecatalog,项目名称:oscm-app,代码行数:26,代码来源:FWPolicyErrorStrategy.java

示例3: formatMessage

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
@Override
public String formatMessage(SyntaxError error) {
    RecognitionException exception = error.getException();
    if (exception instanceof InputMismatchException) {
        InputMismatchException mismatchException = (InputMismatchException) exception;
        RuleContext ctx = mismatchException.getCtx();
        int ruleIndex = ctx.getRuleIndex();
        switch (ruleIndex) {
            case ProtoParser.RULE_ident:
                return ProtostuffBundle.message("error.expected.identifier");
            default:
                break;
        }
    }
    return super.formatMessage(error);
}
 
开发者ID:protostuff,项目名称:protobuf-jetbrains-plugin,代码行数:17,代码来源:ProtoParserDefinition.java

示例4: reportError

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
public void reportError(Parser recognizer, RecognitionException e) {
  if (!this.inErrorRecoveryMode(recognizer)) {
    this.beginErrorCondition(recognizer);
    if (e instanceof NoViableAltException) {
      this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
    } else if (e instanceof InputMismatchException) {
      this.reportInputMismatch(recognizer, (InputMismatchException) e);
    } else if (e instanceof FailedPredicateException) {
      this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
    } else {
      System.err.println("unknown recognition error type: " + e.getClass().getName());
      recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
    }

  }
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:17,代码来源:KsqlParserErrorStrategy.java

示例5: recover

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
@Override
public void recover(Parser recognizer, RecognitionException e) {
    for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
        context.exception = e;
    }

    if (PredictionMode.LL.equals(recognizer.getInterpreter().getPredictionMode())) {
        if (e instanceof NoViableAltException) {
            this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
        } else if (e instanceof InputMismatchException) {
            this.reportInputMismatch(recognizer, (InputMismatchException) e);
        } else if (e instanceof FailedPredicateException) {
            this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
        }
    }

    throw new ParseCancellationException(e);
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:DescriptiveErrorStrategy.java

示例6: syntaxError

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
    if (e instanceof InputMismatchException || e instanceof NoViableAltException) {
        String symbol = (offendingSymbol instanceof Token) ?
                ((Token) offendingSymbol).getText() : 
                String.valueOf(offendingSymbol);
        errors.add(String.format(
                "Unexpected input \'%s\' at %d:%d. Valid symbols are: %s",
                symbol,
                line,
                charPositionInLine,
                e.getExpectedTokens().toString(recognizer.getVocabulary())
        ));
    } else {
        errors.add(String.format("Parse error: \'%s\' near \'%s\' at %d:%d", msg, String.valueOf(offendingSymbol), line, charPositionInLine));
    }
}
 
开发者ID:meridor,项目名称:perspective-backend,代码行数:18,代码来源:QueryParserImpl.java

示例7: compile

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
public Walk compile( CharStream input, ErrorHandler errors ) {
     try  {
         return compile( input );
     } catch (ParseCancellationException ex) {
int line = ErrorHandler.UNKNOWN;
int column = ErrorHandler.UNKNOWN;
String msg = "Parser Cancelled.";
Throwable cause = ex.getCause();
if( cause instanceof InputMismatchException ) {
	InputMismatchException immEx = (InputMismatchException) cause;
	Token offender = immEx.getOffendingToken();
	if( offender != null ) {
		line = offender.getLine();
		column = offender.getCharPositionInLine();
		String txt = offender.getText();
		if(txt != null) {
			msg = " Unexpected Token '" + txt + "'.";
		}
	}
}
         errors.parseError( line, column, msg );
     }		
     return getProgram();
 }
 
开发者ID:vZome,项目名称:vzome-core,代码行数:25,代码来源:ZomicASTCompiler.java

示例8: generate

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
Axis generate() {
			try {
				Axis axis = namingConvention.getAxis(axisColor, indexFullName() );
				// This check has been moved into a thorough unit test instead of a runtime check.
				// but I'll leave the code commented out here in case additional colors are eventually supported and need debugging
//				String check = namingConvention.getName( axis );
//				if ( axis != namingConvention.getAxis(axisColor, check ) ) {
//					log( axisColor + " " + indexFullName() + " mapped to " + check );
//				}
				if(axis == null) {
					InputMismatchException imex = new InputMismatchException(parser);
					logger.log(Level.WARNING, imex.getMessage(), imex);
					throw imex;
				}
				return axis;
			//} catch( ArrayIndexOutOfBoundsException ex ){
			//} catch( NullPointerException  ex ) {
			} catch( RuntimeException ex) {
				String msg = "bad axis specification: '" + axisColor + " " + indexFullName() + "'";
				logger.warning(msg);
				throw new RuntimeException( msg, ex);
			} 
		}
 
开发者ID:vZome,项目名称:vzome-core,代码行数:24,代码来源:ZomicASTCompiler.java

示例9: recoverInline

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
/** Make sure we don't attempt to recover inline; if the parser
	* successfully recovers, it won't throw an exception.
	*/
	@Override
	public Token recoverInline(Parser recognizer) throws RecognitionException
	{
		// SINGLE TOKEN DELETION
		Token matchedSymbol = singleTokenDeletion(recognizer);
		if (matchedSymbol != null)
		{
			// we have deleted the extra token.
			// now, move past ttype token as if all were ok
			recognizer.consume();
			return matchedSymbol;
		}

		// SINGLE TOKEN INSERTION
		if (singleTokenInsertion(recognizer))
		{
			return getMissingSymbol(recognizer);
		}
		
//		BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR);
//		exception.pushToken(this.getGrammarToken(recognizer.getCurrentToken()));
//		throw exception;
		throw new InputMismatchException(recognizer);
	}
 
开发者ID:javamonkey,项目名称:beetl2.0,代码行数:28,代码来源:BeetlAntlrErrorStrategy.java

示例10: reportInputMismatch

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的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

示例11: exceptionString

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
public static String exceptionString(Parser parser, RecognitionException ex) {
    if (ex instanceof FailedPredicateException) {
        return failedPredicate((FailedPredicateException) ex);
    } else if (ex instanceof InputMismatchException) {
        return inputMismatch((InputMismatchException) ex);
    } else if (ex instanceof NoViableAltException) {
        return noViableAlt(parser, (NoViableAltException) ex);
    } else {
        System.err.println("unknown recognition exception:" + ex);
        return ex.toString();
    }
}
 
开发者ID:kasonyang,项目名称:kalang,代码行数:13,代码来源:AntlrErrorString.java

示例12: recoverInline

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的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;
		}
 
开发者ID:antlr,项目名称:codebuff,代码行数:13,代码来源:GrammarParserInterpreter.java

示例13: recoverInline

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
@Override
public Token recoverInline(Parser recognizer)
        throws RecognitionException {

    this.recover(recognizer, new InputMismatchException(recognizer)); // stop parsing
    return null;
}
 
开发者ID:apache,项目名称:groovy,代码行数:8,代码来源:DescriptiveErrorStrategy.java

示例14: syntaxError

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p/>
 * The method is overridden to throw an exception if the parsed input has an invalid syntax.
 */
@Override
public void syntaxError(Recognizer<?, ?> recognizer, @Nullable Object offendingSymbol, int line,
        int charPositionInLine, String msg, @Nullable RecognitionException e) {

    String errorMessage = msg;
    if (e instanceof InputMismatchException && msg.endsWith(" expecting VALUE")) {
        errorMessage += ". Please make sure that all values are surrounded by double quotes.";
    }

    throw new IllegalArgumentException(errorMessage);
}
 
开发者ID:osiam,项目名称:resource-server,代码行数:17,代码来源:OsiamAntlrErrorListener.java

示例15: reportInputMismatch

import org.antlr.v4.runtime.InputMismatchException; //导入依赖的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


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