java类org.antlr.v4.runtime.misc.ParseCancellationException的实例源码

BQLCompilerAnalyzer.java 文件源码 项目:linden 阅读 26 收藏 0 点赞 0 评论 0
@Override
public void exitLike_predicate(BQLParser.Like_predicateContext ctx) {
  if (ctx.PLACEHOLDER() != null) {
    return;
  }

  String col = unescapeColumnName(ctx.column_name());
  Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
  LindenType type = fieldNameAndType.getValue();
  if (type != LindenType.STRING && type != LindenType.FACET) {
    throw new ParseCancellationException(new SemanticException(ctx.column_name(),
                                                               "Non-string type column \"" + col
                                                               + "\" can not be used in LIKE predicates."));
  }
  col = fieldNameAndType.getKey();

  String likeString = unescapeStringLiteral(ctx.STRING_LITERAL());
  LindenWildcardQuery wildcardQuery = new LindenWildcardQuery().setField(col)
      .setQuery(likeString);
  if (inQueryWhere) {
    if (ctx.NOT() != null) {
      LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
      builder.addQuery(LindenRangeQueryBuilder.buildMatchAllQuery(), LindenBooleanClause.MUST);
      builder.addQuery(new LindenQuery().setWildcardQuery(wildcardQuery), LindenBooleanClause.MUST_NOT);
      queryProperty.put(ctx, builder.build());
    } else {
      queryProperty.put(ctx, new LindenQuery().setWildcardQuery(wildcardQuery));
    }
  } else {
    LindenFilter filter = new LindenFilter().setQueryFilter(
        new LindenQueryFilter().setQuery(new LindenQuery().setWildcardQuery(wildcardQuery)));
    if (ctx.NOT() != null) {
      LindenBooleanFilter booleanFilter = new LindenBooleanFilter();
      booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(filter)
                                     .setClause(LindenBooleanClause.MUST_NOT));
      filter = new LindenFilter().setBooleanFilter(booleanFilter);
    }
    filterProperty.put(ctx, filter);
  }
}
BQLCompiler.java 文件源码 项目:linden 阅读 19 收藏 0 点赞 0 评论 0
public String getErrorMessage(Exception error) {
  if (error instanceof NoViableAltException) {
    return getErrorMessage((NoViableAltException) error);
  } else if (error instanceof ParseCancellationException) {
    return getErrorMessage((ParseCancellationException) error);
  } else {
    return error.getMessage();
  }
}
CoqFTParser.java 文件源码 项目:exterminator 阅读 23 收藏 0 点赞 0 评论 0
public static Term parseTerm(String s, boolean trySLL) {
    CoqFTParser p = new CoqFTParser(s);
    if(trySLL) {
        p.getInterpreter().setPredictionMode(PredictionMode.SLL);
        p.setErrorHandler(new BailErrorStrategy());
        try {
            return p.parseTerm();
        } catch(ParseCancellationException | CoqSyntaxException e) {
            p = new CoqFTParser(s);
        }
    }
    return p.parseTerm();
}
CoqFTParser.java 文件源码 项目:exterminator 阅读 25 收藏 0 点赞 0 评论 0
public static Tactic parseTactic(String s, boolean trySLL) {
    CoqFTParser p = new CoqFTParser(s);
    if(trySLL) {
        p.getInterpreter().setPredictionMode(PredictionMode.SLL);
        p.setErrorHandler(new BailErrorStrategy());
        try {
            return p.parseTactic();
        } catch(ParseCancellationException | CoqSyntaxException e) {
            p = new CoqFTParser(s);
        }
    }
    return p.parseTactic();
}
InputOutputDeclarationSource.java 文件源码 项目:MatrixC 阅读 19 收藏 0 点赞 0 评论 0
private Object readRational(List<Object> parameters) {
  String rationalString = in.nextLine();

  MatrixLexer matrixLexer = new MatrixLexer(new ANTLRInputStream(rationalString));

  MatrixParser matrixParser = new MatrixParser(new CommonTokenStream(matrixLexer));

  try {
    MatrixParser.RationalContext rationalContext = matrixParser.rational();

    return Rational.fromRationalContext(rationalContext);
  } catch (ParseCancellationException e) {
    throw new InvalidReadRuntimeError("Invalid input read from stdin! Expected rational format!");
  }
}
GraphQLQueryExecutor.java 文件源码 项目:spring-graphql-common 阅读 16 收藏 0 点赞 0 评论 0
public <T extends ExecutionResult> T execute() {

        assertNotNull(arguments, "Arguments can't be null");
        LOGGER.info("Executing request. Operation name: {}. Request: {} ", operationName, requestQuery);

        Parser parser = new Parser();
        Document document;
        try {
            document = parser.parseDocument(requestQuery);
        } catch (ParseCancellationException e) {
            RecognitionException recognitionException = (RecognitionException) e.getCause();
            SourceLocation sourceLocation = new SourceLocation(recognitionException.getOffendingToken().getLine(), recognitionException.getOffendingToken().getCharPositionInLine());
            InvalidSyntaxError invalidSyntaxError = new InvalidSyntaxError(sourceLocation);
            return (T) new GraphQLRxExecutionResult(Observable.just(null), Observable.just(Arrays.asList(invalidSyntaxError)));
        }

        Validator validator = new Validator();
        List<ValidationError> validationErrors = validator.validateDocument(graphQLSchemaHolder.getGraphQLSchema(), document);
        if (validationErrors.size() > 0) {
            return (T) new GraphQLRxExecutionResult(Observable.just(null), Observable.just(validationErrors));
        }

        if (executionStrategy == null) {
            if (executorService == null) {
                executionStrategy = new GraphQLDefaultRxExecutionStrategy(graphQLSchemaHolder, maxQueryDepth, maxQueryComplexity);
            } else {
                executionStrategy = new GraphQLExecutorServiceRxExecutionStrategy(graphQLSchemaHolder, executorService, maxQueryDepth, maxQueryComplexity);
            }
        }

        RxExecution execution = new RxExecution(graphQLSchemaHolder, maxQueryDepth, maxQueryComplexity, executionStrategy);
        ExecutionResult executionResult = execution.execute(graphQLSchemaHolder.getGraphQLSchema(), context, document, operationName, arguments);

        return (T) (executionResult instanceof GraphQLRxExecutionResult ?
                executionResult : new GraphQLRxExecutionResult(Observable.just(executionResult.getData()), Observable.just(executionResult.getErrors())));
    }
