From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1VlPCh-0002Pi-G6 for mharc-grub-devel@gnu.org; Tue, 26 Nov 2013 15:25:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlPCa-00029r-M1 for grub-devel@gnu.org; Tue, 26 Nov 2013 15:25:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlPCZ-0001da-N4 for grub-devel@gnu.org; Tue, 26 Nov 2013 15:25:44 -0500 Received: from v6.chiark.greenend.org.uk ([2001:ba8:1e3::]:60993 helo=chiark.greenend.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlPCZ-0001dJ-7o for grub-devel@gnu.org; Tue, 26 Nov 2013 15:25:43 -0500 Received: from [172.20.153.9] (helo=riva.pelham.vpn.ucam.org) by chiark.greenend.org.uk (Debian Exim 4.72 #1) with esmtps (return-path cjwatson@ubuntu.com) id 1VlPCY-00082s-OO for grub-devel@gnu.org; Tue, 26 Nov 2013 20:25:42 +0000 Received: from ns1.pelham.vpn.ucam.org ([172.20.153.2] helo=riva.ucam.org) by riva.pelham.vpn.ucam.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1VlPCY-00017d-1z for grub-devel@gnu.org; Tue, 26 Nov 2013 20:25:42 +0000 Date: Tue, 26 Nov 2013 20:25:40 +0000 From: Colin Watson To: grub-devel@gnu.org Subject: [PATCH 3/3] Handle #if/#endif and C-style comments in AutoGen definitions files. Message-ID: <20131126202540.GD1228@riva.ucam.org> References: <20131126202446.GA1228@riva.ucam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20131126202446.GA1228@riva.ucam.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:ba8:1e3:: X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Nov 2013 20:25:49 -0000 --- gentpl.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/gentpl.py b/gentpl.py index 5bee43a..0c5eabb 100644 --- a/gentpl.py +++ b/gentpl.py @@ -106,9 +106,11 @@ for platform in GRUB_PLATFORMS: # # We support a subset of the AutoGen definitions file syntax. Specifically, -# compound names are disallowed; C-style comments and preprocessing -# directives are disallowed; and shell-generated strings, Scheme-generated -# strings, and here strings are disallowed. +# compound names are disallowed; some preprocessing directives are +# disallowed (though #if/#endif are allowed; note that, like AutoGen, #if +# skips everything to the next #endif regardless of the value of the +# conditional); and shell-generated strings, Scheme-generated strings, and +# here strings are disallowed. class AutogenToken: (autogen, definitions, eof, var_name, other_name, string, number, @@ -189,7 +191,27 @@ class AutogenParser: if offset >= end: break c = data[offset] - if c == "{": + if c == "#": + offset += 1 + try: + end_directive = data.index("\n", offset) + directive = data[offset:end_directive] + offset = end_directive + except ValueError: + directive = data[offset:] + offset = end + name, value = directive.split(None, 1) + if name == "if": + try: + end_if = data.index("\n#endif", offset) + new_offset = end_if + len("\n#endif") + self.cur_line += data[offset:new_offset].count("\n") + offset = new_offset + except ValueError: + self.error("#if without matching #endif") + else: + self.error("Unhandled directive '#%s'" % name) + elif c == "{": yield AutogenToken.lbrace, c offset += 1 elif c == "=": @@ -234,6 +256,22 @@ class AutogenParser: else: s.append(data[offset]) yield AutogenToken.string, "".join(s) + elif c == "/": + offset += 1 + if data[offset] == "*": + offset += 1 + try: + end_comment = data.index("*/", offset) + new_offset = end_comment + len("*/") + self.cur_line += data[offset:new_offset].count("\n") + offset = new_offset + except ValueError: + self.error("/* without matching */") + elif data[offset] == "/": + try: + offset = data.index("\n", offset) + except ValueError: + pass elif (c.isdigit() or (c == "-" and offset < end - 1 and data[offset + 1].isdigit())): -- 1.8.4.3