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 NameError on @ + UPPERCASE token in Objective-C #1406

Merged
merged 2 commits into from Jan 25, 2020

Conversation

pocke
Copy link
Contributor

@pocke pocke commented Jan 24, 2020

I got an error when highlighting @FOO as Objective-C.
This pull request will fix the problem.

$ ruby -Ilib -rrouge -e 'p Rouge.highlight("@FOO", "objective_c", "html")'
Traceback (most recent call last):
        18: from -e:1:in `<main>'
        17: from /path/to/rouge/lib/rouge.rb:32:in `highlight'
        16: from /path/to/rouge/lib/rouge/formatter.rb:46:in `format'
        15: from /path/to/rouge/lib/rouge/formatter.rb:74:in `format'
        14: from /path/to/rouge/lib/rouge/formatters/html.rb:12:in `stream'
        13: from /path/to/rouge/lib/rouge/formatters/html.rb:12:in `each'
        12: from /path/to/rouge/lib/rouge/formatter.rb:58:in `filter_escapes'
        11: from /path/to/rouge/lib/rouge/formatter.rb:58:in `each'
        10: from /path/to/rouge/lib/rouge/lexer.rb:451:in `lex'
         9: from /path/to/rouge/lib/rouge/lexer.rb:461:in `continue_lex'
         8: from /path/to/rouge/lib/rouge/regex_lexer.rb:272:in `stream_tokens'
         7: from /path/to/rouge/lib/rouge/regex_lexer.rb:291:in `step'
         6: from /path/to/rouge/lib/rouge/regex_lexer.rb:291:in `each'
         5: from /path/to/rouge/lib/rouge/regex_lexer.rb:294:in `block in step'
         4: from /path/to/rouge/lib/rouge/regex_lexer.rb:291:in `step'
         3: from /path/to/rouge/lib/rouge/regex_lexer.rb:291:in `each'
         2: from /path/to/rouge/lib/rouge/regex_lexer.rb:309:in `block in step'
         1: from /path/to/rouge/lib/rouge/regex_lexer.rb:309:in `instance_exec'
/path/to/rouge/lib/rouge/lexers/objective_c/common.rb:47:in `block (2 levels) in extended': uninitialized constant Rouge::Lexers::ObjectiveCCommon::Error (NameError)
Did you mean?  IOError
               Errno

I guess this error is related to #1378. Because this PR introduced the base variable.

By the way, I'm not sure I should write test code for this fix.
I guess we can add it to spec/visual/samples/objective_c, but I don't know Objective-C syntax.
And it is highlighted as "Error", so I'm wondering if the visual test should contain it.

Please tell me how to write a test if it's necessary 🙇‍♂️

```bash
$ ruby -Ilib -rrouge -e 'p Rouge.highlight("@foo", "objective_c", "html")'
Traceback (most recent call last):
        18: from -e:1:in `<main>'
        17: from /path/to/rouge/lib/rouge.rb:32:in `highlight'
        16: from /path/to/rouge/lib/rouge/formatter.rb:46:in `format'
        15: from /path/to/rouge/lib/rouge/formatter.rb:74:in `format'
        14: from /path/to/rouge/lib/rouge/formatters/html.rb:12:in `stream'
        13: from /path/to/rouge/lib/rouge/formatters/html.rb:12:in `each'
        12: from /path/to/rouge/lib/rouge/formatter.rb:58:in `filter_escapes'
        11: from /path/to/rouge/lib/rouge/formatter.rb:58:in `each'
        10: from /path/to/rouge/lib/rouge/lexer.rb:451:in `lex'
         9: from /path/to/rouge/lib/rouge/lexer.rb:461:in `continue_lex'
         8: from /path/to/rouge/lib/rouge/regex_lexer.rb:272:in `stream_tokens'
         7: from /path/to/rouge/lib/rouge/regex_lexer.rb:291:in `step'
         6: from /path/to/rouge/lib/rouge/regex_lexer.rb:291:in `each'
         5: from /path/to/rouge/lib/rouge/regex_lexer.rb:294:in `block in step'
         4: from /path/to/rouge/lib/rouge/regex_lexer.rb:291:in `step'
         3: from /path/to/rouge/lib/rouge/regex_lexer.rb:291:in `each'
         2: from /path/to/rouge/lib/rouge/regex_lexer.rb:309:in `block in step'
         1: from /path/to/rouge/lib/rouge/regex_lexer.rb:309:in `instance_exec'
/path/to/rouge/lib/rouge/lexers/objective_c/common.rb:47:in `block (2 levels) in extended': uninitialized constant Rouge::Lexers::ObjectiveCCommon::Error (NameError)
Did you mean?  IOError
               Errno
```

```bash
$ ruby -Ilib -rrouge -e 'p Rouge.highlight("@foo", "objective_c", "html")'
"<span class=\"err\">@foo</span>"
```
@pyrmont pyrmont self-assigned this Jan 24, 2020
@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Jan 24, 2020
@pyrmont
Copy link
Contributor

pyrmont commented Jan 24, 2020

@pocke Thanks for taking the time to track down the bug! And yep, just an example in the visual sample is a good way to test this kind of thing. The fact that it highlights as an error is no problem at all. (I've added such an example and pushed to your repo.)

How does it look to you now?

@pyrmont pyrmont added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Jan 24, 2020
@pocke
Copy link
Contributor Author

pocke commented Jan 25, 2020

Thanks for adding the test code!
It looks good to me. 👍

@pyrmont pyrmont merged commit 2472b40 into rouge-ruby:master Jan 25, 2020
@pyrmont pyrmont removed the author-action The PR has been reviewed but action by the author is needed label Jan 25, 2020
@pocke pocke deleted the fix-objective-c-at-CAPITAL_CHARS branch January 26, 2020 04:15
@pyrmont
Copy link
Contributor

pyrmont commented Jan 26, 2020

@pocke Thanks again for the PR. I should have mentioned that this will go out as part of v3.16.0. That's scheduled for release on Tuesday 11 February :)

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