本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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.
}
}
示例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);
}
示例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;
}
示例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());
}
示例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)
);
}
示例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
}
示例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;
}
示例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;
}
}