gpt4 book ai didi

ctags 正则表达式用于一行中的多个声明

转载 作者:行者123 更新时间:2023-12-02 02:39:34 26 4
gpt4 key购买 nike

我正在为自定义语言编写一个 .ctags 文件...与大多数语言一样,它允许在一行中声明多个变量...即:

int a, b, c;

我有一个识别“a”的基本正则表达式:

--regex-mylang=/^[ \t]*int[ \t]*([a-zA-Z_0-9]+)/\1/v,variable/

如何修改它以使其也匹配“b”和“c”?我在 ctags 文档中找不到任何处理单行中多个匹配的内容。

最佳答案

最新通用 ctag 可以捕获它们。

[jet@localhost]/tmp% cat input.x 
int a, b, c;

[jet@localhost]/tmp% cat x.ctags
--langdef=X
--map-X=.x

--kinddef-X=v,var,variables
--_tabledef-X=main
--_tabledef-X=vardef

--_mtable-regex-X=main/int[ \t]+//{tenter=vardef}
--_mtable-regex-X=main/.//

--_mtable-regex-X=vardef/([a-zA-Z0-9]+)/\1/v/
--_mtable-regex-X=vardef/;//{tleave}
--_mtable-regex-X=vardef/.//


[jet@localhost]/tmp% u-ctags --options=x.ctags -o - ./input.x
a ./input.x /^int a, b, c;$/;" v
b ./input.x /^int a, b, c;$/;" v
c ./input.x /^int a, b, c;$/;" v

参见https://docs.ctags.io/en/latest/optlib.html#advanced-pattern-matching-with-multiple-regex-tables了解更多详情。

关于ctags 正则表达式用于一行中的多个声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10741664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com