-
Notifications
You must be signed in to change notification settings - Fork 165
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
Java serialization (pretty print) of strings does not escape special chars #449
Comments
This issue exists in all non-FP backends. The Haskell backend produces the following printer for strings: printString :: String -> Doc
printString s = doc (showChar '"' . concatS (map (mkEsc '"') s) . showChar '"')
mkEsc :: Char -> Char -> ShowS
mkEsc q = \case
s | s == q -> showChar '\\' . showChar s
'\\' -> showString "\\\\"
'\n' -> showString "\\n"
'\t' -> showString "\\t"
s -> showChar s The Ocaml backend produces: let prtString (_:int) (s:string) : doc = render ("\"" ^ String.escaped s ^ "\"") From the docs: https://v2.ocaml.org/api/String.html
Java produces only this: private static void printQuoted(String s) { render("\"" + s + "\""); } CPP this: void PrintAbsyn::visitString(String s)
{
bufAppend('\"');
bufAppend(s);
bufAppend('\"');
bufAppend(' ');
} |
While working on this issue, I found that two backends do not lex escape characters properly: |
This is a precaution, should not happen unless there are other bugs (e.g. the one introduced in d5ba1ac).
This is a precaution, should not happen unless there are other bugs (e.g. the one introduced in d5ba1ac).
thank you |
While predefined basic type
String
in Haskell backend serialization escapes special chars in strings (like"line1\nline2"
) in Java it does not (and output is"line1
line2"
).The text was updated successfully, but these errors were encountered: