當前位置: 首頁>>代碼示例>>Java>>正文


Java ParseCancellationException類代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.misc.ParseCancellationException的典型用法代碼示例。如果您正苦於以下問題:Java ParseCancellationException類的具體用法?Java ParseCancellationException怎麽用?Java ParseCancellationException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ParseCancellationException類屬於org.antlr.v4.runtime.misc包,在下文中一共展示了ParseCancellationException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: exitDelete_stmt

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
@Override
public void exitDelete_stmt(BQLParser.Delete_stmtContext ctx) {
  deleteRequest = new LindenDeleteRequest();
  if (ctx.dw != null) {
    LindenFilter filter = filterProperty.get(ctx.dw);
    if (filter == null) {
      throw new ParseCancellationException(new SemanticException(ctx, "Filter parse failed"));
    }
    LindenQuery query = LindenQueryBuilder.buildMatchAllQuery();
    query = LindenQueryBuilder.buildFilteredQuery(query, filter);
    deleteRequest.setQuery(query);
  } else {
    deleteRequest.setQuery(LindenQueryBuilder.buildMatchAllQuery());
  }
  if (ctx.route_param != null) {
    deleteRequest.setRouteParam((SearchRouteParam) valProperty.get(ctx.route_param));
  }
  if (ctx.indexes != null) {
    deleteRequest.setIndexNames((List<String>) valProperty.get(ctx.indexes));
  }
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:22,代碼來源:BQLCompilerAnalyzer.java

示例2: exitType

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
@Override
public void exitType(BQLParser.TypeContext ctx) {
  String type;
  if (ctx.primitive_type() != null) {
    type = ctx.primitive_type().getText();
  } else if (ctx.boxed_type() != null) {
    type = ctx.boxed_type().getText();
  } else if (ctx.limited_type() != null) {
    type = ctx.limited_type().getText();
  } else if (ctx.map_type() != null) {
    return;
  } else {
    throw new UnsupportedOperationException("Not implemented yet.");
  }
  try {
    if (type.equalsIgnoreCase("int")) {
      valProperty.put(ctx, LindenType.INTEGER);
    } else {
      valProperty.put(ctx, LindenType.valueOf(type.toUpperCase()));
    }
  } catch (Exception e) {
    throw new ParseCancellationException(new SemanticException(ctx, "Type " + type + " not support."));
  }
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:25,代碼來源:BQLCompilerAnalyzer.java

示例3: exitSnippet_clause

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
@Override
public void exitSnippet_clause(BQLParser.Snippet_clauseContext ctx) {
  if (ctx.selection_list() != null) {
    List<String> selections = (List<String>) valProperty.get(ctx.selection_list());
    if (selections != null && !selections.isEmpty()) {
      SnippetParam snippet = new SnippetParam();
      for (String selection : selections) {
        Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(selection);
        LindenType type = fieldNameAndType.getValue();
        String col = fieldNameAndType.getKey();
        if (type == LindenType.STRING) {
          snippet.addToFields(new SnippetField(col));
        } else {
          throw new ParseCancellationException("Snippet doesn't support this type " + type);
        }
      }
      valProperty.put(ctx, snippet);
    }
  }
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:21,代碼來源:BQLCompilerAnalyzer.java

示例4: exitPython_style_list

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
@Override
public void exitPython_style_list(BQLParser.Python_style_listContext ctx) {
  List<String> values = new ArrayList<>();
  for (BQLParser.Python_style_valueContext subCtx : ctx.python_style_value()) {
    if (subCtx.value() != null) {
      values.add(subCtx.value().getText());
    } else if (subCtx.python_style_list() != null) {
      throw new ParseCancellationException(
          new SemanticException(subCtx.python_style_list(), "Nested list is not supported"));
    } else if (subCtx.python_style_dict() != null) {
      throw new ParseCancellationException(
          new SemanticException(subCtx.python_style_dict(), "Dict list is not supported"));
    }
  }
  valProperty.put(ctx, values);
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:17,代碼來源:BQLCompilerAnalyzer.java

示例5: exitAggregation_spec

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
@Override
public void exitAggregation_spec(BQLParser.Aggregation_specContext ctx) {
  String col = unescapeColumnName(ctx.column_name());
  Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
  LindenType type = fieldNameAndType.getValue();
  if (type != LindenType.INTEGER && type != LindenType.LONG && type != LindenType.DOUBLE) {
    throw new ParseCancellationException(new SemanticException(ctx.column_name(),
                                                               "Aggregation doesn't support the type of the field \""
                                                               + col + "\"."));
  }
  col = fieldNameAndType.getKey();

  Aggregation aggregation = new Aggregation();
  aggregation.setField(col);
  aggregation.setType(type);
  for (BQLParser.Bucket_specContext specContext : ctx.bucket_spec()) {
    Bucket bucket = (Bucket) valProperty.get(specContext);
    if (bucket != null) {
      aggregation.addToBuckets(bucket);
    }
  }
  facetRequest.addToAggregations(aggregation);
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:24,代碼來源:BQLCompilerAnalyzer.java

示例6: getErrorMessage

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
public String getErrorMessage(ParseCancellationException error) {
  if (error.getCause() != null) {
    String message = error.getCause().getMessage();
    if (error.getCause() instanceof SemanticException) {
      SemanticException semanticException = (SemanticException) error.getCause();
      if (semanticException.getNode() != null) {
        TerminalNode startNode = getStartNode(semanticException.getNode());
        if (startNode != null) {
          String prefix = String.format("[line:%d, col:%d] ", startNode.getSymbol().getLine(),
              startNode.getSymbol().getCharPositionInLine());
          message = prefix + message;
        }
      }
      return message;
    } else if (error.getCause() instanceof RecognitionException) {
      return getErrorMessage((RecognitionException) error.getCause());
    } else {
      return error.getCause().getMessage();
    }
  }

  return error.getMessage();
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:24,代碼來源:BQLCompiler.java

示例7: readMatrix

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
private Object readMatrix(List<Object> parameters) {
  String rationalString = in.nextLine();

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

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

  matrixParser.setErrorHandler(new BailErrorStrategy());

  try {
    MatrixParser.MatrixContext matrixContext = matrixParser.matrix();

    return Matrix.fromMatrixContext(matrixContext, Scope.NULL_SCOPE);
  } catch (ParseCancellationException e) {
    throw new InvalidReadRuntimeError("Invalid input read from stdin! Expected matrix format!");
  }
}
 
開發者ID:daergoth,項目名稱:MatrixC,代碼行數:18,代碼來源:InputOutputDeclarationSource.java

示例8: parse

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
/**
 * Parse the {@link GraqlParser} into a Java object, where errors are reported to the given
 * {@link GraqlErrorListener}.
 */
final T parse(GraqlParser parser, GraqlErrorListener errorListener) {
    S tree;

    try {
        tree = parseTree(parser);
    } catch (ParseCancellationException e) {
        // If we're using the BailErrorStrategy, we will throw here
        // This strategy is designed for parsing very large files and cannot provide useful error information
        throw GraqlSyntaxException.parsingError("syntax error");
    }

    if (errorListener.hasErrors()) {
        throw GraqlSyntaxException.parsingError(errorListener.toString());
    }

    return visit(getQueryVisitor(), tree);
}
 
開發者ID:graknlabs,項目名稱:grakn,代碼行數:22,代碼來源:QueryParserImpl.java

示例9: menuViewASTActionPerformed

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
/**
 * Quand un terme sauvegardé dans la liste des termes sauvegardés est séléectionné il est possible
 * de voir son AST via le menu, ou le raccourci Ctrl+I / Cmd+I
 *
 * @param evt L'event qui a trigger l'action.
 */
private void menuViewASTActionPerformed(java.awt.event.ActionEvent evt) {
    if (!termSavedList.isSelectionEmpty()) {
        int index = termSavedList.getSelectedIndex();
        String term = saveTermModel.getElementAt(index);
        try {
            ANTLRInputStream inputStream = new ANTLRInputStream(term);
            LambdaLexer lexer = new LambdaLexer(inputStream);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            LambdaParser parser = new LambdaParser(tokens);
            ParseTree tree = parse(term);
            TreeViewer viewer = new TreeViewer(Arrays.asList(parser.getRuleNames()), tree);
            viewer.open();
        } catch (ParseCancellationException e) {
            workSpace.append("Don't try to watch AST of illformed term please");
        }
    }
}
 
開發者ID:Tirke,項目名稱:Lambda-Interpreter,代碼行數:24,代碼來源:LambdaInterpreterGUI.java

示例10: parse

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
public static Program parse(String source) {
	RankPLLexer lexer = new RankPLLexer(new ANTLRInputStream(source));
	TokenStream tokens = new CommonTokenStream(lexer);
	RankPLParser parser = new RankPLParser(tokens);
	parser.setErrorHandler(new BailErrorStrategy());
	ConcreteParser classVisitor = new ConcreteParser();

	// Parse
	Program program = null;
	try {
		program = (Program) classVisitor.visit(parser.program());
	} catch (ParseCancellationException e) {
		System.out.println("Syntax error");
		lexer = new RankPLLexer(new ANTLRInputStream(source));
		tokens = new CommonTokenStream(lexer);
		parser = new RankPLParser(tokens);
		classVisitor = new ConcreteParser();
		try {
			program = (Program) classVisitor.visit(parser.program());
		} catch (Exception ex) {
			// Ignore
		}
		return null;
	}
	return program;
}
 
開發者ID:tjitze,項目名稱:RankPL,代碼行數:27,代碼來源:RankPL.java

示例11: start

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
public static ReplState start(String code){
Program p=Phase1CacheKey._handleCache();
try{
  boolean cached=p!=null;
  if(!cached){
    Timer.activate("RunningWithoutParsedCache");
    p= L42.parseAndDesugar("Repl",code);
    }
  ProgramReduction pr = new ProgramReduction(Paths.get("localhost","ReplCache.C42"),!cached);
  ReplState res=new ReplState(code,p.top(),p,pr);
  res.desugaredL=res.reduction.allSteps(res.p);
  res.p=res.p.updateTop(res.desugaredL);
  res.code=code.substring(1, code.length()-1); //to remove start and end {}
  return res;
  }
  catch(org.antlr.v4.runtime.misc.ParseCancellationException parser){
    System.out.println(parser.getMessage());
    return null;
    }
  catch(ErrorMessage msg){
    ErrorFormatter.topFormatErrorMessage(msg);
    return null;
    }
}
 
開發者ID:ElvisResearchGroup,項目名稱:L42,代碼行數:25,代碼來源:ReplState.java

示例12: testParse_String

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
/**
 * Test of parse method, of class Number.
 */
@Test
public void testParse_String() {
    System.out.println("parse");
    try {
        assertEquals(Number.parse("UINT8_MAX"), 255L);
        assertEquals(Number.parse("UINT16_MAX"), 65535L);
        assertEquals(Number.parse("UINT24_MAX"), 16777215L);
        assertEquals(Number.parse("UINT32_MAX"), 4294967295L);
        assertEquals(Number.parse("UINT64_MAX"), -1L);
        assertEquals(Number.parse("073"), 59L);
        assertEquals(Number.parse("0"), 0L);
        assertEquals(Number.parse("123456789"), 123456789L);
        assertEquals(Number.parse("0xdeadbeef"), 0xdeadbeefL);
        assertEquals(Number.parse("0xdeadBeef"), 0xdeadbeefL);
    } catch (ParseCancellationException ex) {
        fail();
    }
}
 
開發者ID:bengtmartensson,項目名稱:IrpTransmogrifier,代碼行數:22,代碼來源:NumberNGTest.java

示例13: recover

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的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

示例14: visitSource

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
@Override public String visitSource(MainParser.SourceContext ctx) {
    StringBuilder program = new StringBuilder("v2.0 raw\n");

    for (ParseTree child : ctx.children) {
        String currentByte = visit(child);
        if (! currentByte.isEmpty()) { // empty string doesn't effect program output
            if (currentByte.matches("^[01]{8}$")) {
                int value = Integer.parseInt(currentByte, 2);
                program.append(toBase(value, 16, 2) + " ");
                bytes++; // running count of bytes is important for visitAssignLabel
            } else {
                throw new ParseCancellationException(new com.github.charmoniumq.assembler.backend.InternalError(String.format("Invalid byte produced: %s", currentByte)));
            }
        }
    }
    return program.toString();
}
 
開發者ID:charmoniumQ,項目名稱:LALU-Assembler,代碼行數:18,代碼來源:Compiler.java

示例15: parse

import org.antlr.v4.runtime.misc.ParseCancellationException; //導入依賴的package包/類
/**
 * Compile request to AST.
 *
 * @param path request
 * @return AST parse tree
 */
public static ParseTree parse(String path) {
    String normalizedPath = Paths.get(path).normalize().toString().replace(File.separatorChar, '/');
    if (normalizedPath.startsWith("/")) {
        normalizedPath = normalizedPath.substring(1);
    }
    ANTLRInputStream is = new ANTLRInputStream(normalizedPath);
    CoreLexer lexer = new CoreLexer(is);
    lexer.removeErrorListeners();
    lexer.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
                                int charPositionInLine, String msg, RecognitionException e) {
            throw new ParseCancellationException(msg, e);
        }
    });
    CoreParser parser = new CoreParser(new CommonTokenStream(lexer));
    parser.setErrorHandler(new BailErrorStrategy());
    return parser.start();
}
 
開發者ID:yahoo,項目名稱:elide,代碼行數:26,代碼來源:Elide.java


注:本文中的org.antlr.v4.runtime.misc.ParseCancellationException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。