Search in sources :

Example 1 with ArchieErrorListener

use of com.nedap.archie.antlr.errors.ArchieErrorListener in project archetype-languageserver by nedap.

the class ADL2SymbolExtractor method extractSymbols.

public DocumentInformation extractSymbols(String uri, String text) throws IOException {
    AdlLexer lexer = new AdlLexer(CharStreams.fromString(text));
    AdlParser parser = new AdlParser(new CommonTokenStream(lexer));
    ArchieErrorListener listener = new ArchieErrorListener();
    parser.addErrorListener(listener);
    SymbolInformationExtractingListener symbolExtractingListener = new SymbolInformationExtractingListener(uri, lexer);
    // DocumentSymbolExtractingListener symbolExtractingListener = new DocumentSymbolExtractingListener();
    try {
        new ParseTreeWalker().walk(symbolExtractingListener, parser.adl());
    } catch (Exception e) {
        // this is fine. for now
        e.printStackTrace();
    }
    archetypeId = symbolExtractingListener.getArchetypeId();
    return new DocumentInformation(archetypeId, ADLVersion.VERSION_2, listener.getErrors(), symbolExtractingListener.getSymbols(), symbolExtractingListener.getFoldingRanges(), symbolExtractingListener.getDocumentLinks(), symbolExtractingListener.getCTerminologyCodes());
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ArchieErrorListener(com.nedap.archie.antlr.errors.ArchieErrorListener) AdlLexer(com.nedap.archie.adlparser.antlr.AdlLexer) DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) AdlParser(com.nedap.archie.adlparser.antlr.AdlParser) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) IOException(java.io.IOException)

Example 2 with ArchieErrorListener

use of com.nedap.archie.antlr.errors.ArchieErrorListener in project archetype-languageserver by nedap.

the class ADL14SymbolExtractor method extractSymbols.

public DocumentInformation extractSymbols(String uri, String text) throws IOException {
    Adl14Lexer lexer = new Adl14Lexer(CharStreams.fromString(text));
    Adl14Parser parser = new Adl14Parser(new CommonTokenStream(lexer));
    ArchieErrorListener listener = new ArchieErrorListener();
    parser.addErrorListener(listener);
    ADL14SymbolInformationExtractingListener symbolExtractingListener = new ADL14SymbolInformationExtractingListener(uri, lexer);
    // DocumentSymbolExtractingListener symbolExtractingListener = new DocumentSymbolExtractingListener();
    try {
        new ParseTreeWalker().walk(symbolExtractingListener, parser.adl());
    } catch (Exception e) {
        // this is fine. for now
        e.printStackTrace();
    }
    archetypeId = symbolExtractingListener.getArchetypeId();
    return new DocumentInformation(archetypeId, ADLVersion.VERSION_1_4, listener.getErrors(), symbolExtractingListener.getSymbols(), symbolExtractingListener.getFoldingRanges(), symbolExtractingListener.getDocumentLinks());
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ArchieErrorListener(com.nedap.archie.antlr.errors.ArchieErrorListener) Adl14Parser(com.nedap.archie.adlparser.antlr.Adl14Parser) DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) Adl14Lexer(com.nedap.archie.adlparser.antlr.Adl14Lexer) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) IOException(java.io.IOException)

Aggregations

ArchieErrorListener (com.nedap.archie.antlr.errors.ArchieErrorListener)2 DocumentInformation (com.nedap.openehr.lsp.document.DocumentInformation)2 IOException (java.io.IOException)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)2 Adl14Lexer (com.nedap.archie.adlparser.antlr.Adl14Lexer)1 Adl14Parser (com.nedap.archie.adlparser.antlr.Adl14Parser)1 AdlLexer (com.nedap.archie.adlparser.antlr.AdlLexer)1 AdlParser (com.nedap.archie.adlparser.antlr.AdlParser)1