1

Closed

Error with escape characters

description

module hw; //line 1
 
import System;
 
void main()
{
string s = "\\"; //line 7
Console.WriteLine(sys(s));
}
 
//line 11. last line
 
C:\d\dnet\projects\hw>dnet hw.d
hw.d(12): unterminated string constant starting at hw.d(7)
hw.d(12): semicolon expected, not 'EOF'
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
hw.d(12): found 'EOF' instead of statement
 
BTW why has this code changed so much from the dmd's front end?
Closed Jun 18, 2009 at 7:14 AM by cristiv

comments

cristiv wrote May 21, 2009 at 6:44 PM

Bummer, I introduced this one with the last check in.

To answer your question: the native compiler replaces escaped characters with their ascii codes in the generated string, for example \n turns into a 10.
The .NET back-end emits textual IL, so the escape sequences should be left alone and simply passed through (for example just feed "Hello world\n" to ILASM).

Now the double-quote is an interesting case, because the native compiler handles it as string beginning or ending (since \" is handled elsewhere by the escaping logic). My attempt to fix this was to check whether the preceding character is a \, but you found a good counter example :( I should not check in things after midnight...

cristiv wrote May 22, 2009 at 1:54 AM

Checked in fix, see changeset 19025.

wrote Jun 18, 2009 at 7:14 AM

wrote Feb 14, 2013 at 12:52 AM

wrote May 16, 2013 at 5:01 AM