Note that there are some explanatory texts on larger screens.

plurals
  1. POANTLR: how to extract error messages when build fails
    primarykey
    data
    text
    <p>I've built my lexer and parser in ANTLR and they work really well in the sense that when user code fails to parse, it outputs useful error messages to STDERR, showing the exact line no. etc. </p> <p>The problem is, I need to extract this information in order to display the error messages in my Eclipse editor at the correct positions, but it doesn't seem to be available anywhere except on STDERR. I'm basically looking for some kind of myParser.getErrorMessages().</p> <p>Has anybody come across a solution to this?</p> <p>I found the below link, however this only works if the user code partially parses (i.e. so we still get an AST). When it fails completely, you don't get a tree back. <a href="http://tech.puredanger.com/2007/02/01/recovering-line-and-column-numbers-in-your-antlr-ast/" rel="nofollow">http://tech.puredanger.com/2007/02/01/recovering-line-and-column-numbers-in-your-antlr-ast/</a></p> <p>I also found this exact question in the official ANTLR FAQ... but I really don't understand his solution. Can anybody translate it for me? I'm not using any of the classes he refers to, and he's talking about v4 (which isn't released yet). <a href="http://www.antlr.org/wiki/display/ANTLR3/Pattern+for+returning+errors+from+ANTLR+in+data+structures%2C+not+STDERR" rel="nofollow">http://www.antlr.org/wiki/display/ANTLR3/Pattern+for+returning+errors+from+ANTLR+in+data+structures%2C+not+STDERR</a></p> <p>My code looks as follows:</p> <pre><code>FileInputStream fis = new FileInputStream("UserCode.txt"); ANTLRInputStream input = new ANTLRInputStream(fis); MyLexer lexer = new MyLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); MyParser parser = new MyParser(tokens); CommonTree tree = (CommonTree)parser.flow().getTree(); MyAST ast = new MyAST(tree); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload