From 0c8f23453e5ec345fbf9063092c933a745cd5672 Mon Sep 17 00:00:00 2001 From: Zeex Date: Wed, 1 Jan 2014 03:45:33 +0700 Subject: [PATCH] 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"); } --- source/compiler/sc2.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 666dede..0d1fa63 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -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; }