Search code examples
javaeclipse-pluginantlr4

How to fix the encoding problem produced by ANTLR4 in the parser generated?


I use an error alternative with a message in my grammar. The problem is that when the parser is generated, the message has encoding problems. How can I fix that?

This is what I put in my grammar :

{notifyErrorListeners("À corriger – l'expression ne correspond pas au type de l'attribut");}

And this is what the generated parser have :

notifyErrorListeners("� corriger � l'expression ne correspond pas au type de l'attribut");

Solution

  • If using the latest ANTLR4 version (4.7.2) does this, try using the Unicode escapes for these characters:

    {notifyErrorListeners("\u0192 corriger \u2013 l'expression ne correspond pas au type de l'attribut");}
    

    If using an older version than 4.7.2, try upgrading first.