X Tutup
The Wayback Machine - https://web.archive.org/web/20201206081257/https://github.com/MagicStack/MagicPython/issues/114
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

Raw string highlighting #114

Closed
jcrmatos opened this issue Dec 4, 2017 · 7 comments
Closed

Raw string highlighting #114

jcrmatos opened this issue Dec 4, 2017 · 7 comments

Comments

@jcrmatos
Copy link

@jcrmatos jcrmatos commented Dec 4, 2017

Environment data

VS Code version: 1.18.1
Python Extension version: 0.80.0
Python Version: CPython 3.5.4 32b
OS and version: Windows 7 Pro SP1 x64

Actual behavior

I have the following line

fops.save_txt(environ['SystemRoot'] + r'\explorer.exe '
                      + bdexp.EXPORTS_DIR,
                      bpl.PROGS_TO_LAUNCH_PN)

and the r and \e shows in blue with the first ' and xplorer.exe ' shows in brown(?).
My point is that it isn't recognizing it as a string (raw in this case) like it does with the previous 'SystemRoot' which shows all brown(?) and the Intellisense recognizes as a string.

Expected behavior

It should show r'\explorer.exe ' all brown(?) and recognize it as a string.

I reported this first in VS Code Python at microsoft/vscode-python#337 (comment) but Brett Cannon told me to open it here because their syntax highlighting depends on MagicPython.

Thanks,

JM

@elprans
Copy link
Member

@elprans elprans commented Dec 4, 2017

This is a feature.

foo = r'\nregexp'  # this is parsed as a "regexp-string"
bar = R'\nregexp'  # this is parsed as a raw string
@elprans elprans closed this Dec 4, 2017
@jcrmatos
Copy link
Author

@jcrmatos jcrmatos commented Dec 4, 2017

Hello,

I'm sorry but I can't find that difference in the CPython spec.
In fact what I find in both Py2 and Py3 official docs is:

Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters.

...

Unless an 'r' or 'R' prefix is present, escape sequences in string and bytes literals are interpreted according to rules similar to those used by Standard C.

Please reconsider changing MagicPython behavior to be in sync with CPython.

Thanks,

JM

@jcrmatos
Copy link
Author

@jcrmatos jcrmatos commented Dec 4, 2017

Hello,

I forgot to include the CPython official docs links:
https://docs.python.org/3/reference/lexical_analysis.html
and
https://docs.python.org/2/reference/lexical_analysis.html

Thanks,

JM

@1st1
Copy link
Member

@1st1 1st1 commented Dec 4, 2017

Please reconsider changing MagicPython behavior to be in sync with CPython.

You're correct—there's no "regex" literal in Python, and r"string" is the same thing as R"string". However, TextMate originally, and Sublime Text later both highlighted r"strings" as regular expressions for years, and a lot of users expect MagicPython to do the same, as it's positioned as a "drop in replacement" for Python syntax highlighters in those editors. Therefore, unfortunately, we are not going to reconsider having this feature in MagicPython.

@jcrmatos
Copy link
Author

@jcrmatos jcrmatos commented Dec 4, 2017

Hello,

I understand.
Can I ask you please to add a Settings option to disable that behavior?

Thanks,

JM

@1st1
Copy link
Member

@1st1 1st1 commented Dec 4, 2017

Generally syntax highlighters don't have settings panels and aren't configurable. We had an idea how to do that for MP, but don't have time to pursue it. So unfortunately there's no ETA for this feature.

@vors

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.
X Tutup