ref: 6fbb25c0dae9d755ef5eeb1326472de46811df77
parent: 65fc42cce50de0a5039e703f6be568a29e23e213
author: ISSOtm <[email protected]>
date: Thu Sep 5 11:22:24 EDT 2019
Clean up lexer.c Remove some hardcoded character values Allow tabs to be used for line continuations
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -275,17 +275,15 @@
mem += 2;
} else {
/* LF CR and CR LF */
- if (((mem[0] == 10) && (mem[1] == 13))
- || ((mem[0] == 13) && (mem[1] == 10))) {
- mem[0] = ' ';
- mem[1] = '\n';
- mem += 2;
+ if (((mem[0] == '\n') && (mem[1] == '\r'))
+ || ((mem[0] == '\r') && (mem[1] == '\n'))) {
+ *mem++ = ' ';
+ *mem++ = '\n';
/* LF and CR */
- } else if ((mem[0] == 10) || (mem[0] == 13)) {
- mem[0] = '\n';
- mem += 1;
+ } else if ((mem[0] == '\n') || (mem[0] == '\r')) {
+ *mem++ = '\n';
} else {
- mem += 1;
+ mem++;
}
}
}
@@ -293,16 +291,16 @@
/* Remove comments */
mem = pBuffer->pBuffer;
- uint32_t instring = 0;
+ bool instring = false;
while (*mem) {
if (*mem == '\"')
- instring = 1 - instring;
+ instring = !instring;
if ((mem[0] == '\\') && (mem[1] == '\"' || mem[1] == '\\')) {
mem += 2;
} else if (instring) {
- mem += 1;
+ mem++;
} else {
/* Comments that start with ; anywhere in a line */
if (*mem == ';') {
@@ -310,11 +308,11 @@
*mem++ = ' ';
/* Comments that start with * at the start of a line */
} else if ((mem[0] == '\n') && (mem[1] == '*')) {
- mem += 1;
+ mem++;
while (!((*mem == '\n') || (*mem == '\0')))
*mem++ = ' ';
} else {
- mem += 1;
+ mem++;
}
}
}
@@ -793,10 +791,10 @@
* endings: "\r\n" is replaced by " \n" before the lexer has the
* opportunity to see it.
*/
- if (pLexBuffer[1] == ' ') {
+ if (pLexBuffer[1] == ' ' || pLexBuffer[1] == '\t') {
pLexBuffer += 2;
while (1) {
- if (*pLexBuffer == ' ') {
+ if (*pLexBuffer == ' ' || *pLexBuffer == '\t') {
pLexBuffer++;
} else if (*pLexBuffer == '\n') {
pLexBuffer++;
@@ -935,6 +933,7 @@
ch = '}';
break;
case ' ':
+ case '\t':
/*
* Look for line continuation character after a
* series of spaces. This is also useful for
@@ -943,7 +942,8 @@
* opportunity to see it.
*/
while (1) {
- if (*pLexBuffer == ' ') {
+ if (*pLexBuffer == ' '
+ || *pLexBuffer == '\t') {
pLexBuffer++;
} else if (*pLexBuffer == '\n') {
pLexBuffer++;