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

Support fat comma in Perl lexer #1553

Merged
merged 9 commits into from
Jul 14, 2020

Conversation

pyrmont
Copy link
Contributor

@pyrmont pyrmont commented Jun 19, 2020

The => operator (sometimes called the 'fat comma') is an operator in Perl that causes the identifier to the immediate left of the fat comma to be treated as if it were a string. See additional explanation in the answers to this StackOverflow question.

This fixes #1164.

@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Jun 19, 2020
@pyrmont pyrmont self-assigned this Jun 19, 2020
@pyrmont
Copy link
Contributor Author

pyrmont commented Jun 19, 2020

@miparnisari How does this look to you?

@pyrmont
Copy link
Contributor Author

pyrmont commented Jul 5, 2020

@jneen This PR now correctly lexes the following:

# fat commas                                  
use constant EMPTY_SPACE => ' ';
my %h = ( FOO => 23 );
$text = format_text({FOO => 23, BAR => 30});
foo(
  sub # comment
      # second comment
    => 1
)

Screen Shot 2020-07-05 at 2 46 44 pm

It does this using a regular expression similar to the one you suggested:

rule(/(?=[a-z_]\w*(\s*#.*)*\s*=>)/i) { push :fat_comma }

This looks good to me but if you can think of any issues, let me know.

@pyrmont
Copy link
Contributor Author

pyrmont commented Jul 5, 2020

@jneen I realised that the previous rule would match comments that contained a fat arrow. This variation fixes that:

rule(/(?=[a-z_]\w*(\s*#.*\n)*\s*=>)/i) { push :fat_comma }

@pyrmont pyrmont merged commit 32186d5 into rouge-ruby:master Jul 14, 2020
@pyrmont pyrmont removed the needs-review The PR needs to be reviewed label Jul 14, 2020
@pyrmont pyrmont deleted the bugfix.perl-fat-comma branch July 14, 2020 15:27
mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
The `=>` operator (sometimes called the 'fat comma') is an operator in
Perl that causes the identifier to the immediate left of the fat comma
to be treated as if it were a string. This commit adds support for it
using a simple lookahead heuristic.
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.

When "sub" is used as key of a Perl hash, error tokens are rendered
1 participant