Fix compile error with string literals in ternary operator

The ':' symbol was not recognized as a separator in stringize mode
so you always got a weird compile error with a code like this:

(condition) ? "yes : "no"

error 001: expected token: "-string end-", but found "-identifier-"

See 2) here: http://forum.sa-mp.com/showthread.php?t=355877

Test code:

native print(const s[]);

main() {
	new a = 5;
	print((a == 5) ? "is five" : !"is not five");
	print((a != 5) ? !"is not five" : "is five");
}
This commit is contained in:
Zeex 2014-01-01 03:45:33 +07:00
parent 4831cb76a3
commit 0c8f23453e

View File

@ -1432,7 +1432,7 @@ static const unsigned char *skippgroup(const unsigned char *string)
break;
default:
assert(0);
close='\0'; /* only to avoid a compiler warning */
close='\0'; /* only to avoid a compiler warning */
}/* switch */
string++;
@ -1745,7 +1745,8 @@ static const unsigned char *unpackedstring(const unsigned char *lptr,int *flags)
lptr--;
instring=1;
*flags |= STRINGIZE;
} else if (*lptr==')' || *lptr==',' || *lptr=='}' || *lptr==';' || *lptr=='\r' || *lptr=='\n') {
} else if (*lptr==')' || *lptr==',' || *lptr=='}' || *lptr==';' |
*lptr==':' || *lptr=='\r' || *lptr=='\n') {
break;
} else if (*lptr!=' ' && *lptr!='\t') {
error(1,"-string end-","-identifier-");
@ -1767,7 +1768,8 @@ static const unsigned char *unpackedstring(const unsigned char *lptr,int *flags)
lptr=stringize+1;
*flags &= ~STRINGIZE;
continue;
} else if (*stringize==',' || *stringize==')' || *stringize=='}' || *stringize==';') { /* end */
} else if (*stringize==',' || *stringize==')' || *stringize=='}' ||
*stringize==';' || *stringize==':') { /* end */
lptr=stringize;
break;
} else if (*stringize=='\0') {
@ -1785,8 +1787,9 @@ static const unsigned char *unpackedstring(const unsigned char *lptr,int *flags)
litadd(litchar(&lptr,*flags | UTF8MODE)); /* litchar() alters "lptr" */
} /* while */
litadd(0);
if (*lptr==',' || *lptr==')' || *lptr=='}' || *lptr==';' || *lptr=='\n' || *lptr=='\r')
if (*lptr==',' || *lptr==')' || *lptr=='}' || *lptr==';' ||
*lptr==':' || *lptr=='\n' || *lptr=='\r')
lptr=stringize; /* backtrack to end of last string for closing " */
return lptr;
}
@ -1797,7 +1800,7 @@ static const unsigned char *packedstring(const unsigned char *lptr,int *flags)
ucell val,c;
unsigned char *stringize;
int instring=1;
if (*flags & STRINGIZE)
if (*flags & STRINGIZE)
while (*lptr==' ' || *lptr=='\t')
lptr++;
@ -1816,7 +1819,8 @@ static const unsigned char *packedstring(const unsigned char *lptr,int *flags)
lptr--;
instring=1;
*flags |= STRINGIZE;
} else if (*lptr==')' || *lptr==',' || *lptr=='}' || *lptr==';' || *lptr=='\r' || *lptr=='\n') {
} else if (*lptr==')' || *lptr==',' || *lptr=='}' || *lptr==';' ||
*lptr==':' || *lptr=='\r' || *lptr=='\n') {
break;
} else if (*lptr!=' ' && *lptr!='\t') {
error(1,"-string end-","-identifier-");
@ -1838,7 +1842,8 @@ static const unsigned char *packedstring(const unsigned char *lptr,int *flags)
lptr=stringize+1;
*flags &= ~STRINGIZE;
continue;
} else if (*stringize==',' || *stringize==')' || *stringize=='}' || *stringize==';') { /* end */
} else if (*stringize==',' || *stringize==')' || *stringize=='}' |
*stringize==';' || *stringize==':') { /* end */
lptr=stringize;
break;
} else if (*stringize=='\0') {
@ -1869,7 +1874,8 @@ static const unsigned char *packedstring(const unsigned char *lptr,int *flags)
else
litadd(0); /* add full cell of zeros */
if (*lptr==',' || *lptr==')' || *lptr=='}' || *lptr==';' || *lptr=='\n' || *lptr=='\r')
if (*lptr==',' || *lptr==')' || *lptr=='}' || *lptr==';' ||
*lptr==':' || *lptr=='\n' || *lptr=='\r')
lptr=stringize; /* backtrack to end of last string for closing " */
return lptr;
}