本文整理匯總了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));
}
}
示例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."));
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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();
}
示例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!");
}
}
示例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);
}
示例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");
}
}
}
示例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;
}
示例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;
}
}
示例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();
}
}
示例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);
}
示例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();
}
示例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();
}