From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id xRcSLpWC/mpP6B4AWB0awg (envelope-from ) for ; Thu, 19 Nov 2026 00:01:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1795064469; bh=q/gfY3Rre+taRfXxBYHejpNuI+lu+VNRcO1UgC/Ll4A=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=sMf8/nG+5o+/0yePMTEKOA/PxF1iQ1YChBXFt4QRA/Tz12nBcgbypZiqgHpZtdtp+ mPBpg+z2fC0tRTUJiliiB5+pBX8P17IHGTyefi871rMay6513Fmn1A8VqRihJ7h4Aw 3GH1HjZPXqkvu0WC6FAQG3NQPrUjqy8aBXi98hqw= Received: by simark.ca (Postfix, from userid 112) id A92551E0BC; Thu, 19 Nov 2026 00:01:09 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=P7ncIxlp; dkim-atps=neutral Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A4C9B1E087 for ; Thu, 19 Nov 2026 00:01:08 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B546E4BA2E38 for ; Thu, 19 Nov 2026 05:01:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B546E4BA2E38 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=P7ncIxlp Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 268F14BA2E15 for ; Thu, 19 Nov 2026 05:00:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 268F14BA2E15 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 268F14BA2E15 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795064440; cv=none; b=xx9dLGlpMk6mKLyczUqTjubQNc53WyIUgYVhHYfiNAtJp6RxUN40ig0wM3YNTczZJLp7GREqKNWaSmCG2GCkgKsgG8PLLSyvz6Z6agdXY9nAXV6gyDDNTGrfnvPVBwix3iCrhOEL087B2vauWId4aIYP+3cjxef23Jv54AT50Fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795064440; c=relaxed/simple; bh=q/gfY3Rre+taRfXxBYHejpNuI+lu+VNRcO1UgC/Ll4A=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=r+gT68LK70R3tMk+Gzsu/utXsiH8CDpfWk6oINaqHNLHCZOBdh17p0EPArZyQ/qp09UNgiI4LzlTmR55j9cxaeAiRSfrdgHMPW0RJblqrtxUwAKKkYbMVh/EFUuqgLDacwLAb3Qz4le4i5nIbg3sfrjl0oXwsgVW1dh8FV/S7bE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=P7ncIxlp DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 268F14BA2E15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1795064438; bh=q/gfY3Rre+taRfXxBYHejpNuI+lu+VNRcO1UgC/Ll4A=; h=Date:Subject:To:References:From:In-Reply-To:From; b=P7ncIxlpbMG8gS0E3nukOQHeP59iMbK6jH4/IhwpCl4xk9osuI3Zgfg1DHN/k75hD Dl6soO5nuiWeOWF3uREnbyUQaSsZCy8+gD4lA2jTpmGHxCeLzOzvqvXq3v3hIzKBd+ KUlse5mXIi9VDL3U+awkpFo2MIX1OXPZglz7VNOY= Received: by simark.ca (Postfix) id 56B351E087; Thu, 19 Nov 2026 00:00:38 -0500 (EST) Message-ID: Date: Thu, 19 Nov 2026 00:00:37 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] Rewrite the Ada lexer To: Tom Tromey , gdb-patches@sourceware.org References: <20261117191854.2893194-1-tromey@adacore.com> Content-Language: fr From: Simon Marchi In-Reply-To: <20261117191854.2893194-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 11/17/26 2:18 PM, Tom Tromey wrote: > Recently a series landed that changed how the Ada lexer was built. In > particular, commit d3d68d79 ("gdb: let the parser and lexer generators > prefix their symbols") changed gdb to require a newer version of flex. > > Unfortunately, this version of flex is reported as being difficult to > build with mingw; and this change broke all the Windows-hosted builds > at AdaCore. > > Rather than try to puzzle out the flex build, I decided to rewrite the > lexer to avoid the flex dependency. This patch is the result. I > tried for a fairly minimal transition, so some oddities are preserved. > Further cleanups are possible (I have a few I will send later). > > I've also added some unit tests. In some cases these test things that > previously were not tested in the tree. > > v2: addressed review comments. LGTM, I noted some minor comments below. Approved-By: Simon Marchi Some cleanup that could be part of this patch, of a later one: - remove ada-lex-gen.{c,h} from .gitignore - post-process-parser-output.sh can be simplified - ECHO_LEX can be removed from silent-rules.mk > +/* The number of subexpressions to allocate space for, including the > + "0th" whole match subexpression. */ > +#define NUM_OPER_SUBEXPRESSIONS 2 NUM_OPER_SUBEXPRESSIONS is unused, I don't know if it should? > @@ -207,51 +275,47 @@ processReal (struct parser_state *par_state, const char *num0) > /* See ada-exp-parser.h. */ > > struct stoken > -processId (const char *name0, int len) > +ada_parse_state::process_id (std::string_view name0) > { > - char *name = (char *) obstack_alloc (&ada_parser->temp_space, len + 11); > - int i0, i; > + char *name = (char *) obstack_alloc (&ada_parser->temp_space, > + name0.size () + 11); > struct stoken result; > > result.ptr = name; > - while (len > 0 && c_isspace (name0[len-1])) > - len -= 1; > + while (!name0.empty () && c_isspace (name0.back ())) > + name0 = name0.substr (0, name0.size () - 1); Can use name0.remove_suffix(1). > @@ -365,39 +406,32 @@ attributes[] = { > /* See ada-exp-parser.h. */ > > int > -processAttribute (const char *str) > +ada_parse_state::process_attribute (const std::string &str, bool completing) > { > - gdb_assert (*str == '\''); > - ++str; > - while (c_isspace (*str)) > - ++str; > - > - int len = strlen (str); > - if (len > 0 && str[len - 1] == COMPLETE_CHAR) > + size_t len = str.length (); > + if (completing) > { > - /* This is enforced by YY_INPUT. */ > - gdb_assert (pstate->parse_completion); > ada_yylval.sval.ptr = obstack_strndup (&ada_parser->temp_space, Should be just temp_space (or this->temp_space), instead of going through the `ada_parser` global. There is another instance at line 280 in ada_parse_state::process_id. > +ada_parse_state::lex_number () > +{ > + const char *num_start = pstate->lexptr; > + gdb_assert (c_isdigit (*num_start)); > + > + regmatch_t subexps[NUM_SUBEXPRESSIONS]; > + int match = regexec (&number_regex, num_start, ARRAY_SIZE (subexps), > + subexps, 0); > + /* Failure means the regexp is broken. */ > + gdb_assert (match == 0); > + > + pstate->lexptr += subexps[0].rm_eo; > + > +#define NUMERAL_WIDTH 256 > + char numbuf[NUMERAL_WIDTH]; This predates the patch, so maybe a TODO cleanup, we can overflow this static buffer: (gdb) set language ada (gdb) python gdb.execute("print " + "1" * 300) It would easily be fixed by making canonicalize_numeral return an std::string. Apparently, the callers can keep using their trick of splitting the string with \0 in place, in the std::string: char *e_ptr = strrchr (numbuf.data (), 'e'); *e_ptr = '\0'; > +ada_parse_state::invalid_char () > { > - pstate->lexptr -= ada_yyleng; > - while (c_toupper (*pstate->lexptr) != c_toupper (ch)) > - pstate->lexptr -= 1; > - ada_yyrestart (NULL); > + error (_("Invalid character '%s' in expression."), pstate->lexptr); %s or %c? > + const code_entry us3_test[] = > + { > + { "x", NAME }, > + { nullptr, '+' }, > + { "a___b", NAME }, > + { nullptr, 0 } Indentation is off for the first element. > @@ -1349,3 +2152,19 @@ ada_parse (struct parser_state *par_state) > } > return result; > } > + > +INIT_GDB_FILE (ada_exp_parser) > +{ > + int code = regcomp (&number_regex, number_regex_text, > + REG_EXTENDED | REG_ICASE); > + /* If the regular expression was incorrect, it was a programming > + error. */ > + gdb_assert (code == 0); > + code = regcomp (&operator_regex, operator_regex_text, > + REG_EXTENDED | REG_ICASE); > + gdb_assert (code == 0); Can these use compiled_regex? Simon