universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.47k stars 620 forks source link

Support for the Nix expression language (Nix / NixOS) #261

Open blueyed opened 9 years ago

blueyed commented 9 years ago

Description: https://nixos.org/nix/manual/#ch-expression-language

There is some very basic config in https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/misc/ctags/wrapped.nix:

--langdef=NIX
--langmap=NIX:.nix
--regex-NIX=/([^ \t*]*)[ \t]*=/\1/f/

I have (hopefully) improved this a bit locally:

--regex-NIX=/([^ \t*]*)[ \t]*=.*:/\1/f/

But it's still too basic and would need a separate parser probably.

I am new to Nix/NixOS myself, and have therefore not much knowledge about this language myself.

vcunat commented 9 years ago

Nix itself parses the language - it uses standard parsing and lexing tools https://github.com/NixOS/nix/tree/master/src/libexpr (probably most useful in context of this issue). Then I know about some stuff in haskell https://github.com/peti/language-nix, and there are syntax highlighters for various editors (or highlighting libraries).

masatake commented 9 years ago

As an initial version, a regular expression based implementation is o.k; it is always better than nothing. Though I have to rethink the directory structures, optlib is the first class way to implement an parser. You can write a C based parser later. The important point is the "kinds" compatibility between regex based parser and C based parser. If the compatibility of kinds are kept, no one takes care the way of implementation.

However, if nix implementation has real parser, why don't you utilize it? My xmcd is for you. See data/optlib/cofee.ctags and libexec/drivers/coffeetags.

roosemberth commented 6 years ago

Hi, what's the status of this issue?

masatake commented 3 years ago

A pull request is welcome.

lf- commented 3 years ago

If anyone wants a Nix ctags implementation, I wrote one in my tool here: https://github.com/lf-/nix-doc

It's Rust so not possible to integrate here though.

bsima commented 2 months ago

fwiw this has been working for me, just drop this into ~/.ctags.d/nix.ctags

--langdef=nix
--languages=+nix
--langmap=nix:.nix
# packages are "name = <tag>" or "pname = <tag>"
--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 just have =, but only index if they have >=4 chars
--kinddef-nix=a,attr,attribute definition
--regex-nix=/\s+([a-zA-Z_0-9-]{4,20})\s*=/\1/a/
masatake commented 2 months ago

Why don't you make a pull request to integrate it into ctags?

bsima commented 2 months ago

Well I'm not very good at C, but I could give it the old college try

masatake commented 2 months ago

NO. You don't have to use C. Universal Ctags has a quack translator named optlib2c that converts your .ctags to C. So, you make your parser written in .ctags a built-in parser. See https://github.com/universal-ctags/ctags/tree/master/optlib . Many parsers are written in the way.

See https://github.com/universal-ctags/ctags/commit/599cc354134a4e742dd517318800e94ef27c5607 as an example. Though it includes .c file but it is translated from .ctags from optlib2c. A perl interpreter is needed on your platform.

Let me know if you want to integrate your .ctags into Universal Ctags. I will explain the details.

bsima commented 2 months ago

Okay, I will try and follow the PkgConfig example tonight

bsima commented 2 months ago

I got it started here https://github.com/universal-ctags/ctags/pull/4020

Will continue work on it tomorrow. But I think I'm moving in the right direction.