VSCode task.json 里的 ProblemMatcher 正则编写请教

2018-05-23 13:48:53 +08:00
 trlsmax

各位大神好, 我现在有个需求是用 VSCode 编写 51 单片机的程序,编译器用的是 keil c51。现在希望编译报错时 VSCode 能识别,参考网上的例子自己改了个 task.json。

编译输出是这样的

[Compiling main.c ...]

c51 compiler v9.00 - sn: t1amc-bzmwsc
copyright keil elektronik gmbh 1987 - 2009
*** warning c500 in line 1 of main.c: license error (r208: renew license id code (lic))

*** error c141 in line 170 of main.c: syntax error near 'display_num'

c51 compilation complete.  1 warning(s),  1 error(s)

在官方推荐的网站 https://regex101.com/’,用以下规则,已经可以匹配到错误

^\*\*\* (error|warning) c\d+ in line (\d+) of (.*): (.*)$

但这个规则放到 task.json 里是报错的,要怎么写? 这样?

"regexp": "^//*//*//* (error|warning) c\\d+ in line (\\d+) of (.*): (.*)$",
"file": 3,
"line": 2,
"severity": 1,
"message": 4

但这样是不行的

2245 次点击
所在节点    问与答
2 条回复
golmic
2018-05-23 13:56:52 +08:00
我觉得,你可以发原始文本和想匹配的文本。然后我可以看看怎么写正则。这个问题感觉和 vscode 无关
trlsmax
2018-05-23 14:24:08 +08:00
原始文本
```
[Compiling main.c ...]

c51 compiler v9.00 - sn: t1amc-bzmwsc
copyright keil elektronik gmbh 1987 - 2009
*** warning c500 in line 1 of main.c: license error (r208: renew license id code (lic))

*** error c141 in line 170 of main.c: syntax error near 'display_num'

c51 compilation complete. 1 warning(s), 1 error(s)
```

要匹配的文本
```
*** error c141 in line 170 of main.c: syntax error near 'display_num'
```
其中,要提取的是 error, 在行 170,文件 main.c,错误信息 syntax error near 'display_num'

我现在用的是
```
^\*\*\* (error|warning) c\d+ in line (\d+) of (.*): (.*)$
```
https://regex101.com 是测试 OK 的,就是在 VSCode 里不行

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/457126

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX