gpt4 book ai didi

syntax-error - 如何编写多行错误格式字符串?

转载 作者:行者123 更新时间:2023-12-03 08:12:13 26 4
gpt4 key购买 nike

我想为vim-opencl plugin编写OpenCL语法检查器。 OpenCL编译器会对输出错误进行一些奇怪的格式化。有两种类型的错误。

正常(错误解释少):

"/tmp/OCLUKvOsF.cl", line 143: error: expression must have integral type
rec_table[PRIME_P - ri] = PRIME_P - i;
^

错误说明中的换行符不正常:
"/tmp/OCLUKvOsF.cl", line 148: error: a value of type "uint16" cannot be used
to initialize an entity of type "uint"
uint a = value, b = PRIME_P, u = 0, v = 0;
^

因此,麻烦在于将第二种情况下的错误解释和常规情况下的错误处理两部分串联起来。

我正在使用 syntastic作为通用语法检查器。现在我有这样的代码:
let errorformat = '%E"%f"\, line %l: error: %m,%+C%.%#,%-Z%p^,'.
\'%W"%f"\, line %l: warning: %m,%-C%.%#,'.
\'%-G%.%#'

因此,第一个和第二个错误如下:
program.cl|143 error| expression must have integral type rec_table[PRIME_P - ri] = PRIME_P - i; ^
program.cl|148 col 14 error| a value of type "uint16" cannot be used to initialize an entity of type "uint" uint a = value, b = PRIME_P, u = 0, v = 0;

几乎可以(特别是第二种情况),但是我不知道如何做到这一点:
program.cl|143 col 19 error| expression must have integral type
program.cl|148 col 14 error| a value of type "uint16" cannot be used to initialize an entity of type "uint"

或至少像这样:
program.cl|143 col 19 error| expression must have integral type rec_table[PRIME_P - ri] = PRIME_P - i;
program.cl|148 col 14 error| a value of type "uint16" cannot be used to initialize an entity of type "uint" uint a = value, b = PRIME_P, u = 0, v = 0;

你有什么主意吗

UPD。更新了错误格式和期望

最佳答案

我不知道测试这种情况的有用方法,但是您也需要使用反斜杠来转义空间。

我还可以在%C之后放置-space,以便它们仅匹配以空格开头的行。

最后,对于警告,您将忽略一些行,并且永远在任何地方都没有%Z。 (我认为您不需要在Z前面加上减号,但我对此不清楚;我自己不使用减号。

祝好运。

关于syntax-error - 如何编写多行错误格式字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13256135/

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