-
Notifications
You must be signed in to change notification settings - Fork 717
fix: quoting single quote Char (''') #8742
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
Conversation
nomeata
left a comment
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.
LGTM, but I'll let someone from the library team press the button.
|
Mathlib CI status (docs):
|
|
I feel like single quotes within double quotes or the other way round shouldn't need to escaped. Also (unrelated) the way it currently works is that it allocates a new string for every character when trying to quote, maybe we could instead use a function |
|
So something like def String.pushQuotedChar (s : String) (c : Char) (quote : Char := '"') : String :=
if c = '\n' then s.push '\\' |>.push 'n'
else if c = '\t' then s.push '\\' |>.push 't'
else if c = '\\' ∨ c = quote then s.push '\\' |>.push c
else if c.toNat <= 31 ∨ c = '\x7f' then smallCharToHex s c
else s.push c
where
smallCharToHex (s : String) (c : Char) : String :=
let n := Char.toNat c
let d2 := n / 16
let d1 := n % 16
s.push '\\' |>.push 'x' |>.push (Nat.digitChar d2) |>.push (Nat.digitChar d1) |
As Rob says, the change to string literals is probably not great.
Co-authored-by: Kyle Miller <[email protected]>
This PR fixes a bug where the single-quote character `Char.ofNat 39` would delaborate as `'''`, which causes a parse error if pasted back in to the source code. --------- Co-authored-by: Kyle Miller <[email protected]>
This PR fixes a bug where the single-quote character `Char.ofNat 39` would delaborate as `'''`, which causes a parse error if pasted back in to the source code. --------- Co-authored-by: Kyle Miller <[email protected]>
This PR fixes a bug where the single-quote character
Char.ofNat 39would delaborate as''', which causes a parse error if pasted back in to the source code.