shithub: rgbds

Download patch

ref: f7f697c2677be5fe456effeb6f27138f62c1bc42
parent: 554b5292de88e5f522d81cf6040b4a9c92ac8098
author: Antonio Niño Díaz <[email protected]>
date: Fri Apr 14 13:07:01 EDT 2017

Fix parsing of first line of included linkerscripts

When including a linkerscript from a parent one, the lexer didn't
include a newline character because the INCLUDE command was handled
before reaching the newline. This behaviour is needed to parse the last
line of a linkerscript correctly (it doesn't have a newline character).

However, this meant that when the included file was being parsed, the
first line was considered a continuation of the last line of the parent
script (the INCLUDE command), which means that the first line of an
included linkerscript could only contain a comment (or nothing at all).

This patch adds a newline character to the buffer used by the lexer so
that the parser will receive a newline and it will handle the first line
of the included file as expected.

Signed-off-by: Antonio Niño Díaz <[email protected]>

--- a/src/link/lexer.l
+++ b/src/link/lexer.l
@@ -15,7 +15,6 @@
  */
 
 %option noinput
-%option nounput
 %option yylineno
 
 %{
@@ -131,7 +130,22 @@
 	include_path[include_stack_ptr][sizeof(include_path[0])-1] = '\0';
 
 	yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
-	yylineno = 0;
+	yylineno = 1;
+
+	/*
+	 * The INCLUDE keyword is handled before reaching a newline token, it's
+	 * handled right after parsing the string with the file name that has to
+	 * be included. It isn't actually needed to include a newline after the
+	 * path, the last line of the linkerscript doesn't need to have a
+	 * newline character but it can have a command.
+	 *
+	 * This means that, when opening a new file, we must tell the parser
+	 * that what it is going to start at a new line or it will think that
+	 * the first line of the included script is the continuation of the
+	 * INCLUDE line of the parent script. If this is not done, the first
+	 * line of an included linkerscript can only be a comment (or empty).
+	 */
+	unput('\n');
 }
 
 int script_IncludeDepthGet(void)