Clean up lexer.c

Remove some hardcoded character values
Allow tabs to be used for line continuations
This commit is contained in:
ISSOtm
2019-09-05 15:22:24 +02:00
parent 65fc42cce5
commit 6fbb25c0da

View File

@@ -275,17 +275,15 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
mem += 2; mem += 2;
} else { } else {
/* LF CR and CR LF */ /* LF CR and CR LF */
if (((mem[0] == 10) && (mem[1] == 13)) if (((mem[0] == '\n') && (mem[1] == '\r'))
|| ((mem[0] == 13) && (mem[1] == 10))) { || ((mem[0] == '\r') && (mem[1] == '\n'))) {
mem[0] = ' '; *mem++ = ' ';
mem[1] = '\n'; *mem++ = '\n';
mem += 2;
/* LF and CR */ /* LF and CR */
} else if ((mem[0] == 10) || (mem[0] == 13)) { } else if ((mem[0] == '\n') || (mem[0] == '\r')) {
mem[0] = '\n'; *mem++ = '\n';
mem += 1;
} else { } else {
mem += 1; mem++;
} }
} }
} }
@@ -293,16 +291,16 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
/* Remove comments */ /* Remove comments */
mem = pBuffer->pBuffer; mem = pBuffer->pBuffer;
uint32_t instring = 0; bool instring = false;
while (*mem) { while (*mem) {
if (*mem == '\"') if (*mem == '\"')
instring = 1 - instring; instring = !instring;
if ((mem[0] == '\\') && (mem[1] == '\"' || mem[1] == '\\')) { if ((mem[0] == '\\') && (mem[1] == '\"' || mem[1] == '\\')) {
mem += 2; mem += 2;
} else if (instring) { } else if (instring) {
mem += 1; mem++;
} else { } else {
/* Comments that start with ; anywhere in a line */ /* Comments that start with ; anywhere in a line */
if (*mem == ';') { if (*mem == ';') {
@@ -310,11 +308,11 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
*mem++ = ' '; *mem++ = ' ';
/* Comments that start with * at the start of a line */ /* Comments that start with * at the start of a line */
} else if ((mem[0] == '\n') && (mem[1] == '*')) { } else if ((mem[0] == '\n') && (mem[1] == '*')) {
mem += 1; mem++;
while (!((*mem == '\n') || (*mem == '\0'))) while (!((*mem == '\n') || (*mem == '\0')))
*mem++ = ' '; *mem++ = ' ';
} else { } else {
mem += 1; mem++;
} }
} }
} }
@@ -793,10 +791,10 @@ scanagain:
* endings: "\r\n" is replaced by " \n" before the lexer has the * endings: "\r\n" is replaced by " \n" before the lexer has the
* opportunity to see it. * opportunity to see it.
*/ */
if (pLexBuffer[1] == ' ') { if (pLexBuffer[1] == ' ' || pLexBuffer[1] == '\t') {
pLexBuffer += 2; pLexBuffer += 2;
while (1) { while (1) {
if (*pLexBuffer == ' ') { if (*pLexBuffer == ' ' || *pLexBuffer == '\t') {
pLexBuffer++; pLexBuffer++;
} else if (*pLexBuffer == '\n') { } else if (*pLexBuffer == '\n') {
pLexBuffer++; pLexBuffer++;
@@ -935,6 +933,7 @@ static uint32_t yylex_MACROARGS(void)
ch = '}'; ch = '}';
break; break;
case ' ': case ' ':
case '\t':
/* /*
* Look for line continuation character after a * Look for line continuation character after a
* series of spaces. This is also useful for * series of spaces. This is also useful for
@@ -943,7 +942,8 @@ static uint32_t yylex_MACROARGS(void)
* opportunity to see it. * opportunity to see it.
*/ */
while (1) { while (1) {
if (*pLexBuffer == ' ') { if (*pLexBuffer == ' '
|| *pLexBuffer == '\t') {
pLexBuffer++; pLexBuffer++;
} else if (*pLexBuffer == '\n') { } else if (*pLexBuffer == '\n') {
pLexBuffer++; pLexBuffer++;