From: Stefan Kangas <stefan@marxist.se>
To: Pierre-Antoine Rouby <contact@parouby.fr>
Cc: larsi@gnus.org, 46055@debbugs.gnu.org
Subject: bug#46055: [PATCH] Add rust lang to etags
Date: Wed, 21 Apr 2021 07:39:42 -0500 [thread overview]
Message-ID: <CADwFkmnrc3E2aBXxtOuxAa5cH7qtJRCKxZoAbYUAHOa6KU6t3g@mail.gmail.com> (raw)
In-Reply-To: <20210125143344.21837-1-contact@parouby.fr> (Pierre-Antoine Rouby's message of "Mon, 25 Jan 2021 15:33:44 +0100")
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 <contact@parouby.fr> 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, Perl,
> -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) = 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 [] =
> { "ruby", NULL };
>
> +static const char *Rust_suffixes [] =
> + { "rs", NULL };
> +static const char Rust_help [] =
> + "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 [] =
> { "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)
> }
> }
>
> +\f
> +/*
> + * 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 = false;
> +
> + LOOP_ON_INPUT_LINES(inf, lb, cp)
> + {
> + cp = skip_spaces(cp);
> + name = cp;
> +
> + // Skip 'pub' keyworld
> + (void)LOOKING_AT (cp, "pub");
> +
> + // Look for define
> + if ((is_func = LOOKING_AT (cp, "fn"))
> + || LOOKING_AT (cp, "enum")
> + || LOOKING_AT (cp, "struct")
> + || (is_func = LOOKING_AT (cp, "macro_rules!")))
> + {
> + cp = skip_spaces (cp);
> + name = cp;
> +
> + while (!notinname (*cp))
> + cp++;
> +
> + make_tag (name, cp - name, is_func,
> + lb.buffer, cp - lb.buffer + 1,
> + lineno, linecharno);
> + is_func = false;
> + }
> + }
> +}
> +
> \f
> /*
> * PHP support
next prev parent reply other threads:[~2021-04-21 12:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-23 19:01 bug#46055: [PATCH] Add rust lang to etags Pierre-Antoine Rouby
2021-01-23 19:59 ` Lars Ingebrigtsen
2021-01-23 20:23 ` Eli Zaretskii
2021-01-25 10:08 ` parouby
2021-01-25 10:09 ` Lars Ingebrigtsen
2021-04-21 3:19 ` Stefan Kangas
2021-04-21 8:54 ` Eli Zaretskii
2021-01-25 10:15 ` Pierre-Antoine Rouby
2021-01-25 14:33 ` Pierre-Antoine Rouby
2021-04-21 12:39 ` Stefan Kangas [this message]
2021-04-21 15:02 ` Francesco Potortì
2021-05-17 15:23 ` Lars Ingebrigtsen
2021-05-17 15:51 ` Eli Zaretskii
2021-05-17 16:08 ` Lars Ingebrigtsen
2021-05-17 16:14 ` Eli Zaretskii
2021-05-17 16:27 ` Lars Ingebrigtsen
2021-05-17 16:31 ` Lars Ingebrigtsen
2021-05-17 16:40 ` Eli Zaretskii
2021-05-18 13:44 ` Lars Ingebrigtsen
2021-05-20 10:03 ` Eli Zaretskii
2021-05-17 15:21 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADwFkmnrc3E2aBXxtOuxAa5cH7qtJRCKxZoAbYUAHOa6KU6t3g@mail.gmail.com \
--to=stefan@marxist.se \
--cc=46055@debbugs.gnu.org \
--cc=contact@parouby.fr \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).