From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#46055: [PATCH] Add rust lang to etags Date: Wed, 21 Apr 2021 07:39:42 -0500 Message-ID: References: <20210125143344.21837-1-contact@parouby.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39432"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: larsi@gnus.org, 46055@debbugs.gnu.org To: Pierre-Antoine Rouby Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 21 14:41:44 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lZCAp-000A6G-Py for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Apr 2021 14:41:43 +0200 Original-Received: from localhost ([::1]:46250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZCAo-00007a-RE for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Apr 2021 08:41:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZC9C-0007Dy-RK for bug-gnu-emacs@gnu.org; Wed, 21 Apr 2021 08:40:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lZC9C-0007xa-Hk for bug-gnu-emacs@gnu.org; Wed, 21 Apr 2021 08:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lZC9C-00062H-F9 for bug-gnu-emacs@gnu.org; Wed, 21 Apr 2021 08:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 21 Apr 2021 12:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46055 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 46055-submit@debbugs.gnu.org id=B46055.161900879123176 (code B ref 46055); Wed, 21 Apr 2021 12:40:02 +0000 Original-Received: (at 46055) by debbugs.gnu.org; 21 Apr 2021 12:39:51 +0000 Original-Received: from localhost ([127.0.0.1]:57147 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lZC90-00061k-N7 for submit@debbugs.gnu.org; Wed, 21 Apr 2021 08:39:51 -0400 Original-Received: from mail-pl1-f169.google.com ([209.85.214.169]:33385) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lZC8y-00061X-Ul for 46055@debbugs.gnu.org; Wed, 21 Apr 2021 08:39:49 -0400 Original-Received: by mail-pl1-f169.google.com with SMTP id n10so10423651plc.0 for <46055@debbugs.gnu.org>; Wed, 21 Apr 2021 05:39:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:in-reply-to:references:user-agent :mime-version:date:message-id:subject:to:cc :content-transfer-encoding; bh=9nB9scLbDhki4Ry97VDBVMuENM8g/HfU+LZsQc6sLFI=; b=GCbiOrk1ujhuDyFPOrYyDoS+YvU/O/oYv5A7/jnSN2EmLR6dkGRuL2y7Wd64a1goVu NvvA3J1xM2mU/fOerd7p37wzHo7ke3ie5QITp5AQF7EXQ/5/6ZcHYuFSKXlWZvAeT286 hxOUVqRTXCzRDBYx/ZLRO/xvra4ts7xZZUGq+9jslagDeqlRj5EbS3oryrXlRMAtH2/s hV5hdn0hvtoGcLo5CF+ZaKshBJMwVIOYnbVfMc55hZgRIygF0EwLnpDj9GyEvD054qCR t4Tn9fwsf0b16UGKV/C/VcS9oQ2nTkqpXXyo241CmujYjOLPVcW1OnjXfwrQDrefe9qz E0zQ== X-Gm-Message-State: AOAM532UMqbmBsVC34UliycyuFujRuCA8lG7cPUhoP/ZOqlFk7C1a37Q O9G3gH/3IxEyVyOh3iw45MsCYxdZ8gQDQ7vW9h4= X-Google-Smtp-Source: ABdhPJzzEZ1z1s6pE0WInovbI/H5FwYwOaN/9BcBCW6Hg/MLS2KMw4s/rWcs6xPOibxnFqD9ytlcxbFRvWb5liqonL4= X-Received: by 2002:a17:902:e9c4:b029:eb:4626:feba with SMTP id 4-20020a170902e9c4b02900eb4626febamr34791580plk.39.1619008783110; Wed, 21 Apr 2021 05:39:43 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 21 Apr 2021 07:39:42 -0500 In-Reply-To: <20210125143344.21837-1-contact@parouby.fr> (Pierre-Antoine Rouby's message of "Mon, 25 Jan 2021 15:33:44 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:204600 Archived-At: Your patch looks good to me, but I didn't test it. I have one question, though. In "test/manual/etags", we have manual tests for etags including source code examples and which tags they should generate. Should we add a manual test also for Rust? Pierre-Antoine Rouby writes: > * lib-src/etags.c (Rust_functions): New function to make tags for rust > files. > (Rust_help, Rust_suffixes): New constant. > * doc/emacs/maintaining.texi (Tag Syntax): Add Rust item. > * doc/man/etags.1: Add Rust. > --- > doc/emacs/maintaining.texi | 4 +++ > doc/man/etags.1 | 2 +- > lib-src/etags.c | 51 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 56 insertions(+), 1 deletion(-) > > diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi > index 415815473e..0f96dc65d1 100644 > --- a/doc/emacs/maintaining.texi > +++ b/doc/emacs/maintaining.texi > @@ -2639,6 +2639,10 @@ Tag Syntax > @item > In Ruby code, @code{def} or @code{class} or @code{module} at the > beginning of a line generate a tag. Constants also generate tags. > + > +@item > +In Rust code, tags anything defined with @code{fn}, @code{enum}, > +@code{struct} or @code{macro_rules!}. > @end itemize > > You can also generate tags based on regexp matching (@pxref{Etags > diff --git a/doc/man/etags.1 b/doc/man/etags.1 > index c5c15fb182..354f6ca88b 100644 > --- a/doc/man/etags.1 > +++ b/doc/man/etags.1 > @@ -51,7 +51,7 @@ format understood by > \&. Both forms of the program understand > the syntax of C, Objective C, C++, Java, Fortran, Ada, Cobol, Erlang, > Forth, Go, HTML, LaTeX, Emacs Lisp/Common Lisp, Lua, Makefile, Pascal, P= erl, > -Ruby, PHP, PostScript, Python, Prolog, Scheme and > +Ruby, Rust, PHP, PostScript, Python, Prolog, Scheme and > most assembler\-like syntaxes. > Both forms read the files specified on the command line, and write a tag > table (defaults: \fBTAGS\fP for \fBetags\fP, \fBtags\fP for > diff --git a/lib-src/etags.c b/lib-src/etags.c > index b5c18e0e01..d703183cef 100644 > --- a/lib-src/etags.c > +++ b/lib-src/etags.c > @@ -366,6 +366,7 @@ #define xrnew(op, n, m) ((op) =3D xnrealloc (op, n, (= m) * sizeof *(op))) > static void Prolog_functions (FILE *); > static void Python_functions (FILE *); > static void Ruby_functions (FILE *); > +static void Rust_entries (FILE *); > static void Scheme_functions (FILE *); > static void TeX_commands (FILE *); > static void Texinfo_nodes (FILE *); > @@ -752,6 +753,12 @@ #define STDIN 0x1001 /* returned by getopt_long on = --parse-stdin */ > static const char *Ruby_interpreters [] =3D > { "ruby", NULL }; > > +static const char *Rust_suffixes [] =3D > + { "rs", NULL }; > +static const char Rust_help [] =3D > + "In Rust code, tags anything defined with 'fn', 'enum', \n\ > +'struct' or 'macro_rules!'."; > + > /* Can't do the `SCM' or `scm' prefix with a version number. */ > static const char *Scheme_suffixes [] =3D > { "oak", "sch", "scheme", "SCM", "scm", "SM", "sm", "ss", "t", NULL }; > @@ -836,6 +843,7 @@ #define STDIN 0x1001 /* returned by getopt_long on -= -parse-stdin */ > NULL, Python_interpreters }, > { "ruby", Ruby_help, Ruby_functions, Ruby_suffixes, > Ruby_filenames, Ruby_interpreters }, > + { "rust", Rust_help, Rust_entries, Rust_suffixes }= , > { "scheme", Scheme_help, Scheme_functions, Scheme_suffixes }= , > { "tex", TeX_help, TeX_commands, TeX_suffixes }= , > { "texinfo", Texinfo_help, Texinfo_nodes, Texinfo_suffixes }= , > @@ -5019,6 +5027,49 @@ Ruby_functions (FILE *inf) > } > } > > +=0C > +/* > + * Rust support > + * Look for: > + * - fn: Function > + * - struct: Structure > + * - enum: Enumeration > + * - macro_rules!: Macro > + */ > +static void > +Rust_entries (FILE *inf) > +{ > + char *cp, *name; > + bool is_func =3D false; > + > + LOOP_ON_INPUT_LINES(inf, lb, cp) > + { > + cp =3D skip_spaces(cp); > + name =3D cp; > + > + // Skip 'pub' keyworld > + (void)LOOKING_AT (cp, "pub"); > + > + // Look for define > + if ((is_func =3D LOOKING_AT (cp, "fn")) > + || LOOKING_AT (cp, "enum") > + || LOOKING_AT (cp, "struct") > + || (is_func =3D LOOKING_AT (cp, "macro_rules!"))) > + { > + cp =3D skip_spaces (cp); > + name =3D cp; > + > + while (!notinname (*cp)) > + cp++; > + > + make_tag (name, cp - name, is_func, > + lb.buffer, cp - lb.buffer + 1, > + lineno, linecharno); > + is_func =3D false; > + } > + } > +} > + > =0C > /* > * PHP support