0

I am trying to match errors of this format for the VSCode ProblemMatcher...

C:\projects\folder\main.cpp(6) : Error[AA000]: identifier "level2" is undefined
C:\projects\folder\main.cpp(7) : Error[AA000]: identifier "level3" is undefined

With regex101.com I am able to match what I need with this regex...

^([][{} \t#%$~A-Za-z0-9_:+\.-\\]+)\(([0-9]+)\) (:) (Warning|Error)(.*)$

Alas, when put into my tasks.json file with the (hopefully) correct escape slashes I don't receive any output in the Problems tab after running the task that will generate these errors in the terminal of VSCode.

// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [      
    {           
        "label": "build simple regex",
        "type": "shell",
        "command": "iarbuild iar_ewb_build_timer.ewp -make Debug -log errors -parallel 8",  
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "problemMatcher": {
            "fileLocation": "absolute",
            "pattern": {
                "regexp": "^([][{} \\t#%$~A-Za-z0-9_:+\\.-\\\\]+)\\(([0-9]+)\\) (:) (Warning|Error)(.*)$",
                "file": 1,
                "line": 2,
                "severity": 4,
                "message": 5
            }
        }
    },
]
}

Perhaps there is a problem with my Regex. Any help?

buck
  • 11
  • 2
  • What part(s) of your error message are you trying to extract? – emsimpson92 Sep 28 '18 at 19:36
  • I don't think you need to escape anything in json other than any double quotes within the regex... – Sal Sep 28 '18 at 19:41
  • i'm trying to extract file path + name, line number, severity (error/warning) and the error message itself. If I don't add the extra backslashes I get messages in the problem tab of vscode saying that the regex is not usable (something to that effect). Perhaps a bug in vscode? – buck Sep 28 '18 at 20:41

1 Answers1

1

I was able to get this working for example error codes in my original post. Thank you for the replies!

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {           
        "label": "build simple regex",
        "type": "shell",
        "command": "iarbuild iar_ewb_build_timer.ewp -make Debug -log errors -parallel 8",  
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "problemMatcher": {
            "fileLocation": "absolute",
            "pattern": {
                "regexp": "^([#%$~A-Za-z0-9_:+-\\\\]+)[(]([0-9]+)[)] (:) (Warning|Error)(.*)$",
                "file": 1,
                "line": 2,
                "severity": 4,
                "message": 5
            }
        }
    },
]
}
buck
  • 11
  • 2
  • There are also plugins that integratie iar even furter into vscode, such as https://github.com/pluyckx/iar-vsc. – spoorcc Jan 27 '19 at 19:10