use of com.nedap.healthcare.tolerantaqlparser.ErrorTolerantAQLLexer in project archetype-languageserver by nedap.
the class AQLStorage method createAQLDocument.
private AQLDocument createAQLDocument(String uri, String text) {
ErrorTolerantAQLLexer lexer = new ErrorTolerantAQLLexer(CharStreams.fromString(text));
ErrorTolerantAQLParser aqlParser = new ErrorTolerantAQLParser(new CommonTokenStream(lexer));
AQLSymbolListener aqlSymbolListener = new AQLSymbolListener();
new ParseTreeWalker().walk(aqlSymbolListener, aqlParser.queryClause());
boolean errorFound = false;
try {
Lookup lookup = new Lookup();
QueryClause parsed = QOMParser.parse(text, lookup);
// we don't care about the result, not going to use the object model, but this does both parsing and validation
} catch (AQLUnsupportedFeatureException ex) {
// I don't WANT this one, I want it to parse whatever it can and ignore this
List<Diagnostic> diagnostics = new ArrayList<>();
diagnostics.add(new Diagnostic(new Range(new Position(0, 0), new Position(0, 50)), ex.getMessage()));
PublishDiagnosticsParams params = new PublishDiagnosticsParams(uri, diagnostics);
archetypeRepository.getTextDocumentService().publishDiagnostics(params);
errorFound = true;
} catch (AQLValidationException ex) {
List<Diagnostic> diagnostics = new ArrayList<>();
Range range;
if (ex.getLineNumber() != null) {
range = new Range(new Position(ex.getLineNumber() - 1, ex.getCharPosition()), new Position(ex.getLineNumber() - 1, ex.getCharPosition() + ex.getLength()));
} else {
range = new Range(new Position(0, 0), new Position(0, 50));
}
diagnostics.add(new Diagnostic(range, ex.getMessageWithoutLineNumbers()));
PublishDiagnosticsParams params = new PublishDiagnosticsParams(uri, diagnostics);
archetypeRepository.getTextDocumentService().publishDiagnostics(params);
errorFound = true;
} catch (AQLRuntimeException ex) {
List<Diagnostic> diagnostics = new ArrayList<>();
diagnostics.add(new Diagnostic(new Range(new Position(0, 0), new Position(0, 50)), ex.getMessage()));
PublishDiagnosticsParams params = new PublishDiagnosticsParams(uri, diagnostics);
archetypeRepository.getTextDocumentService().publishDiagnostics(params);
errorFound = true;
} catch (Exception ex) {
List<Diagnostic> diagnostics = new ArrayList<>();
diagnostics.add(new Diagnostic(new Range(new Position(0, 0), new Position(0, 50)), ex.getMessage()));
PublishDiagnosticsParams params = new PublishDiagnosticsParams(uri, diagnostics);
archetypeRepository.getTextDocumentService().publishDiagnostics(params);
errorFound = true;
}
if (!errorFound) {
archetypeRepository.getTextDocumentService().publishDiagnostics(new PublishDiagnosticsParams(uri, new ArrayList<>()));
}
return new AQLDocument(uri, aqlSymbolListener.getSymbolToArchetypeIdMap(), aqlSymbolListener.getArchetypePathReferences(), new LinkedHashMap<>());
}
Aggregations