Search in sources :

Example 1 with QueryClause

use of com.nedap.healthcare.aqlparser.model.clause.QueryClause 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<>());
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) AQLValidationException(com.nedap.healthcare.aqlparser.exception.AQLValidationException) AQLUnsupportedFeatureException(com.nedap.healthcare.aqlparser.exception.AQLUnsupportedFeatureException) ArrayList(java.util.ArrayList) QueryClause(com.nedap.healthcare.aqlparser.model.clause.QueryClause) AQLRuntimeException(com.nedap.healthcare.aqlparser.exception.AQLRuntimeException) AQLValidationException(com.nedap.healthcare.aqlparser.exception.AQLValidationException) AQLRuntimeException(com.nedap.healthcare.aqlparser.exception.AQLRuntimeException) AQLUnsupportedFeatureException(com.nedap.healthcare.aqlparser.exception.AQLUnsupportedFeatureException) ErrorTolerantAQLParser(com.nedap.healthcare.tolerantaqlparser.ErrorTolerantAQLParser) ErrorTolerantAQLLexer(com.nedap.healthcare.tolerantaqlparser.ErrorTolerantAQLLexer) Lookup(com.nedap.healthcare.aqlparser.model.Lookup) ArrayList(java.util.ArrayList) List(java.util.List) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker)

Aggregations

AQLRuntimeException (com.nedap.healthcare.aqlparser.exception.AQLRuntimeException)1 AQLUnsupportedFeatureException (com.nedap.healthcare.aqlparser.exception.AQLUnsupportedFeatureException)1 AQLValidationException (com.nedap.healthcare.aqlparser.exception.AQLValidationException)1 Lookup (com.nedap.healthcare.aqlparser.model.Lookup)1 QueryClause (com.nedap.healthcare.aqlparser.model.clause.QueryClause)1 ErrorTolerantAQLLexer (com.nedap.healthcare.tolerantaqlparser.ErrorTolerantAQLLexer)1 ErrorTolerantAQLParser (com.nedap.healthcare.tolerantaqlparser.ErrorTolerantAQLParser)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)1