ANTLR: Unicode Character Scanning

后端 未结 1 1240
盖世英雄少女心
盖世英雄少女心 2021-02-10 09:43

Problem: Can\'t get Unicode character to print correctly.

Here is my grammar:

options { k=1; filter=true;
 // Allow any char but \\uFFFF (16 bit -1)
char         


        
相关标签:
1条回答
  • 2021-02-10 10:37

    Your problem is not in the ANTLR generated lexer, but in the Java stream you pass to it. The stream reads bytes only (doesn't interpret them in an encoding), and what you see is an UTF-8 sequence.

    If its ANTLR 3, you can use the ANTLRInputStream constructor that takes an ancoding as a parameter:

    ANTLRInputStream (InputStream input, String encoding) throws IOException
    
    0 讨论(0)
提交回复
热议问题