From 05a8ff0ee5a003e816519486ae78aa4156dfffb4 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 24 Feb 2019 11:22:34 -0800 Subject: scan: Handle escaped newlines --- scan.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'scan.c') diff --git a/scan.c b/scan.c index 22c1821..473400f 100644 --- a/scan.c +++ b/scan.c @@ -47,13 +47,25 @@ bufget(struct buffer *b) static void nextchar(struct scanner *s) { + int c; + if (s->usebuf) bufadd(&s->buf, s->chr); - s->chr = getchar(); - if (s->chr == '\n') + for (;;) { + s->chr = getchar(); + if (s->chr == '\n') + ++s->loc.line, s->loc.col = 1; + else + ++s->loc.col; + if (s->chr != '\\') + break; + c = getchar(); + if (c != '\n') { + ungetc(c, stdin); + break; + } ++s->loc.line, s->loc.col = 1; - else - ++s->loc.col; + } } static int -- cgit v1.2.3