aboutsummaryrefslogtreecommitdiff
path: root/scan.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2020-03-16 02:04:47 -0700
committerMichael Forney <mforney@mforney.org>2020-03-16 02:21:13 -0700
commit19b816b032dfc01a49f7f86ae7c411a0f15fd2bc (patch)
tree6ab7a834c2ea064856b7c006c783edda8a54916e /scan.c
parentca7d50a3fef8d4f2bfa199a0e334217978fd6483 (diff)
scan: Keep track of whether tokens had preceeding whitespace
Diffstat (limited to 'scan.c')
-rw-r--r--scan.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/scan.c b/scan.c
index ef2a2ca..557b595 100644
--- a/scan.c
+++ b/scan.c
@@ -16,6 +16,7 @@ struct buffer {
struct scanner {
int chr;
bool usebuf;
+ bool sawspace;
FILE *file;
struct location loc;
struct buffer buf;
@@ -249,7 +250,7 @@ comment(struct scanner *s)
case '/': /* C++-style comment */
do nextchar(s);
while (s->chr != '\n' && s->chr != EOF);
- return true;
+ break;
case '*': /* C-style comment */
nextchar(s);
do {
@@ -259,10 +260,12 @@ comment(struct scanner *s)
error(&s->loc, "EOF in comment");
} while (last != '*' || s->chr != '/');
nextchar(s);
- return true;
+ break;
default:
return false;
}
+ s->sawspace = true;
+ return true;
}
static int
@@ -277,6 +280,7 @@ again:
case '\t':
case '\f':
case '\v':
+ s->sawspace = true;
nextchar(s);
goto again;
case '!':
@@ -451,6 +455,7 @@ scanclose(void)
void
scan(struct token *t)
{
+ scanner->sawspace = false;
for (;;) {
t->loc = scanner->loc;
t->kind = scankind(scanner);
@@ -466,4 +471,5 @@ scan(struct token *t)
} else {
t->lit = NULL;
}
+ t->space = scanner->sawspace;
}