Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unicode characters in identifiers #13753

Closed
sxwangzhiwen opened this issue Dec 3, 2022 · 3 comments
Closed

Use unicode characters in identifiers #13753

sxwangzhiwen opened this issue Dec 3, 2022 · 3 comments

Comments

@sxwangzhiwen
Copy link

At present, the function name and variable name of Zig language can only use ASCII characters. It is expected that future versions will consider allowing the use of unicode encoded characters in identifiers.

I wrote a program fragment to judge unicode character derived property for reference, see: https://github.com/sxwangzhiwen/unicodeid

The source of data acquisition and generation is https://www.unicode.org/Public/UCD/latest/ucd/DerivedCoreProperties.txt

There are four functions in unicodeid.zig: isID_Start(), isID_Continue(), isXID_Start(), isXID_Continue()

It can judge the derived property of UTF-8 character encoding in UTF-8 string.

The four functions can be used in the. Identifier and else branches of the src/lib/std/zig/tokenizer.zig and src/lib/std/zig/c/tokenizer.zig next() functions, as required, to allow the use of UTF-8 characters conforming to unicode encoding in identifiers.

@IntegratedQuantum
Copy link
Contributor

It may be a bit clunky to use, but zig currently supports arbitrary (unicode) identifiers using @"...".
For example:

const @"π" = 3.141592653589;
const @"π²/6" = @"π" * @"π" / 6;

@sxwangzhiwen
Copy link
Author

Yes, it's OK. After all, it is not as convenient as using unicode characters directly.

Now, major programming languages such as python, javascript, java, rust, etc. support the direct use of unicode characters in identifiers.

Therefore, it is recommended that Zig also support it.

@Vexu
Copy link
Member

Vexu commented Dec 3, 2022

Duplicate of #3947, #4151

@Vexu Vexu closed this as completed Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants