本文整理了Java中org.antlr.v4.runtime.Parser.getContext()
方法的一些代码示例,展示了Parser.getContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.getContext()
方法的具体详情如下:
包路径:org.antlr.v4.runtime.Parser
类名称:Parser
方法名:getContext
暂无
代码示例来源:origin: prestodb/presto
currentState = atn.states.get(parser.getState());
currentToken = parser.getCurrentToken();
context = parser.getContext();
代码示例来源:origin: apache/incubator-shardingsphere
/**
* Get matched token by token type.
*
* @param tokenType token type
* @return matched token
* @throws RecognitionException mismatch throw exception
*/
public Token getMatchedToken(final int tokenType) throws RecognitionException {
Token result = parser.getCurrentToken();
boolean isIdentifierCompatible = false;
if (identifierTokenIndex == tokenType && identifierTokenIndex > result.getType()) {
isIdentifierCompatible = true;
}
if (result.getType() == tokenType || isIdentifierCompatible) {
if (Token.EOF != tokenType && isIdentifierCompatible && result instanceof CommonToken) {
((CommonToken) result).setType(identifierTokenIndex);
}
parser.getErrorHandler().reportMatch(parser);
parser.consume();
} else {
result = parser.getErrorHandler().recoverInline(parser);
if (parser.getBuildParseTree() && -1 == result.getTokenIndex()) {
parser.getContext().addErrorNode(parser.createErrorNode(parser.getContext(), result));
}
}
return result;
}
}
代码示例来源:origin: apache/incubator-shardingsphere
nextTokensContext = recognizer.getContext();
nextTokensState = recognizer.getState();
代码示例来源:origin: org.antlr/antlr4-runtime
/** Instead of recovering from exception {@code e}, re-throw it wrapped
* in a {@link ParseCancellationException} so it is not caught by the
* rule function catches. Use {@link Exception#getCause()} to get the
* original {@link RecognitionException}.
*/
@Override
public void recover(Parser recognizer, RecognitionException e) {
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new ParseCancellationException(e);
}
代码示例来源:origin: org.antlr/antlr4-runtime
/**
* Computes the set of input symbols which could follow the current parser
* state and context, as given by {@link #getState} and {@link #getContext},
* respectively.
*
* @see ATN#getExpectedTokens(int, RuleContext)
*/
public IntervalSet getExpectedTokens() {
return getATN().getExpectedTokens(getState(), getContext());
}
代码示例来源:origin: org.antlr/antlr4-runtime
/** 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);
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new ParseCancellationException(e);
}
代码示例来源:origin: org.antlr/antlr4-runtime
nextTokensContext = recognizer.getContext();
nextTokensState = recognizer.getState();
代码示例来源:origin: apache/eagle
/** Instead of recovering from exception {@code e}, re-throw it wrapped
* in a {@link org.antlr.v4.runtime.misc.ParseCancellationException} so it is not caught by the
* rule function catches. Use {@link Exception#getCause()} to get the
* original {@link org.antlr.v4.runtime.RecognitionException}.
*/
@Override
public void recover(Parser recognizer, RecognitionException e) {
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
super.recover(recognizer,e);
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime
/** Instead of recovering from exception {@code e}, re-throw it wrapped
* in a {@link ParseCancellationException} so it is not caught by the
* rule function catches. Use {@link Exception#getCause()} to get the
* original {@link RecognitionException}.
*/
@Override
public void recover(Parser recognizer, RecognitionException e) {
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new ParseCancellationException(e);
}
代码示例来源:origin: radkovo/jStyleParser
/**
* throws RecognitionException to handle in parser's catch block
*/
public Token recoverInline(Parser recognizer) throws RecognitionException {
throw new RecognitionException(recognizer, recognizer.getInputStream(), recognizer.getContext());
}
代码示例来源:origin: org.apache.eagle/eagle-antlr
/** Instead of recovering from exception {@code e}, re-throw it wrapped
* in a {@link org.antlr.v4.runtime.misc.ParseCancellationException} so it is not caught by the
* rule function catches. Use {@link Exception#getCause()} to get the
* original {@link org.antlr.v4.runtime.RecognitionException}.
*/
@Override
public void recover(Parser recognizer, RecognitionException e) {
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
super.recover(recognizer,e);
}
代码示例来源:origin: net.sf.cssbox/jstyleparser
/**
* throws RecognitionException to handle in parser's catch block
*/
public Token recoverInline(Parser recognizer) throws RecognitionException {
throw new RecognitionException(recognizer, recognizer.getInputStream(), recognizer.getContext());
}
代码示例来源:origin: uk.co.nichesolutions/antlr4-runtime
/** Instead of recovering from exception {@code e}, re-throw it wrapped
* in a {@link ParseCancellationException} so it is not caught by the
* rule function catches. Use {@link Exception#getCause()} to get the
* original {@link RecognitionException}.
*/
@Override
public void recover(Parser recognizer, RecognitionException e) {
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new ParseCancellationException(e);
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/** Instead of recovering from exception {@code e}, re-throw it wrapped
* in a {@link ParseCancellationException} so it is not caught by the
* rule function catches. Use {@link Exception#getCause()} to get the
* original {@link RecognitionException}.
*/
@Override
public void recover(Parser recognizer, RecognitionException e) {
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new ParseCancellationException(e);
}
代码示例来源:origin: org.ballerinalang/language-server-core
@Override
public void reportInputMismatch(Parser parser, InputMismatchException e) {
if (!parser.getContext().start.getTokenSource().getSourceName()
.equals(context.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY).replace("\\", "/"))) {
return;
}
this.context.put(CompletionKeys.TOKEN_STREAM_KEY, parser.getTokenStream());
}
代码示例来源:origin: org.ballerinalang/language-server-core
@Override
public void reportMissingToken(Parser parser) {
if (!parser.getContext().start.getTokenSource().getSourceName()
.equals(context.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY).replace("\\", "/"))) {
return;
}
this.context.put(CompletionKeys.TOKEN_STREAM_KEY, parser.getTokenStream());
}
代码示例来源:origin: org.ballerinalang/language-server-core
@Override
public void reportNoViableAlternative(Parser parser, NoViableAltException e) {
if (!parser.getContext().start.getTokenSource().getSourceName()
.equals(context.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY).replace("\\", "/"))) {
return;
}
this.context.put(CompletionKeys.TOKEN_STREAM_KEY, parser.getTokenStream());
}
代码示例来源:origin: org.ballerinalang/ballerina-lang
@Override
public void reportFailedPredicate(Parser parser, FailedPredicateException e) {
setErrorState(parser);
DiagnosticPos pos = getPosition(getMissingSymbol(parser));
if (parser.getContext() instanceof BallerinaParser.ShiftExprPredicateContext) {
dlog.error(pos, DiagnosticCode.INVALID_SHIFT_OPERATOR);
} else if (parser.getContext() instanceof BallerinaParser.RestDescriptorPredicateContext) {
dlog.error(pos, DiagnosticCode.INVALID_RECORD_REST_DESCRIPTOR);
} else {
dlog.error(pos, DiagnosticCode.FAILED_PREDICATE, e.getMessage());
}
}
代码示例来源:origin: org.ballerinalang/ballerina-lang
@Override
public void reportUnwantedToken(Parser parser) {
if (parser.getContext().exception != null || inErrorRecoveryMode(parser)) {
return;
}
beginErrorCondition(parser);
setErrorState(parser);
Token token = parser.getCurrentToken();
DiagnosticPos pos = getPosition(getMissingSymbol(parser));
dlog.error(pos, DiagnosticCode.EXTRANEOUS_INPUT, getTokenErrorDisplay(token));
}
代码示例来源:origin: com.ibeetl/beetl
protected void reportFailedPredicate(@NotNull Parser recognizer, @NotNull FailedPredicateException e)
{
String ruleName = recognizer.getRuleNames()[recognizer.getContext().getRuleIndex()];
BeetlException exception = new BeetlParserException(BeetlException.PARSER_PREDICATE_ERROR, ruleName, e);
// exception.token = this.getGrammarToken(e.getOffendingToken());
exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
throw exception;
}
内容来源于网络,如有侵权,请联系作者删除!