trlsmax
V2EX  ›  问与答

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

  •  
  •   trlsmax · May 23, 2018 · 3038 views
    This topic created in 2912 days ago, the information mentioned may be changed or developed.

    各位大神好, 我现在有个需求是用 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
    

    但这样是不行的

    Supplement 1  ·  May 24, 2018
    这样写就可以了,是自己不会正则
    "regexp": "^//*//*//* (error|warning) c\\d+ in line (\\d+) of (.*?): (.*)$",
    2 replies    2018-05-23 14:24:08 +08:00
    golmic
        1
    golmic  
       May 23, 2018 via Android
    我觉得,你可以发原始文本和想匹配的文本。然后我可以看看怎么写正则。这个问题感觉和 vscode 无关
    trlsmax
        2
    trlsmax  
    OP
       May 23, 2018
    原始文本
    ```
    [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 里不行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2841 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:28 · PVG 23:28 · LAX 08:28 · JFK 11:28
    ♥ Do have faith in what you're doing.