Skip to content

Commit 4745a10

Browse files
committed
Implement Nix optlib parser
1 parent 08e07dc commit 4745a10

File tree

7 files changed

+121
-0
lines changed

7 files changed

+121
-0
lines changed

Units/simple-nix.d/args.ctags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--sort=no

Units/simple-nix.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this should fail

Units/simple-nix.d/input.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ stdenv, fetchgit }:
2+
3+
stdenv.mkDerivation {
4+
name = "hello";
5+
src = fetchgit {
6+
url = "https://example.com";
7+
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
8+
};
9+
}

docs/news/HEAD.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Parser related changes
1414
New parsers
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1616

17+
* Nix *optlib* by Ben Sima
18+
1719
Changes about parser specific kinds, roles, fields, and extras
1820
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1921

optlib/nix.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Generated by ./misc/optlib2c from optlib/nix.ctags, Don't edit this manually.
3+
*/
4+
#include "general.h"
5+
#include "parse.h"
6+
#include "routines.h"
7+
#include "field.h"
8+
#include "xtag.h"
9+
10+
11+
static void initializeNixParser (const langType language CTAGS_ATTR_UNUSED)
12+
{
13+
}
14+
15+
extern parserDefinition* NixParser (void)
16+
{
17+
static const char *const extensions [] = {
18+
"nix",
19+
NULL
20+
};
21+
22+
static const char *const aliases [] = {
23+
NULL
24+
};
25+
26+
static const char *const patterns [] = {
27+
NULL
28+
};
29+
30+
static kindDefinition NixKindTable [] = {
31+
{
32+
true, 'p', "package", "package definition",
33+
},
34+
{
35+
true, 'f', "function", "function definition",
36+
},
37+
{
38+
true, 'a', "attr", "attribute definition",
39+
},
40+
};
41+
static tagRegexTable NixTagRegexTable [] = {
42+
{"[p?]name\\s*=\\s*\"(\\w+)\"", "\\1",
43+
"p", NULL, NULL, false},
44+
{"(\\S+)\\s*=\\s+\\w+:", "\\1",
45+
"f", NULL, NULL, false},
46+
{"\\s+([a-zA-Z_0-9-]{4,20})\\s*=", "\\1",
47+
"a", NULL, NULL, false},
48+
};
49+
50+
51+
parserDefinition* const def = parserNew ("Nix");
52+
53+
def->versionCurrent= 0;
54+
def->versionAge = 0;
55+
def->enabled = true;
56+
def->extensions = extensions;
57+
def->patterns = patterns;
58+
def->aliases = aliases;
59+
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX;
60+
def->kindTable = NixKindTable;
61+
def->kindCount = ARRAY_SIZE(NixKindTable);
62+
def->tagRegexTable = NixTagRegexTable;
63+
def->tagRegexCount = ARRAY_SIZE(NixTagRegexTable);
64+
def->initialize = initializeNixParser;
65+
66+
return def;
67+
}

optlib/nix.ctags

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
#
3+
# Copyright (c) 2024, Ben Sima
4+
#
5+
# Author: Ben Sima <[email protected]>
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License
9+
# as published by the Free Software Foundation; either version 2
10+
# of the License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20+
# USA.
21+
#
22+
#
23+
--langdef=Nix
24+
--map-Nix=+.nix
25+
26+
# Index packages when we see "name = <tag>" or "pname = <tag>"
27+
--kinddef-Nix=p,package,package definition
28+
--regex-Nix=/[p?]name\s*=\s*"(\w+)"/\1/p/
29+
30+
# Functions have args, so look for a : right of the =
31+
# (This should probably be a multiline regex.)
32+
--kinddef-Nix=f,function,function definition
33+
--regex-Nix=/(\S+)\s*=\s+\w+:/\1/f/
34+
35+
# Attrs definitions just have =, but only index if they have >=4 chars,
36+
# otherwise we get way too many tags. This will also index attr definitions
37+
# inside nix build files, which is not the most useful when writing nix code,
38+
# but can be useful when writing packages I guess.
39+
--kinddef-Nix=a,attr,attribute definition
40+
--regex-Nix=/\s+([a-zA-Z_0-9-]{4,20})\s*=/\1/a/

source.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ OPTLIB2C_INPUT = \
241241
optlib/man.ctags \
242242
optlib/meson.ctags \
243243
optlib/mesonOptions.ctags \
244+
optlib/nix.ctags \
244245
optlib/org.ctags \
245246
optlib/passwd.ctags \
246247
optlib/pkgConfig.ctags \

0 commit comments

Comments
 (0)