Skip to content

Require whitespace before as in to/downto labels #1085

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

Merged
merged 3 commits into from
Apr 28, 2025

Conversation

mediremi
Copy link
Contributor

@mediremi mediremi commented Apr 28, 2025

The grammar rule RE_TO_DOWNTO_AS_LABELS contains two patterns for ensuring that labelled arguments with names to and downto are highlighted as variables and not keywords.

The second pattern, (to|downto)\s*(as), is supposed to match cases like (~to as to2) => ..., but was also matching e.g. ~toast.

I've fixed this by changing \s* to \s+.

Before After
image image

The `RE_TO_DOWNTO_AS_LABELS` rule previously used `\s*` between `(to|downto)` and `(as)`,
allowing zero spaces and accidentally matching identifiers like "toast".

Change the pattern to `\s+` so that an actual space is required, preventing spurious `as`
highlighting inside identifiers.
@mediremi
Copy link
Contributor Author

I've also prefixed these patterns with ~ to make it clearer that they're targeting labelled arguments as well as to narrow their scope.

Copy link
Member

@DZakh DZakh left a comment

Choose a reason for hiding this comment

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

Nice catch 👍

@zth
Copy link
Collaborator

zth commented Apr 28, 2025

Great stuff! @mediremi could you add a changelog?

@mediremi
Copy link
Contributor Author

@zth changelog entry added

@zth
Copy link
Collaborator

zth commented Apr 28, 2025

@mediremi awesome. Thank you for your contribution! 🎉

@zth zth merged commit 1bf87b3 into rescript-lang:master Apr 28, 2025
6 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.

3 participants