我在使用正则表达式解析buildc的构建输出时遇到了一些问题。
输出看起来像
Compiling svd2rust v0.2.1 (file:///C:/trust/svd2rust)
error: expected one of `=>`, `@`, `if`, or `|`, found `Some`
--> src\main.rs:56:9
|
56 | Some("all") =>
| ^^^^
error: aborting due to previous error
error: Could not compile `svd2rust`.
To learn more, run the command again with --verbose.
我目前的任务看起来像是:
{
"version": "0.1.0",
"command": "cargo",
"isShellCommand": true,
"args": ["build"],
"problemMatcher": {
"owner": "build",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "(error):(.*)\\s+-->\\s+(.*):(\\d+):(\\d+)",
"file": 3,
"line": 4,
"column": 5,
"severity": 1,
"message": 2
}
}
}
According to regex101,看起来正则表达式应匹配相应的部分。
答案 0 :(得分:0)
根据VS Code documentation,您需要一个多行问题匹配器。这可能有用;我没有测试它:
{
"version": "0.1.0",
"command": "cargo",
"isShellCommand": true,
"args": ["build"],
"problemMatcher": {
"owner": "build",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": [{
"regexp": "(error):(.*)",
"severity": 1,
"message": 2
},{
"regexp": "-->\\s+([^:]*):(\\d+):(\\d+)",
"file": 1,
"line": 2,
"column": 3
}]
}
}
答案 1 :(得分:0)
正确使用Rust v1.20.0的正则表达式:
"pattern": [{
"regexp": "(error(?:\\[E\\d{4}\\])?|warning):\\s(.*)",
"severity": 1,
"message": 2
},{
"regexp": "-->\\s+([^:]*):(\\d+):(\\d+)",
"file": 1,
"line": 2,
"column": 3
}]