本文整理匯總了Java中org.antlr.v4.runtime.Recognizer.getInputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java Recognizer.getInputStream方法的具體用法?Java Recognizer.getInputStream怎麽用?Java Recognizer.getInputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.v4.runtime.Recognizer
的用法示例。
在下文中一共展示了Recognizer.getInputStream方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: underlineError
import org.antlr.v4.runtime.Recognizer; //導入方法依賴的package包/類
protected <T extends Token> void underlineError(
Recognizer<T, ?> recognizer, Token offendingToken, int line,
int charPositionInLine) {
CommonTokenStream tokens = (CommonTokenStream) recognizer
.getInputStream();
String input = tokens.getTokenSource().getInputStream().toString();
String[] lines = input.split("\n");
String errorLine = lines[line - 1];
System.out.println(errorLine);
for (int i = 0; i < charPositionInLine; i++)
System.out.print(" ");
int start = offendingToken.getStartIndex();
int stop = offendingToken.getStopIndex();
if (start >= 0 && stop >= 0) {
for (int i = start; i <= stop; i++)
System.out.print("^");
}
System.out.println();
}
示例2: underlineError
import org.antlr.v4.runtime.Recognizer; //導入方法依賴的package包/類
protected void underlineError(Recognizer<?, ?> recognizer, Token offendingToken, int line, int charPositionInLine, String msg) {
CommonTokenStream tokens = (CommonTokenStream) recognizer.getInputStream();
int start = offendingToken.getStartIndex() + embeddedOffset;
int stop = offendingToken.getStopIndex() + embeddedOffset;
SyntaxError syntaxError = new SyntaxError();
syntaxError.message = msg;
syntaxError.line = line;
syntaxError.charPositionInLine = charPositionInLine;
syntaxError.start = start;
syntaxError.stop = stop + 1;
syntaxErrors.add(syntaxError);
}
示例3: syntaxError
import org.antlr.v4.runtime.Recognizer; //導入方法依賴的package包/類
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
String msg, RecognitionException e) {
super.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
this.line = line;
if (recognizer.getInputStream() instanceof CommonTokenStream) {
StringBuilder errorBuilder = new StringBuilder(msg);
CommonTokenStream tokenStream = (CommonTokenStream) recognizer.getInputStream();
errorBuilder.append("\n");
String expression = tokenStream.getTokenSource().getInputStream().toString();
String[] split = expression.split("(\r\n|\n)");
String error = null;
if (split.length > 0) {
if (line - 1 >= 0 && line - 1 < split.length) {
error = split[line - 1].replace("\t", " ");
} else {
error = split[split.length - 1].replace("\t", " ");
}
errorBuilder.append(error);
errorBuilder.append("\n");
} else {
errorBuilder.append(expression);
errorBuilder.append("\n");
}
for (int i = 0; i < charPositionInLine; i++) {
errorBuilder.append(" ");
}
if (offendingSymbol instanceof Token) {
Token token = (Token) offendingSymbol;
int startIndex = token.getStartIndex();
int stopIndex = token.getStopIndex();
if (startIndex >= 0 && stopIndex >= 0 && startIndex <= stopIndex) {
for (int i = token.getStartIndex(); i <= token.getStopIndex(); i++) {
errorBuilder.append("^");
}
} else {
errorBuilder.append("^");
}
} else {
errorBuilder.append("^");
}
errorMessage = errorBuilder.toString();
} else {
errorMessage = msg;
}
}