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

add Unicode.julia_chartransform Julia-parser normalization #42561

Merged
merged 16 commits into from
Oct 18, 2021

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Oct 8, 2021

Finally addresses a request by @Keno in #19464 (comment): provides a Unicode.julia_chartransform function exporting the custom character normalization used by the Julia parser, which can be used as a chartransform keyword to Unicode.normalize.

(More generally, the user can pass any custom codepoint mapping to normalize via the chartransform keyword.)

This should be useful for any package that needs to reproduce the normalization performed by the Julia parser: they can now do Unicode.normalize(string, compose=true, stable=true, chartransformUnicode.julia_chartransform).

@stevengj stevengj added domain:unicode Related to unicode characters and encodings parser Language parsing and surface syntax labels Oct 8, 2021
@stevengj stevengj requested a review from Keno October 8, 2021 19:43
@nalimilan
Copy link
Member

Cool. Though is "charmap" the best term for this? It's often used to refer to the full list of all possible characters. Maybe something about "mapping" or "transformation" would avoid confusion?

@bkamins
Copy link
Member

bkamins commented Oct 9, 2021

Thank you for working on this.

@stevengj
Copy link
Member Author

stevengj commented Oct 9, 2021

@nalimilan, renamed charmap to chartransform

base/strings/unicode.jl Outdated Show resolved Hide resolved
stdlib/Unicode/src/Unicode.jl Outdated Show resolved Hide resolved
stdlib/Unicode/src/Unicode.jl Outdated Show resolved Hide resolved
stdlib/Unicode/test/runtests.jl Outdated Show resolved Hide resolved
@stevengj stevengj changed the title add Unicode.julia_charmap Julia-parser normalization add Unicode.julia_chartransform Julia-parser normalization Oct 9, 2021
NEWS.md Show resolved Hide resolved
@stevengj
Copy link
Member Author

CI failures seem unrelated (it's been a long time since I've seen a green CI!), so this PR should be ready for review.

Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small nits. Merge when you want.

stdlib/Unicode/src/Unicode.jl Outdated Show resolved Hide resolved
stdlib/Unicode/src/Unicode.jl Outdated Show resolved Hide resolved
@@ -4,6 +4,50 @@ module Unicode

export graphemes, isequal_normalized

"""
Unicode.julia_chartransform(c::Union{Char,Integer})
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts about naming this something like parsertransform?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, do you have an opinion on my last comment above? #42561 (comment)

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the callback function is good

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong feelings on the name…

base/strings/unicode.jl Outdated Show resolved Hide resolved
stevengj and others added 3 commits October 15, 2021 23:19
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
base/strings/unicode.jl Outdated Show resolved Hide resolved
@JeffBezanson JeffBezanson merged commit 50fcb03 into master Oct 18, 2021
@JeffBezanson JeffBezanson deleted the sgj/julia_charmap branch October 18, 2021 17:28
c42f added a commit to JuliaLang/JuliaSyntax.jl that referenced this pull request Jan 21, 2022
* Add Unicode NFC normalization of all identifiers
* Add Julia-specific normalizations of lookalikes of - ⋅ ε μ

Based on the same functionality from the Unicode stdlib in Julia 1.8
JuliaLang/julia#42561
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:unicode Related to unicode characters and encodings parser Language parsing and surface syntax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants