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


Java NoViableAltException类代码示例

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


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

示例1: reportNoViableAlternative

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

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

示例3: reportError

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

示例4: reportNoViableAlternative

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

示例5: reportNoViableAlternative

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

示例6: recover

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

示例7: dumpDeadEndConfigs

import org.antlr.v4.runtime.NoViableAltException; //导入依赖的package包/类
/** Used for debugging in adaptivePredict around execATN but I cut
 *  it out for clarity now that alg. works well. We can leave this
 *  "dead" code for a bit.
 */
public void dumpDeadEndConfigs(@NotNull NoViableAltException nvae) {
	System.err.println("dead end configs: ");
	for (ATNConfig c : nvae.getDeadEndConfigs()) {
		String trans = "no edges";
		if ( c.state.getNumberOfTransitions()>0 ) {
			Transition t = c.state.transition(0);
			if ( t instanceof AtomTransition) {
				AtomTransition at = (AtomTransition)t;
				trans = "Atom "+getTokenName(at.label);
			}
			else if ( t instanceof SetTransition ) {
				SetTransition st = (SetTransition)t;
				boolean not = st instanceof NotSetTransition;
				trans = (not?"~":"")+"Set "+st.set.toString();
			}
		}
		System.err.println(c.toString(parser, true)+":"+trans);
	}
}
 
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:24,代码来源:ParserATNSimulator.java

示例8: syntaxError

import org.antlr.v4.runtime.NoViableAltException; //导入依赖的package包/类
public void syntaxError(Recognizer<?, ?> aRecognizer,
		Object aOffendingSymbol, int aLine, int aCharIndex,
		String aMessage, RecognitionException aException) {
	ANTLRErrorStrategy errorHandler = myParser.getErrorHandler();

	if (LOGGER.isWarnEnabled()) {
		LOGGER.warn(aMessage + " [" + aLine + ":" + aCharIndex + "]");
	}

	/*
	 * Setting the lexer exception in the parser since I don't see a
	 * getNumberOfSyntaxErrors() method in the lexer (like in antlr3) and
	 * the lexer's errors aren't being reported by parser's method
	 * 
	 * I may just be missing the correct way this should be handled(?)
	 */
	if (aException instanceof LexerNoViableAltException) {
		NoViableAltException exception = new NoViableAltException(myParser);
		errorHandler.reportError(myParser, exception);
	}
	else {
		errorHandler.reportError(myParser, aException);
	}
}
 
开发者ID:ksclarke,项目名称:freelib-edtf,代码行数:25,代码来源:ParserErrorListener.java

示例9: noViableAlt

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

示例10: exceptionString

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

示例11: specparam_assignment

import org.antlr.v4.runtime.NoViableAltException; //导入依赖的package包/类
public final Specparam_assignmentContext specparam_assignment() throws RecognitionException {
	Specparam_assignmentContext _localctx = new Specparam_assignmentContext(_ctx, getState());
	enterRule(_localctx, 126, RULE_specparam_assignment);
	try {
		setState(1541);
		switch (_input.LA(1)) {
		case Escaped_identifier:
		case Simple_identifier:
			enterOuterAlt(_localctx, 1);
			{
			setState(1536);
			specparam_identifier();
			setState(1537);
			match(T__50);
			setState(1538);
			constant_mintypmax_expression();
			}
			break;
		case T__62:
			enterOuterAlt(_localctx, 2);
			{
			setState(1540);
			pulse_control_specparam();
			}
			break;
		default:
			throw new NoViableAltException(this);
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
开发者ID:xprova,项目名称:netlist-graph,代码行数:40,代码来源:Verilog2001Parser.java

示例12: arrayed_identifier

import org.antlr.v4.runtime.NoViableAltException; //导入依赖的package包/类
public final Arrayed_identifierContext arrayed_identifier() throws RecognitionException {
	Arrayed_identifierContext _localctx = new Arrayed_identifierContext(_ctx, getState());
	enterRule(_localctx, 526, RULE_arrayed_identifier);
	try {
		setState(3834);
		switch (_input.LA(1)) {
		case Simple_identifier:
			enterOuterAlt(_localctx, 1);
			{
			setState(3832);
			simple_arrayed_identifier();
			}
			break;
		case Escaped_identifier:
			enterOuterAlt(_localctx, 2);
			{
			setState(3833);
			escaped_arrayed_identifier();
			}
			break;
		default:
			throw new NoViableAltException(this);
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
开发者ID:xprova,项目名称:netlist-graph,代码行数:35,代码来源:Verilog2001Parser.java

示例13: hierarchical_identifier

import org.antlr.v4.runtime.NoViableAltException; //导入依赖的package包/类
public final Hierarchical_identifierContext hierarchical_identifier() throws RecognitionException {
	Hierarchical_identifierContext _localctx = new Hierarchical_identifierContext(_ctx, getState());
	enterRule(_localctx, 556, RULE_hierarchical_identifier);
	try {
		setState(3876);
		switch (_input.LA(1)) {
		case Simple_identifier:
			enterOuterAlt(_localctx, 1);
			{
			setState(3874);
			simple_hierarchical_identifier();
			}
			break;
		case Escaped_identifier:
			enterOuterAlt(_localctx, 2);
			{
			setState(3875);
			escaped_hierarchical_identifier();
			}
			break;
		default:
			throw new NoViableAltException(this);
		}
	}
	catch (RecognitionException re) {
		_localctx.exception = re;
		_errHandler.reportError(this, re);
		_errHandler.recover(this, re);
	}
	finally {
		exitRule();
	}
	return _localctx;
}
 
开发者ID:xprova,项目名称:netlist-graph,代码行数:35,代码来源:Verilog2001Parser.java

示例14: expressioncomparisonoperator

import org.antlr.v4.runtime.NoViableAltException; //导入依赖的package包/类
/**
 * Expressioncomparisonoperator.
 *
 * @return the expressioncomparisonoperator context
 * @throws RecognitionException the recognition exception
 */
public final ExpressioncomparisonoperatorContext expressioncomparisonoperator() throws RecognitionException {
    ExpressioncomparisonoperatorContext _localctx = new ExpressioncomparisonoperatorContext(_ctx, getState());
    enterRule(_localctx, 78, RULE_expressioncomparisonoperator);
    try {
        setState(423);
        switch (_input.LA(1)) {
        case EQUALS:
            enterOuterAlt(_localctx, 1);
            {
            setState(420);
            match(EQUALS);
            }
            break;
        case EXCLAMATION:
            enterOuterAlt(_localctx, 2);
            {
            {
            setState(421);
            match(EXCLAMATION);
            setState(422);
            match(EQUALS);
            }
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:45,代码来源:ExpressionConstraintParser.java

示例15: stringcomparisonoperator

import org.antlr.v4.runtime.NoViableAltException; //导入依赖的package包/类
/**
 * Stringcomparisonoperator.
 *
 * @return the stringcomparisonoperator context
 * @throws RecognitionException the recognition exception
 */
public final StringcomparisonoperatorContext stringcomparisonoperator() throws RecognitionException {
    StringcomparisonoperatorContext _localctx = new StringcomparisonoperatorContext(_ctx, getState());
    enterRule(_localctx, 82, RULE_stringcomparisonoperator);
    try {
        setState(439);
        switch (_input.LA(1)) {
        case EQUALS:
            enterOuterAlt(_localctx, 1);
            {
            setState(436);
            match(EQUALS);
            }
            break;
        case EXCLAMATION:
            enterOuterAlt(_localctx, 2);
            {
            {
            setState(437);
            match(EXCLAMATION);
            setState(438);
            match(EQUALS);
            }
            }
            break;
        default:
            throw new NoViableAltException(this);
        }
    }
    catch (RecognitionException re) {
        _localctx.exception = re;
        _errHandler.reportError(this, re);
        _errHandler.recover(this, re);
    }
    finally {
        exitRule();
    }
    return _localctx;
}
 
开发者ID:WestCoastInformatics,项目名称:UMLS-Terminology-Server,代码行数:45,代码来源:ExpressionConstraintParser.java


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