webchatowner
webchatowner

Reputation: 155

What is the purpose of JAVA_UNICODE_ESCAPE in JavaCC?

What is the purpose of JAVA_UNICODE_ESCAPE in JavaCC, I have looked at the documentation and it explains it very vaguely.

Upvotes: 2

Views: 391

Answers (1)

Stephen C
Stephen C

Reputation: 719336

This is what the documentation says:

JAVA_UNICODE_ESCAPE: This is a boolean option whose default value is false. When set to true, the generated parser uses an input stream object that processes Java Unicode escapes (\u...) before sending characters to the token manager. By default, Java Unicode escapes are not processed.

What does that mean?

A Java Unicode escape is a sequence starting with \u and followed by 4 hexadecimal digits. In normal Java, such a sequence is translated into a UTF-16 codeunit. This translation happens before tokenization, as described in JLS 3.3. (And as the JLS explains, Unicode codepoints that are not in the basic code plain need to be represented as two escape sequences representing the UTF-16 surrogate pair for the Unicode codepoint.)

So the JAVA_UNICODE_ESCAPE option basically tells JavaCC whether or not the generated lexer / parser should do Unicode escape handling in the same way as a Java compiler does. The default is to not handle the \uxxxx escape sequences.

Upvotes: 4

Related Questions