1

The following Tasks.json Problem matcher regular expression should match the following typical warning. But it doesn't. ctc W505: ["somedirectory/somefile.c" 350/18] implicit declaration blah blah blah

What is the issue ? I verified the built-in parser matches gcc output errors and warnings.

Thanks,

Satish K

"tasks": [
        {
            "label": "build.bat",
            "type": "shell",
            "command": "build.bat",
            "problemMatcher": {
                "owner": "cpptools",
                "fileLocation": [
                    "relative",
                    "${env:PWD}"
                ],
                "pattern": {
                    "regexp": "^ctc W(\\d+): \\[\\\"(.*)\\\" (\\d+)\\\/(\\d+)\\] (.*)$",
                    "file": 2,
                    "line": 3,
                    "column": 4,
                    "message": 5
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
satish
  • 329
  • 2
  • 11

2 Answers2

1

You add an additional \ to the expression, you only need to escape the " and you don't need to escape /

"tasks": [
        {
            "label": "build.bat",
            "type": "shell",
            "command": "build.bat",
            "problemMatcher": {
                "owner": "cpptools",
                "fileLocation": [
                    "relative",
                    "${env:PWD}"
                ],
                "pattern": {
                    "regexp": "^ctc W(\\d+): \\[\"(.*)\" (\\d+)/(\\d+)\\] (.*)$",
                    "file": 2,
                    "line": 3,
                    "column": 4,
                    "message": 5
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]


Edit

This works in regex101 (flavor Javascript)

^ctc W(\d+): \["(.*)" (\d+)\/(\d+)\] (.*)$

To translate it to a JSON string, escape \" and regex also wants you to escape / but that would only be needed if you use the regex in a literal Javascript (like /\d+/g) but we don't do that in VSC, but it won't hurt.

Resulting in:

"^ctc W(\\d+): \\[\"(.*)\" (\\d+)\\/(\\d+)\\] (.*)$"
rioV8
  • 24,506
  • 3
  • 32
  • 49
  • That didn't work either. Also verified it in regex101.com – satish Apr 20 '20 at 10:56
  • @satish I tried in regex101 and it complained about the non escaped `/` – rioV8 Apr 20 '20 at 14:13
  • To test without ctc, i just echoed the following in build.bat @echo ctc W505: ["somedirectory/somefile.c" 350/18] implicit declaration blah blah Vscode recognizes file path by default. But it cannot get the line and column number. – satish Apr 23 '20 at 17:09
  • @satish I tested it with the updated regex and it works, line and column are fetched – rioV8 Apr 23 '20 at 19:16
  • It works with regex. But vscode could not identify line and column numbers. To reproduce the issue, you can execute build.bat with the echo statement inside it. – satish Apr 24 '20 at 15:17
  • @satish I did, and the problem tab shows me the line and column numbers in [] and when I click on that line it jumps to the file and line number and has a red squiggle at the location. – rioV8 Apr 24 '20 at 15:59
1

I couldn't get this to work. But I ran the working regex101 through a json escpare. It did some more escaping of slashes and ended up as:

"regexp": "^ctc W(\\d+): \\[\\\"(.*)\\\" (\\d+)\\/(\\d+)\\] (.*)$",