Calculator.java 文件源码 项目:antlr-examples 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Returns the value of the given expression.
 *
 * <p>For example, {@code evaluate("1+2")} returns {@code 3.0}, but {@code evaluate("1+")} throws
 * an exception.
 *
 * @param input the {@code String} to parse and evaluate
 * @return the value of the given expression
 * @throws IllegalArgumentException if {@code input} is an invalid expression
 */
public static double evaluate(String input) {
  CalculatorParser parser = ParserUtil.newParser(
      CalculatorLexer::new, CalculatorParser::new, input);
  ExpressionEvaluator evaluator = new ExpressionEvaluator();

  try {
    ParserUtil.parseAndWalk(parser::expression, evaluator);
  } catch (ParseCancellationException e) {
    throw new IllegalArgumentException("Invalid expression", e);
  }

  return evaluator.getValue();
}
Parentheses.java 文件源码 项目:antlr-examples 阅读 17 收藏 0 点赞 0 评论 0
/**
 * Returns whether {@code input} consists of balanced parentheses.
 *
 * <p>For example, {@code verify("(())")} returns true, but {@code verify("(")} returns false.
 *
 * @param input the {@code String} to parse and verify
 * @return whether {@code input} consists of balanced parentheses
 */
public static boolean verify(String input) {
  ParenthesesParser parser = ParserUtil.newParser(
      ParenthesesLexer::new, ParenthesesParser::new, input);

  try {
    parser.expression();
  } catch (ParseCancellationException e) {
    return false;
  }

  return true;
}
InterruptablePHPParser.java 文件源码 项目:mdetect 阅读 16 收藏 0 点赞 0 评论 0
@Override
public void enterRule(ParserRuleContext ctx, int i, int j) {
    super.enterRule(ctx, i, j);
    if(Thread.currentThread().isInterrupted()) {
        logger.info("[DBG] thread interrupted while parsing " + filePath);
        Thread.yield();
        String exceptionMessage = "thread interrupted " + filePath;
        throw new ParseCancellationException(exceptionMessage);
    }
}
KsqlParser.java 文件源码 项目:ksql 阅读 17 收藏 0 点赞 0 评论 0
private ParserRuleContext getParseTree(String sql) {

    SqlBaseLexer
        sqlBaseLexer =
        new SqlBaseLexer(new CaseInsensitiveStream(new ANTLRInputStream(sql)));
    CommonTokenStream tokenStream = new CommonTokenStream(sqlBaseLexer);
    SqlBaseParser sqlBaseParser = new SqlBaseParser(tokenStream);

    sqlBaseLexer.removeErrorListeners();
    sqlBaseLexer.addErrorListener(ERROR_LISTENER);

    sqlBaseParser.removeErrorListeners();
    sqlBaseParser.addErrorListener(ERROR_LISTENER);

    Function<SqlBaseParser, ParserRuleContext> parseFunction = SqlBaseParser::statements;
    ParserRuleContext tree;
    try {
      // first, try parsing with potentially faster SLL mode
      sqlBaseParser.getInterpreter().setPredictionMode(PredictionMode.SLL);
      tree = parseFunction.apply(sqlBaseParser);
    } catch (ParseCancellationException ex) {
      // if we fail, parse with LL mode
      tokenStream.reset(); // rewind input stream
      sqlBaseParser.reset();

      sqlBaseParser.getInterpreter().setPredictionMode(PredictionMode.LL);
      tree = parseFunction.apply(sqlBaseParser);
    }

    return tree;
  }


问题


面经


文章

微信
公众号

扫码关注公众号