问题:无法正确打印 Unicode 字符。
这是我的语法:
options { k=1; filter=true;
// Allow any char but \uFFFF (16 bit -1)
charVocabulary='\u0000'..'\uFFFE';
}
ANYCHAR :'$'
| '_' { System.out.println("Found underscore: "+getText()); }
| 'a'..'z' { System.out.println("Found alpha: "+getText()); }
| '\u0080'..'\ufffe' { System.out.println("Found unicode: "+getText()); }
;
调用词法分析器的主要方法的代码片段:
public static void main(String[] args) {
SimpleLexer simpleLexer = new SimpleLexer(System.in);
while(true) {
try {
Token t = simpleLexer.nextToken();
System.out.println("Token : "+t);
} catch(Exception e) {}
}
}
对于输入"ठ",我得到以下输出:
Found unicode:
Token : ["à",<5>,line=1,col=7]
Found unicode:
Token : ["¤",<5>,line=1,col=8]
Found unicode:
Token : [" ",<5>,line=1,col=9]
词法分析器似乎将 Unicode 字符“ठ”视为三个单独的字符。我的目标是扫描和打印“ठ”。