From: Wolfgang (Blub) Bumiller Date: Fri, 16 Nov 2012 19:29:20 +0000 (+0100) Subject: mergelines flag for the lexer to handle a backslash-newline X-Git-Tag: 0.1.9~404^2~47 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=053d8fb0e20044eb0a3756102d3ad5372d9b52e2 mergelines flag for the lexer to handle a backslash-newline --- 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;