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..d490d53ab3 --- /dev/null +++ b/Units/simple-nix.d/expected.tags @@ -0,0 +1,19 @@ +inc input.nix /^ inc = x: x + 1;$/;" f +inc input.nix /^ inc = x: x + 1;$/;" a +multilineFunc input.nix /^ multilineFunc =$/;" a +attrset input.nix /^ attrset = {$/;" a +foo input.nix /^ foo = "bar";$/;" a +multiline_attrset input.nix /^ multiline_attrset =$/;" a +bar input.nix /^ { bar = "foo"; };$/;" a +hello input.nix /^ hello = stdenv.mkDerivation {$/;" a +hello input.nix /^ name = "hello";$/;" p +name input.nix /^ name = "hello";$/;" a +src input.nix /^ src = fetchgit {$/;" a +url input.nix /^ url = "https:\/\/example.com";$/;" a +hash input.nix /^ hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";$/;" a +goodbye input.nix /^ goodbye = buildPythonPackge {$/;" a +goodbye input.nix /^ pname = "goodbye";$/;" p +pname input.nix /^ pname = "goodbye";$/;" a +src input.nix /^ src = fetchPyPi {$/;" a +url input.nix /^ url = "https:\/\/example.com";$/;" a +hash 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..dba1edd581 --- /dev/null +++ b/Units/simple-nix.d/input.nix @@ -0,0 +1,30 @@ +{ stdenv, fetchgit, lib }: + +let + inc = x: x + 1; + multilineFunc = + a: + b: + c: + a + b + c; + attrset = { + foo = "bar"; + }; + multiline_attrset = + { bar = "foo"; }; +in { + hello = stdenv.mkDerivation { + name = "hello"; + src = fetchgit { + url = "https://example.com"; + hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + }; + }; + goodbye = buildPythonPackge { + pname = "goodbye"; + src = fetchgit { + url = "https://example.com"; + hash = lib.fakeSha256; + }; + }; +} diff --git a/docs/news/HEAD.rst b/docs/news/HEAD.rst index 5b44464c92..66721b578c 100644 --- a/docs/news/HEAD.rst +++ b/docs/news/HEAD.rst @@ -17,6 +17,8 @@ Parser related changes New parsers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* Nix *optlib* by Ben Sima + Changes about parser specific kinds, roles, fields, and extras ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/main/parsers_p.h b/main/parsers_p.h index 3dfd9e8bbc..eca6d99359 100644 --- a/main/parsers_p.h +++ b/main/parsers_p.h @@ -133,6 +133,7 @@ MesonOptionsParser, \ MooseParser, \ MyrddinParser, \ + NixParser, \ NsisParser, \ ObjcParser, \ OcamlParser, \ diff --git a/optlib/nix.c b/optlib/nix.c new file mode 100644 index 0000000000..2e5842da23 --- /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-]+)\\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..b54a3ff4c8 --- /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. +# +# References: +# +# - https://nix.dev/manual/nix/latest/language/ +# +--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 = +--kinddef-Nix=f,function,function definition +--regex-Nix=/(\S+)\s*=\s+\w+:/\1/f/ + +# Attrs definitions just have =. 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-]+)\s*=/\1/a/ diff --git a/source.mak b/source.mak index 4dcc5c173d..a34ab27d0b 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