Issues with Error Listener, with Visual Studio Code and Node

84 views
Skip to first unread message

gabriele....@gmail.com

unread,
Mar 27, 2017, 10:53:12 AM3/27/17
to antlr-discussion
I am trying to create a Language Server for/with Visual Studio Code. So I am creating a client, for VS Code, and a server. I am using Node and ANTLR in the server part.
I am using Typescript/Javascript and I have tried both the Javascript (release) and the Typescript (alpha) libraries, neither of which works.

I have two issues with the Error Listeners:
  • the default Console Error Listener remains
  • mine isn't called

Or more precisely my Error Listener, when I call parser.getErrorListeners(), is shown as the only one, but when there is an error the syntaxError() of my Error Listener is not called and instead is called the one of the Console Error Listener.


let errorListener = new DOTErrorListener();            

lexer
.removeErrorListeners();
parser
.removeErrorListeners();      
lexer
.addErrorListener(errorListener);
parser
.addErrorListener(errorListener);    

console
.log(lexer.getErrorListeners()); // this outputs [ DOTErrorListener ]
console
.log(parser.getErrorListeners()); // this outputs [ DOTErrorListener ]

ParseTreeWalker.DEFAULT.walk(listener, tree);


This is DOTErrorListener


export class DOTErrorListener extends BaseErrorListener {
   
    @Override   
    public syntaxError(@NotNull recognizer, offendingSymbol, line, charPositionInLine, @NotNull msg, e) {                  
        console.error("ERROR! ERROR! ABORT MISSION!");
    }
   
}

Output


[ DOTErrorListener ]
[ DOTErrorListener ]
line 1:0 mismatched input 'graphi' expecting {STRICT, GRAPH, DIGRAPH}

The normal listener works, that is to say the usual enter/exit functions are called.


Any ideas?



Mike Lischke

unread,
Mar 27, 2017, 12:31:57 PM3/27/17
to antlr-di...@googlegroups.com
I only worked with the TS target from Sam, but that does the job pretty well for me. I use ANTLR in a node module, which is then used by a vscode extension. The parsing code is here:  https://github.com/mike-lischke/antlr-graps/blob/master/src/SourceContext.ts#L113 and the error listener here: https://github.com/mike-lischke/antlr-graps/blob/master/src/ContextErrorListener.ts.


Am 27.03.2017 um 16:53 schrieb gabriele....@gmail.com:

I am trying to create a Language Server for/with Visual Studio Code. So I am creating a client, for VS Code, and a server. I am using Node and ANTLR in the server part.
I am using Typescript/Javascript and I have tried both the Javascript (release) and the Typescript (alpha) libraries, neither of which works.

I have two issues with the Error Listeners:
  • the default Console Error Listener remains
  • mine isn't called

Or more precisely my Error Listener, when I call parser.getErrorListeners(), is shown as the only one, but when there is an error the syntaxError() of my Error Listener is not called and instead is called the one of the Console Error Listener.



let errorListener = new DOTErrorListener();            

lexer
.removeErrorListeners();
parser
.removeErrorListeners();      
lexer
.addErrorListener(errorListener);
parser
.addErrorListener(errorListener);    

console
.log(lexer.getErrorListeners()); // this outputs [ DOTErrorListener ]
console
.log(parser.getErrorListeners()); // this outputs [ DOTErrorListener ]

ParseTreeWalker.DEFAULT.walk(listener, tree);


This is DOTErrorListener



export class DOTErrorListener extends BaseErrorListener {
   
    @Override   
    public syntaxError(@NotNull recognizer, offendingSymbol, line, charPositionInLine, @NotNull msg, e) {                  
        console.error("ERROR! ERROR! ABORT MISSION!");
    }
   
}



gabriele....@gmail.com

unread,
Mar 27, 2017, 1:31:40 PM3/27/17
to antlr-discussion
Thanks, I will take a look
Reply all
Reply to author
Forward
0 new messages