More lexer questions

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Feb 11 16:22:25 PST 2012


On Sun, Feb 12, 2012 at 01:00:07AM +0100, simendsjo wrote:
[...]
> Another thing.. Using /+ and +/ in strings gives unexpected results
> when commented out:
> /+
> auto a = "/+";
> +/
> everything from this point is commented out.
> 
> /+
> auto a = "+/";
> +/ // already terminated by the string value.
> 
> Is this a bug, or as designed? /++/ is meant to comment out code, so
> it would have been nice if it was able to handle this, but I guess
> it would complicate the lexer a great deal.

It's designed. At least according to the online specs:

	The contents of strings and comments are not tokenized.
	Consequently, comment openings occurring within a string do not
	begin a comment, and string delimiters within a comment do not
	affect the recognition of comment closings and nested "/+"
	comment openings. With the exception of "/+" occurring within a
	"/+" comment, comment openings within a comment are ignored.

		a = /+ // +/ 1;    // parses as if 'a = 1;'
		a = /+ "+/" +/ 1"; // parses as if 'a = " +/ 1";'
		a = /+ /* +/ */ 3; // parses as if 'a = */ 3;'

For commenting out code, a much better way is to use version(none){...}.


T

-- 
No! I'm not in denial!


More information about the Digitalmars-d mailing list