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

Fix Crystal floor division becoming regex literals #1639

Merged
merged 2 commits into from
Dec 5, 2020
Merged

Fix Crystal floor division becoming regex literals #1639

merged 2 commits into from
Dec 5, 2020

Conversation

rymiel
Copy link
Contributor

@rymiel rymiel commented Nov 28, 2020

Currently, the crystal floor division operator // is not lexed properly when :root is the topmost thing on the stack (default state). It becomes a regular division followed by a regex literal. This literal will span multiple lines until met by another /, which can make large parts of a file become seemingly unformatted.

This change adds // as an operator next to **, as they seem similar. This shouldn't affect actual regex literals or empty regex literals (which are also //) though I haven't tested it much with real-code examples

@pyrmont pyrmont merged commit 9ceab19 into rouge-ruby:master Dec 5, 2020
@pyrmont
Copy link
Contributor

pyrmont commented Dec 5, 2020

@rymiel Thanks for adding this. It will be included in the next release of Rouge that will come out on Tuesday or Wednesday of next week (depending on your time zone).

In terms of its impact on regex literals, it looked good to me but, to be honest, the visual sample for Crystal is really lacking in coverage so it's difficult to tell. I'll open a separate PR that adds a more comprehensive set of examples (based on those in Python's Pygments syntax highlighting library). Thanks again!

@rymiel
Copy link
Contributor Author

rymiel commented Dec 5, 2020 via email

mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
Currently, Crystal's floor division operator (`//`) is not lexed
properly when `:root` is the topmost state in the stack. Instead, Rouge
lexs it as the regular division operator (`/`) followed by a regex
literal.

This commit adds `//` to the rule that matches `**` and other repeated
operator characters. It also reorders some of these operators to ensure
that they are matched correctly.

Co-authored-by: Michael Camilleri <mike@inqk.net>
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.

None yet

2 participants