mergelines flag for the lexer to handle a backslash-newline
authorWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 16 Nov 2012 19:29:20 +0000 (20:29 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Fri, 16 Nov 2012 19:29:20 +0000 (20:29 +0100)
ftepp.c
lexer.c
lexer.h

diff --git a/ftepp.c b/ftepp.c
index 72e6a4899d7f6ca5da8f96ce46b91c24dd024dba..b29b96b916db710ae559d652bf43461199443ce8 100644 (file)
--- 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 96644c2623094d61ff54441bcebbbe66303dd1b8..1d1c42f3b61fc442a23b2b080aa23f180cf07605 100644 (file)
--- 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 76d2b7a711c9ce8f5a2e8ddf704778328c92bb70..b8e2e01f8449c1654ae298ffcff3181f6d58d5cb 100644 (file)
--- 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;