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

parser/lexer: correct ID_Start & ID_Continue checks #524

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

filips
Copy link
Contributor

@filips filips commented Jun 10, 2024

unicode.IsLetter and unicode.IsDigit will not return the complete set of ID_Start and ID_Continue characters defined here: https://www.unicode.org/reports/tr31/.

Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

Looks reasonable but lets get some tests which exercise this.

@filips filips force-pushed the lexer-unicode-start-continue branch from fc0cdaf to a14eb3c Compare June 10, 2024 23:50
@filips filips requested a review from stevenh June 10, 2024 23:51
@filips
Copy link
Contributor Author

filips commented Jun 10, 2024

Looks reasonable but lets get some tests which exercise this.

I added a few tests for the areas where the allowed character sets differ. Please let me know if you want me to add further tests.

@filips filips force-pushed the lexer-unicode-start-continue branch from a14eb3c to c1a6c0a Compare June 11, 2024 15:16
@filips
Copy link
Contributor Author

filips commented Jun 11, 2024

@stevenh Linter warnings should be fixed now

Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

Thanks for this, just a minor nit and then good to go.

parser/lexer.go Outdated
unicode.Pattern_White_Space,
}

func UnicodeIDStart(r rune) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a minor tweak can we unexport these:

Suggested change
func UnicodeIDStart(r rune) bool {
func unicodeIDStart(r rune) bool {

parser/lexer.go Outdated
return unicode.In(r, includeIDStart...)
}

func UnicodeIDContinue(r rune) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func UnicodeIDContinue(r rune) bool {
func unicodeIDContinue(r rune) bool {

parser/lexer.go Outdated
func isDigit(chr rune, base int) bool {
return digitValue(chr) < base
}

func isIdentifierStart(chr rune) bool {
return chr == '$' || chr == '_' || chr == '\\' ||
'a' <= chr && chr <= 'z' || 'A' <= chr && chr <= 'Z' ||
chr >= utf8.RuneSelf && unicode.IsLetter(chr)
chr >= utf8.RuneSelf && UnicodeIDStart(chr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
chr >= utf8.RuneSelf && UnicodeIDStart(chr)
chr >= utf8.RuneSelf && unicodeIDStart(chr)

parser/lexer.go Outdated
}

func isIdentifierPart(chr rune) bool {
return chr == '$' || chr == '_' || chr == '\\' ||
'a' <= chr && chr <= 'z' || 'A' <= chr && chr <= 'Z' ||
'0' <= chr && chr <= '9' ||
chr >= utf8.RuneSelf && (unicode.IsLetter(chr) || unicode.IsDigit(chr))
chr >= utf8.RuneSelf && UnicodeIDContinue(chr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
chr >= utf8.RuneSelf && UnicodeIDContinue(chr)
chr >= utf8.RuneSelf && unicodeIDContinue(chr)

@filips filips force-pushed the lexer-unicode-start-continue branch from c1a6c0a to 8237717 Compare June 11, 2024 16:20
@filips
Copy link
Contributor Author

filips commented Jun 11, 2024

Thanks for this, just a minor nit and then good to go.

Sure thing, I pushed with the methods unexported

@stevenh stevenh merged commit d4edd51 into robertkrimen:master Jun 12, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants