0

我想为 Lua 使用 Ctags。

ctags不支持lua,所以找了个命令:

ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*(\w+):(\w+).*$/\2/f/" --regex-MYLUA="/^\s*(\w+)\s*=\s*[0-9]+.*$/\1/e/" --regex-MYLUA="/^.*\s*function\s*(\w+)\.(\w+).*$/\2/f/" --regex-MYLUA="/^.*\s*function\s*(\w+)\s*\(.*$/\1/f/" --regex-MYLUA="/^\s*(\w+)\s*=\s*\{.*$/\1/e/" --regex-MYLUA="/^\s*module\s+\"(\w+)\".*$/\1/m,module/" --regex-MYLUA="/^\s*module\s+\"[a-zA-Z0-9._]+\.(\w+)\".*$/\1/m,module/" --languages=MYLUA --excmd=number -R .

它太长了,或者你只能看到一个更短的示例,只适用于 lua 函数。

ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*(\w+)\s*\(.*$/\1/f/" --languages=MYLUA --excmd=number -R .

两者都可以在 Windows 上正常工作。

在 OSX 上,没有错误,但标签文件是空的。

PS:我使用 Exuberant Ctags v5.8,而不是 OSX 上的默认 ctags。

这是 ctags 的测试 Lua 代码。

function f1()
end

function c.f2()
end

function c:f3()
end
4

2 回答 2

1

您可以在https://github.com/fishman/ctags找到的丰富的 ctags 版本似乎具有本机 lua 支持。你试过吗?

于 2014-12-24T17:19:08.370 回答
0

最后,我修好了。

  1. '\w' 不能在这个正则表达式中使用('\w' 也不行),我不知道为什么。我使用 '[^\s:>]' 而不是 '\w'。
  2. '\1' 或 '\2' 必须转义为 '\\1' 或 '\\2',但 '\s' 是可以的。也不知道为什么。

现在,命令更改为

ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*([^\s:.]+):([^\s:.]+).*$/\\2/f/" --regex-MYLUA="/^\s*([^\s:.]+)\s*=\s*[0-9]+.*$/\\1/e/" --regex-MYLUA="/^.*\s*function\s*([^\s:.]+)\.([^\s:.]+).*$/\\2/f/" --regex-MYLUA="/^.*\s*function\s*([^\s:.]+)\s*\(.*$/\\1/f/" --regex-MYLUA="/^\s*([^\s:.]+)\s*=\s*\{.*$/\\1/e/" --regex-MYLUA="/^\s*module\s+\"([^\s:.]+)\".*$/\\1/m,module/" --regex-MYLUA="/^\s*module\s+\"[a-zA-Z0-9._]+\.([^\s:.]+)\".*$/\\1/m,module/" --languages=MYLUA --excmd=number -R .

这没关系。

于 2014-12-26T04:26:41.777 回答