Branch: Tag:

2018-10-31

2018-10-31 14:06:08 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Cpp: Improved white-space fidelity.

White space characters that aren't '\r' are now kept unmodified
in the output. '\r' characters are removed if they are followed
immediately by a '\n' character, and are otherwise kept.

This change makes cpp() keep indentations, and improves the
readability of the output from Tools.Standalone.precompile.

9882:   test_eq([[cpp("#define FOO(X)\nFOO BAR")]],"\nFOO BAR")   test_eq([[cpp("#define F 'F'\nF")]],"\n'F'")   test_eq([[cpp("#define MAX(X,Y) ((X)>(Y)?(X):(Y))\n#define MAX3(X,Y,Z) MAX(MAX(X,Y),Z)\nMAX3(1,2,3)")]],"\n\n(( (( 1 )>( 2 )?( 1 ):( 2 )) )>( 3 )?( (( 1 )>( 2 )?( 1 ):( 2 )) ):( 3 ))") - test_eq([[cpp("foo\xfeff""bar \xfeff gazonk")]],[[cpp("foobar gazonk")]]) + test_eq([[cpp("\t foo\xfeff""bar \xfeff gazonk")]], +  [[cpp("\t foobar gazonk")]]) + test_eq([[cpp("\t foobar gazonk\n")]], "\t foobar gazonk\n")   test_eq([[cpp("#define A(X) #X\n#define B(Y) A(Y)\nB(foo)")]],    "\n\n \"foo\" ")   test_eq([[cpp("#define FOO(X) X\nFOO(\"\\\n\")\n")]], "\n\n \"\" \n"); - test_eq([[cpp("#define FOO(X) X\r\nFOO(\"\\\r\n\")\r\n")]], "\n\n \"\" \n" /* Note: Added extra spaces for \r. */); + test_eq([[cpp("#define FOO(X) X\r\nFOO(\"\\\r\n\")\r\n")]], "\n\n \"\" \n");   test_equal([[compile_string("#define FOO(X) X\nstring s=FOO(\"\\\n\\\n\");\nmixed f() {return ({__LINE__, backtrace()[-1][1]});}\n")()->f()]], ({5, 5}));   test_equal([[compile_string("#define FOO(X) X\nstring s=FOO(#\"\n\n\");\nmixed f() {return ({__LINE__, backtrace()[-1][1]});}\n")()->f()]], ({5, 5}));   test_equal([[