<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I am looking for some insights / advice on the best way to handle what has temporarily become something of a recusrsive horror story this afternoon! In my transpiler, there may or may not be strings containing C style printf() format controls. This caught me out<div class=""><br class=""></div><div class=""><font face="FreeMono" class="">Uncaught Mercury exception:</font></div><div class=""><div class=""><font face="FreeMono" class="">Software Error: string.format: The first conversion specifier, which uses specifier character `s', is missing its input.</font></div></div><div class=""><br class=""></div><div class="">once so I implemented:</div><div class=""><div class=""><br class=""></div><div class=""><font face="FreeMono" class=""> % C_String :: Escapes any % with %% in the string.<br class=""> %<br class="">:- func c_string(ps::in) = (string::out).<br class=""><br class="">c_string(ps(_,X)) = string.format("""%s""", [s(c_string_(X))]).<br class=""><br class=""> % TODO: is this a typeclasss ie. things to be escaped ??<br class="">:- func c_string_(string::in) = (string::out).</font></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Which works but....as I tested my way through, the problem is compounded by the recursive nature of the rendering stage, resulting in strings like this:</div><div class=""><br class=""></div><div class=""><font face="FreeMono" class=""> printf("Hello %%%%%s", "World");</font></div><div class=""><br class=""></div><div class="">caused by each successive handler making sure it escapes strings before returning up the stack. </div><div class="">When I print the code out I am using string.format() and of course that blew up mightily until I started using %%s in --my-- strings of source code.</div><div class=""><br class=""></div><div class="">I currently use stream.string_writer.format() for generating the final output.</div><div class=""><br class=""></div><div class="">I wondered what strategy the Mercury compiler uses as it must have addressed the same issue at some point? I've tried reading the code to no avail! I am rethinking through my approach, so far it has all worked great but then.. strings with %s and any other string escape for the C grade is going to have the same issues.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Sean.</div><div class=""><br class=""></div></div></body></html>