cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 05a8ff0ee5a003e816519486ae78aa4156dfffb4
parent f7f0a1c3241640bccb5a2e07241b69f2331cca87
Author: Michael Forney <mforney@mforney.org>
Date:   Sun, 24 Feb 2019 11:22:34 -0800

scan: Handle escaped newlines

Diffstat:
Mscan.c | 20++++++++++++++++----
Atests/escaped-newline.c | 2++
Atests/escaped-newline.qbe | 1+
3 files changed, 19 insertions(+), 4 deletions(-)

diff --git 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 diff --git a/tests/escaped-newline.c b/tests/escaped-newline.c @@ -0,0 +1,2 @@ +int split\ +ident = 3; diff --git a/tests/escaped-newline.qbe b/tests/escaped-newline.qbe @@ -0,0 +1 @@ +export data $splitident = align 4 { w 3, }