From 3e219dee369e24912cbe7de23997dbf91b28e3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Tue, 20 Feb 2018 23:39:30 +0000 Subject: [PATCH] Allow to continuate lines except inside macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines can be continuated after a newline character ('\n'): DB 1, 2, 3, 4 \ 5, 6, 7, 8 This doesn't work for now in lists of arguments of macros. It is possible to have spaces after the '\' and before the newline character. This is needed because Windows line endings "\r\n" are converted to " \n" before the lexer has a chance to handle them. Signed-off-by: Antonio Niño Díaz --- src/asm/lexer.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 0c728784..bb8f6ad0 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -638,6 +638,44 @@ scanagain: } } + /* Check for line continuation character */ + if (*pLexBuffer == '\\') { + + /* + * Look for line continuation character after a series of + * spaces. This is also useful for files that use Windows line + * endings: "\r\n" is replaced by " \n" before the lexer has the + * opportunity to see it. + */ + if (pLexBuffer[1] == ' ') { + pLexBuffer += 2; + while (1) { + if (*pLexBuffer == ' ') { + pLexBuffer++; + } else if (*pLexBuffer == '\n') { + pLexBuffer++; + nLineNo += 1; + goto scanagain; + } else { + errx(1, "Expected a new line after the continuation character."); + } + } + } + + /* Line continuation character */ + if (pLexBuffer[1] == '\n') { + pLexBuffer += 2; + nLineNo += 1; + goto scanagain; + } + + /* + * If there isn't a newline character or a space, ignore the + * character '\'. It will eventually be handled by other + * functions like PutMacroArg(). + */ + } + /* * Try to match an identifier, macro argument (e.g. \1), * or numeric literal.