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

Regex for python shebang is incorrect #945

Closed
FalkF opened this issue Jun 18, 2018 · 4 comments · Fixed by #1172
Closed

Regex for python shebang is incorrect #945

FalkF opened this issue Jun 18, 2018 · 4 comments · Fixed by #1172

Comments

@FalkF
Copy link

FalkF commented Jun 18, 2018

Using a shebang with a specific python subversion:

#!/usr/bin/env python3.6

breaks the syntax highlighting for the file.
It has probably to do with this regex (example) as pointed out by Mark Fletcher in the Gitlab Issue.

@julp
Copy link
Contributor

julp commented Jun 18, 2018

Hi,

ok, I think I've understood the issue and that you're right, the regex should be something like: /pythonw?([32](\.\d)?)?/ because the minor version only apply to versions 2.X, not 3 (/pythonw?(3|2(\.\d)?)?/ is different to /pythonw?((3|2)(\.\d)?)?/).

Can you test with /pythonw?([32](\.\d)?)?/ instead of /pythonw?(3|2(\.\d)?)?/ and let us know, please?

@FalkF
Copy link
Author

FalkF commented Jun 19, 2018

Thanks for looking into this. Your new regex seems to do the job. Sadly I have no way to verify it fast, since I encountered the issue in gitlabs snippets and am not familar with the workflow involved. I can verify it next weekend tho.

@dblessing
Copy link
Collaborator

I think we could even simplify things further. Rouge needs to highlight well, but it doesn't have to be always 100% syntactically correct for a language. So, for instance, we could do something like:

  • /pythonw?(\d(\.\d)?)?/ - Would match any python<digit>.<digit>.
  • /pythonw?.*/ - Even more simplistic. If it starts with python or pythonw it's probably a safe bet.

pyrmont added a commit to pyrmont/rouge that referenced this issue Jun 12, 2019
The Python lexer only supported minor version numbers for shebangs
involving `python2`. Minor versions of Python 3 should also be included.
This commit corrects that problem and supports minor version numbers
higher than 9. This fixes rouge-ruby#945.
@pyrmont
Copy link
Contributor

pyrmont commented Jun 12, 2019

@FalkF @julp I think PR #1172 fixes the problem but please let me know if you spot a mistake.

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 a pull request may close this issue.

4 participants