From: Ammar Ali Date: 2010-11-23T20:39:55+09:00 Subject: Re: gsub and backslashes --001636c5a9381731b20495b6cead Content-Type: text/plain; charset=UTF-8 On Tue, Nov 23, 2010 at 11:17 AM, Robert Klemme wrote: > On Mon, Nov 22, 2010 at 10:06 PM, Ammar Ali wrote: > > > > I guess I took issue with the word tolerance. I don't think of lexers > > and parsers as tolerant. They are quite ruthless and dictatorial. It's > > either their way, or their way in a way one did not expect. :) > > :-) But rules can be made to allow for some flexibility (just think > of method calls with or without brackets in Ruby). That's a good example, and I know understand what you meant by tolerance. > >> This is not an "escaped newline" but merely a backslash followed by > >> character "n". Whether that is considered "escaped" in some way depends > on > >> the code that processes this string. If at all this is an escaped "n". > :) > > > > You are correct sir. For someone who was nitpicking, I misspoke. :) > > No problem. Apparently we both enjoy nitpicking. :-)) :) > I agree, but this long "heritage" that goes back to the 60s is > > probably very hard to shake. Maybe a new language can break away from > > it. > > In Ruby's case the heritage does not go back to the sixties but rather > to the nineties (1997) if I am not mistaken. I was thinking of C, which I believe introduced these escapes, but I'm not sure. > > Out of curiosity, what could these beasts be replaced with? Constants? > > I'd leave everything as is except drop special cases like '\1' (this > would either be an octal escape as in a double quoted string or rather > just "1"). In single quoted strings only ' would be special if > preceded by a backslash. In double quoted strings I would have those > characters which are special currently (", n, r, a, t and probably > others I'm not thinking of right now). I am undecided whether I would > make all others errors or tolerant (e.g. "\z" would either by a syntax > error or just "z"). I have a slight tendency to the more strict > variant though because otherwise people might be left wondering what > \z means when it is just "z"; also, this would help detect typing > errors (maybe someone wanted to type "\t" which is just a key away in > my German keyboard). I like the idea of treating unnecessary escapes as syntax errors, or at least warnings. I see this a lot in regular expressions, especially in character sets. Characters that don't need to be escaped (like ? and *) are preceded with a backslash, just to be safe I guess, making for a harder to code, as you noted. Regards, Ammar --001636c5a9381731b20495b6cead--