ANTLR: verificação de caracteres Unicode
Problema: Não é possível obter o caractere Unicode para imprimir corretamente.
Aqui está a minha gramática:
options { k=1; filter=true;
// Allow any char but \uFFFF (16 bit -1)
charVocabulary='\u0000'..'\uFFFE';
}
ANYCHAR :'Fragmento de código do método principal que chama o lexer:
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) {}
}
}
Para entrada"ठ", Estou recebendo a seguinte saída:
Found unicode:
Token : ["à",<5>,line=1,col=7]
Found unicode:
Token : ["¤",<5>,line=1,col=8]
Found unicode:
Token : [" ",<5>,line=1,col=9]
Parece que o lexer está tratando o caractere Unicode "ठ" como três caracteres separados. Meu objetivo é digitalizar e imprimir "ठ".
| '_' { System.out.println("Found underscore: "+getText()); }
| 'a'..'z' { System.out.println("Found alpha: "+getText()); }
| '\u0080'..'\ufffe' { System.out.println("Found unicode: "+getText()); }
;
Fragmento de código do método principal que chama o lexer:
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) {}
}
}
Para entrada"ठ", Estou recebendo a seguinte saída:
Found unicode:
Token : ["à",<5>,line=1,col=7]
Found unicode:
Token : ["¤",<5>,line=1,col=8]
Found unicode:
Token : [" ",<5>,line=1,col=9]
Parece que o lexer está tratando o caractere Unicode "ठ" como três caracteres separados. Meu objetivo é digitalizar e imprimir "ठ".