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

Fixed Printing of Escape Sequences #1500

Merged
merged 3 commits into from
Feb 5, 2023
Merged

Fixed Printing of Escape Sequences #1500

merged 3 commits into from
Feb 5, 2023

Conversation

gptsarthak
Copy link
Contributor

Fixes #1473
Modified LPython semantics, C and Julia backend so that they do not print the backslash even after it is recognized.

When asked to print the following string:

s: str
s = 'I said \'Wow\' '
print(s)

LPython now prints:
I said 'Wow'

@@ -8,5 +8,5 @@ class a:
" ())] [])) (Expr (ConstantStr "
"\\"
" ())) (Expr (ConstantStr "
'\\'
'\'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked against CPython and this change seems to be correct.

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good, thanks for fixing it! I left some minor formatting comments.

Co-authored-by: Ondřej Čertík <ondrej@certik.us>
@certik certik merged commit 5ba2a2a into lcompilers:main Feb 5, 2023
@certik
Copy link
Contributor

certik commented Feb 5, 2023

Thanks @gptsarthak for the fix!

@faze-geek
Copy link
Contributor

The obvious edge case to be checked here was for " " instead of ' ' :)
Just as I was writing this comment the PR was merged.

def main():
	print("I said \"hi\" ")

main()

(lp) C:\Users\kunni\lpython>python try.py
I said "hi"

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
I said \"hi\"

@gptsarthak Shouldn't be difficult to add this. Thanks !

@gptsarthak
Copy link
Contributor Author

Hey @faze-geek thanks for pointing it out! Now that this PR is merged, should I make another PR after adding it?

@faze-geek
Copy link
Contributor

Hey @faze-geek thanks for pointing it out! Now that this PR is merged, should I make another PR after adding it?

Yes, you can do that!
I noticed you made the changes from your main. It's better to always make a new branch instead.

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.

Escape sequence recognized but not ignored in printing.
3 participants