On Wed, 2008-10-29 at 18:35 -0700, Terence Parr wrote: > Might check your targets for correctness with escaped quotes in '...' > literals. :) > > > > Jim: does this work for '\"' as well as strings '\\"'?\
Yep. '\"\"' in an ANTLR string goes to Java as "\"\"" '""' in an ANTLR string goes to Java as "\"\"" '\u5555' goes to '\u5555' '\'\'' goes to "''" Anything that is escaped in ANTLR that does not need to be in Java is unescaped (for instance '\'\'' -> "''"). Anything that should be escaped in Java but does not need to be escaped in ANTLR is escaped (currently only ") It is not confused by '\\"', which in Java is "\\\"" and so on. C Target works in the same way except all literals are generated as 32 bit integer arrays as C target uses UTF32 internally. Jim > > > Ter > > On Oct 29, 2008, at 5:10 PM, Jim Idle wrote: > > > > > Ter, > > > > The string converter was broken, as you suspected. Basically it was > > too simplistic about coping with \" in the ANTLR string. It was > > trying to normalize \" to " first, then change all " to \". However > > this falls over with: > > > > A : '\\"'; > > > > As the \ before teh " does not belong to the ". > > > > Changed it to a StringBuffer based loop that builds a new string and > > caters for all eventualities like the C version does. See perforce > > change number 5371: > > > > > > Fix string escape parsing for Java target as follows: > > > > Anything that is escaped in ANTLR strings is passed through as > > escaped if it needs escaping in Java > > If it does not need escaping in Java, then the \ is removed, so that > > compiler errors are not given > > \" is passed on untouched > > " is passed on as \" > > \' is passed on as ' > > ' is passed on as ' > > > > Fix comment typos in CTarget.java > > > > Improve Java code generation test to include examples of above. > > > > > > Et volia, the tests pass (including the new ones). > > > > Jim > > > > PS: You might want to encourage the other target developers to do > > the same thing. > > > > > > > > >
_______________________________________________ antlr-dev mailing list [email protected] http://www.antlr.org:8080/mailman/listinfo/antlr-dev
