Merge pull request #829 from inexorabletash/string-escapes
ca65: Add string_escapes feature. Resolves #535
This commit is contained in:
@@ -65,6 +65,7 @@ static const char* const FeatureKeys[FEAT_COUNT] = {
|
||||
"underline_in_numbers",
|
||||
"addrsize",
|
||||
"bracket_as_indirect",
|
||||
"string_escapes",
|
||||
};
|
||||
|
||||
|
||||
@@ -123,6 +124,7 @@ feature_t SetFeature (const StrBuf* Key)
|
||||
case FEAT_UNDERLINE_IN_NUMBERS: UnderlineInNumbers= 1; break;
|
||||
case FEAT_ADDRSIZE: AddrSize = 1; break;
|
||||
case FEAT_BRACKET_AS_INDIRECT: BracketAsIndirect = 1; break;
|
||||
case FEAT_STRING_ESCAPES: StringEscapes = 1; break;
|
||||
default: /* Keep gcc silent */ break;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ typedef enum {
|
||||
FEAT_UNDERLINE_IN_NUMBERS,
|
||||
FEAT_ADDRSIZE,
|
||||
FEAT_BRACKET_AS_INDIRECT,
|
||||
FEAT_STRING_ESCAPES,
|
||||
|
||||
/* Special value: Number of features available */
|
||||
FEAT_COUNT
|
||||
|
||||
@@ -66,6 +66,7 @@ unsigned char DbgSyms = 0; /* Add debug symbols */
|
||||
unsigned char LineCont = 0; /* Allow line continuation */
|
||||
unsigned char LargeAlignment = 0; /* Don't warn about large alignments */
|
||||
unsigned char RelaxChecks = 0; /* Relax a few assembler checks */
|
||||
unsigned char StringEscapes = 0; /* Allow C-style escapes in strings */
|
||||
|
||||
/* Emulation features */
|
||||
unsigned char DollarIsPC = 0; /* Allow the $ symbol as current PC */
|
||||
@@ -84,4 +85,3 @@ unsigned char ForceRange = 0; /* Force values into expected range */
|
||||
unsigned char UnderlineInNumbers = 0; /* Allow underlines in numbers */
|
||||
unsigned char AddrSize = 0; /* Allow .ADDRSIZE function */
|
||||
unsigned char BracketAsIndirect = 0; /* Use '[]' not '()' for indirection */
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ extern unsigned char DbgSyms; /* Add debug symbols */
|
||||
extern unsigned char LineCont; /* Allow line continuation */
|
||||
extern unsigned char LargeAlignment; /* Don't warn about large alignments */
|
||||
extern unsigned char RelaxChecks; /* Relax a few assembler checks */
|
||||
extern unsigned char StringEscapes; /* Allow C-style escapes in strings */
|
||||
|
||||
/* Emulation features */
|
||||
extern unsigned char DollarIsPC; /* Allow the $ symbol as current PC */
|
||||
|
||||
@@ -794,6 +794,43 @@ static void ReadStringConst (int StringTerm)
|
||||
break;
|
||||
}
|
||||
|
||||
if (C == '\\' && StringEscapes) {
|
||||
NextChar ();
|
||||
|
||||
switch (C) {
|
||||
case EOF:
|
||||
Error ("Unterminated escape sequence in string constant");
|
||||
break;
|
||||
case '\\':
|
||||
case '\'':
|
||||
case '"':
|
||||
break;
|
||||
case 't':
|
||||
C = '\x09';
|
||||
break;
|
||||
case 'r':
|
||||
C = '\x0D';
|
||||
break;
|
||||
case 'n':
|
||||
C = '\x0A';
|
||||
break;
|
||||
case 'x':
|
||||
NextChar ();
|
||||
if (IsXDigit (C)) {
|
||||
char high_nibble = DigitVal (C) << 4;
|
||||
NextChar ();
|
||||
if (IsXDigit (C)) {
|
||||
C = high_nibble | DigitVal (C);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* otherwise, fall through */
|
||||
default:
|
||||
Error ("Unsupported escape sequence in string constant");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Append the char to the string */
|
||||
SB_AppendChar (&CurTok.SVal, C);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user