diff options
author | Michael Forney <mforney@mforney.org> | 2019-02-24 11:22:34 -0800 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-02-24 12:35:09 -0800 |
commit | 05a8ff0ee5a003e816519486ae78aa4156dfffb4 (patch) | |
tree | 15b8cd2245430c7ef5332277fc5d7de766fb1de5 /scan.c | |
parent | f7f0a1c3241640bccb5a2e07241b69f2331cca87 (diff) |
scan: Handle escaped newlines
Diffstat (limited to 'scan.c')
-rw-r--r-- | scan.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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 |