-
Notifications
You must be signed in to change notification settings - Fork 646
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
Tcl lexer: \ and $ interpreted as errors fix, add string escape handling, adding test case (fixing issue #2686) #2728
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just driving by, but since tests for Tcl are rather lacking, I'd suggest adding the relevant ones.
pygments/lexers/tcl.py
Outdated
@@ -77,6 +77,8 @@ def _gen_command_rules(keyword_cmds_re, builtin_cmds_re, context=""): | |||
(r'\(', Keyword, 'paren'), | |||
(r'\[', Keyword, 'bracket'), | |||
(r'\{', Keyword, 'brace'), | |||
(r'\\(.)', String.Escape), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider also line break and character escape sequences, e.g.
puts \
\164\x68\u1eed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, thank you for the comment, I have made the changes required to address the issue.
265b56b
to
0285053
Compare
Update new change:@McSinyx have pointed out that Also, his example:
has shown that my change is not considering the case of 16-bit Unicode escape sequences, 8-bit Hexadecimal escape sequences, and 8-bit Octal escape sequences properly. |
Additionally, I'm adding a new file named test_string_escape.txt, which contains examples of string escapes related to this issue. This addition will enhance our test suite, as the current test coverage for the Tcl lexer is relatively limited. |
Update posted in the comments!
Good day! I am proposing a fix for the issue #2686.
I have added some changes to the lexer so that it no longer considers backslashes as errors. The lexer will now consider
\
to beString.Escape
. Standalone$
will be considered asText
.Details changes
![Change](https://private-user-images.githubusercontent.com/108263341/338042960-9544c18f-4452-4cbd-8d1e-98a4a3b393b8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzMjkyNzgsIm5iZiI6MTcyMTMyODk3OCwicGF0aCI6Ii8xMDgyNjMzNDEvMzM4MDQyOTYwLTk1NDRjMThmLTQ0NTItNGNiZC04ZDFlLTk4YTRhM2IzOTNiOC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxOFQxODU2MThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kZjgyODZiZDc2NWU2MzhkNmI2YmM3N2Y2YjZkM2JhNzM0Zjk3YTczOTM2YTZjYTUzYjk5OWY5ZDFmMmFhYjBkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.xOH1ao68odoK3EtwruPQx5hMKBlhgMjG29C7VeI01eg)
Path: pygments/lexers/tcl.py
Result:
![Before](https://private-user-images.githubusercontent.com/108263341/338040488-6406ca04-3553-4171-8b83-397693e60622.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzMjkyNzgsIm5iZiI6MTcyMTMyODk3OCwicGF0aCI6Ii8xMDgyNjMzNDEvMzM4MDQwNDg4LTY0MDZjYTA0LTM1NTMtNDE3MS04YjgzLTM5NzY5M2U2MDYyMi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRS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0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.APXHQexTw7QeZrr7TnbGkNmDq6PsBqafKFWZWKmXz6A)
Tokens:
Please inform me if any alterations or modifications are necessary. I would greatly appreciate any feedback or comments!