diff --git a/Units/simple-nix.d/args.ctags b/Units/simple-nix.d/args.ctags new file mode 100644 index 0000000000..5ee5f79f70 --- /dev/null +++ b/Units/simple-nix.d/args.ctags @@ -0,0 +1 @@ +--sort=no diff --git a/Units/simple-nix.d/expected.tags b/Units/simple-nix.d/expected.tags new file mode 100644 index 0000000000..2bfd7b3c2a --- /dev/null +++ b/Units/simple-nix.d/expected.tags @@ -0,0 +1,2 @@ +name Units/simple-nix.d/input.nix /^ name = "hello";$/;" a +hash Units/simple-nix.d/input.nix /^ hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";$/;" a diff --git a/Units/simple-nix.d/input.nix b/Units/simple-nix.d/input.nix new file mode 100644 index 0000000000..567dd7f691 --- /dev/null +++ b/Units/simple-nix.d/input.nix @@ -0,0 +1,9 @@ +{ stdenv, fetchgit }: + +stdenv.mkDerivation { + name = "hello"; + src = fetchgit { + url = "https://example.com"; + hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + }; +} diff --git a/docs/news/HEAD.rst b/docs/news/HEAD.rst index 5ce63fcfad..485ca1a64f 100644 --- a/docs/news/HEAD.rst +++ b/docs/news/HEAD.rst @@ -14,6 +14,8 @@ Parser related changes New parsers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* Nix *optlib* by Ben Sima + Changes about parser specific kinds, roles, fields, and extras ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/optlib/nix.c b/optlib/nix.c new file mode 100644 index 0000000000..7f9600f67a --- /dev/null +++ b/optlib/nix.c @@ -0,0 +1,67 @@ +/* + * Generated by ./misc/optlib2c from optlib/nix.ctags, Don't edit this manually. + */ +#include "general.h" +#include "parse.h" +#include "routines.h" +#include "field.h" +#include "xtag.h" + + +static void initializeNixParser (const langType language CTAGS_ATTR_UNUSED) +{ +} + +extern parserDefinition* NixParser (void) +{ + static const char *const extensions [] = { + "nix", + NULL + }; + + static const char *const aliases [] = { + NULL + }; + + static const char *const patterns [] = { + NULL + }; + + static kindDefinition NixKindTable [] = { + { + true, 'p', "package", "package definition", + }, + { + true, 'f', "function", "function definition", + }, + { + true, 'a', "attr", "attribute definition", + }, + }; + static tagRegexTable NixTagRegexTable [] = { + {"[p?]name\\s*=\\s*\"(\\w+)\"", "\\1", + "p", NULL, NULL, false}, + {"(\\S+)\\s*=\\s+\\w+:", "\\1", + "f", NULL, NULL, false}, + {"\\s+([a-zA-Z_0-9-]{4,20})\\s*=", "\\1", + "a", NULL, NULL, false}, + }; + + + parserDefinition* const def = parserNew ("Nix"); + + def->versionCurrent= 0; + def->versionAge = 0; + def->enabled = true; + def->extensions = extensions; + def->patterns = patterns; + def->aliases = aliases; + def->method = METHOD_NOT_CRAFTED|METHOD_REGEX; + def->kindTable = NixKindTable; + def->kindCount = ARRAY_SIZE(NixKindTable); + def->tagRegexTable = NixTagRegexTable; + def->tagRegexCount = ARRAY_SIZE(NixTagRegexTable); + def->initialize = initializeNixParser; + + return def; +} diff --git a/optlib/nix.ctags b/optlib/nix.ctags new file mode 100644 index 0000000000..6e5529796d --- /dev/null +++ b/optlib/nix.ctags @@ -0,0 +1,40 @@ +# +# +# Copyright (c) 2024, Ben Sima +# +# Author: Ben Sima +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. +# +# +--langdef=Nix +--map-Nix=+.nix + +# Index packages when we see "name = " or "pname = " +--kinddef-Nix=p,package,package definition +--regex-Nix=/[p?]name\s*=\s*"(\w+)"/\1/p/ + +# Functions have args, so look for a : right of the = +# (This should probably be a multiline regex.) +--kinddef-Nix=f,function,function definition +--regex-Nix=/(\S+)\s*=\s+\w+:/\1/f/ + +# Attrs definitions just have =, but only index if they have >=4 chars, +# otherwise we get way too many tags. This will also index attr definitions +# inside nix build files, which is not the most useful when writing nix code, +# but can be useful when writing packages I guess. +--kinddef-Nix=a,attr,attribute definition +--regex-Nix=/\s+([a-zA-Z_0-9-]{4,20})\s*=/\1/a/ diff --git a/source.mak b/source.mak index cf0326c7ae..ff7172fee6 100644 --- a/source.mak +++ b/source.mak @@ -241,6 +241,7 @@ OPTLIB2C_INPUT = \ optlib/man.ctags \ optlib/meson.ctags \ optlib/mesonOptions.ctags \ + optlib/nix.ctags \ optlib/org.ctags \ optlib/passwd.ctags \ optlib/pkgConfig.ctags \ diff --git a/win32/ctags_vs2013.vcxproj b/win32/ctags_vs2013.vcxproj index afbbc6a629..3e0019d437 100644 --- a/win32/ctags_vs2013.vcxproj +++ b/win32/ctags_vs2013.vcxproj @@ -245,6 +245,7 @@ + diff --git a/win32/ctags_vs2013.vcxproj.filters b/win32/ctags_vs2013.vcxproj.filters index 1476a92bc9..7335d7d490 100644 --- a/win32/ctags_vs2013.vcxproj.filters +++ b/win32/ctags_vs2013.vcxproj.filters @@ -258,6 +258,9 @@ Source Files\optlib + + Source Files\optlib + Source Files\optlib