From 053d8fb0e20044eb0a3756102d3ad5372d9b52e2 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Fri, 16 Nov 2012 20:29:20 +0100 Subject: [PATCH] mergelines flag for the lexer to handle a backslash-newline --- ftepp.c | 3 ++- lexer.c | 15 ++++++++++++++- lexer.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ftepp.c b/ftepp.c index 72e6a48..b29b96b 100644 --- a/ftepp.c +++ b/ftepp.c @@ -576,7 +576,8 @@ static bool ftepp_preprocess(ftepp_t *ftepp) bool newline = true; ftepp->lex->flags.preprocessing = true; - ftepp->lex->flags.noops = true; + ftepp->lex->flags.mergelines = true; + ftepp->lex->flags.noops = true; ftepp_next(ftepp); do diff --git a/lexer.c b/lexer.c index 96644c2..1d1c42f 100644 --- a/lexer.c +++ b/lexer.c @@ -675,7 +675,20 @@ int lex_do(lex_file *lex) return TOKEN_FATAL; #endif - ch = lex_skipwhite(lex); + while (true) { + ch = lex_skipwhite(lex); + if (!lex->flags.mergelines || ch != '\\') + break; + ch = lex_getch(lex); + if (ch != '\n') { + lex_ungetch(lex, ch); + ch = '\\'; + break; + } + /* we reached a linemerge */ + continue; + } + lex->sline = lex->line; lex->tok.ctx.line = lex->sline; lex->tok.ctx.file = lex->name; diff --git a/lexer.h b/lexer.h index 76d2b7a..b8e2e01 100644 --- a/lexer.h +++ b/lexer.h @@ -119,6 +119,7 @@ typedef struct { bool noops; bool nodigraphs; /* used when lexing string constants */ bool preprocessing; /* whitespace and EOLs become actual tokens */ + bool mergelines; /* backslash at the end of a line escapes the newline */ } flags; int framevalue; -- 2.39.2