[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#46055: [PATCH] Add rust lang to etags
From: |
Pierre-Antoine Rouby |
Subject: |
bug#46055: [PATCH] Add rust lang to etags |
Date: |
Sat, 23 Jan 2021 20:01:43 +0100 |
* lib-src/etags.c (Rust_functions): New function to make tags for rust
files.
(Rust_help, Rust_suffixes): New constant.
---
lib-src/etags.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/lib-src/etags.c b/lib-src/etags.c
index b5c18e0e01..8243861c69 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_functions (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_functions, 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,47 @@ Ruby_functions (FILE *inf)
}
}
+
+/*
+ * Rust support
+ * Look for:
+ * - fn: Function
+ * - struct: Structure
+ * - enum: Enumeration
+ * - macro_rules!: Macro
+ */
+static void
+Rust_functions (FILE *inf)
+{
+ char *cp, *name;
+
+ 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 (LOOKING_AT (cp, "fn")
+ || LOOKING_AT (cp, "enum")
+ || LOOKING_AT (cp, "struct")
+ || LOOKING_AT (cp, "macro_rules!"))
+ {
+ cp = skip_spaces (cp);
+ name = cp;
+
+ while (!notinname (*cp))
+ cp++;
+
+ make_tag (name, cp - name, true,
+ lb.buffer, cp - lb.buffer + 1,
+ lineno, linecharno);
+ }
+ }
+}
+
/*
* PHP support
--
2.29.2
- bug#46055: [PATCH] Add rust lang to etags,
Pierre-Antoine Rouby <=