【问题标题】:VSCode Extension: problem matching on compiler output with blank lineVSCode 扩展:编译器输出与空行匹配的问题
【发布时间】:2020-06-21 10:57:50
【问题描述】:

我目前正在为 Campbell Scientific 数据记录器使用的语言编写 vscode 扩展。我所做的部分扩展为编译器结果指定了一个自定义问题匹配器。

我遇到的问题是,当我使用 tasks.json 中的任务将 crbasic 程序 (test.cr300) 发送到编译器时,我无法匹配编译器结果顶部的文件名。

编辑:这是由于文件名和错误消息之间的空白行。我目前无法找到解决此问题的方法。即使在 https://regex101.com/ 上工作,将 \n 添加到模式也无法按预期工作。

编译器返回的文本示例:

test.cr300 -- Compile Failed!
 
line 12: Undeclared variable U1. 
line 18: gmx600 not yet declared so cannot be aliased. 
line 19: gmx600 not yet declared so cannot be aliased. 
line 20: gmx600 not yet declared so cannot be aliased. 
line 21: gmx600 not yet declared so cannot be aliased.

我的 package.json 中指定的模式:

 "pattern": [
                {
                    "regexp": "^(.*\\.cr300).*\\n$",
                    "file": 1
                },
                {
                    "regexp": "^line\\s(\\d+):\\s(.+)$",
                    "line": 1,
                    "message": 2,
                    "loop": true
                }
            ]

这是我在调试中运行扩展时来自 tasks.json 的任务。

        {
        "label": "CRBasic: Compiler",
        "type": "shell",
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "options": {
            "shell": {
                "executable": "powershell.exe"
            }
        },
        "command": "${config:CRBasic.Path.Compiler path}\\cr300comp.exe",
        "args": [
            "${file}"
        ],
        "problemMatcher": [
            "$crbasicCompiler"
        ]
    }

【问题讨论】:

    标签: regex visual-studio-code


    【解决方案1】:

    您需要更改正则表达式的顺序并添加loop 属性并更改linemessage 的组号

    "pattern": [
        {
            "regexp": "^(.*\\.cr300) -- Compile Failed.*$",
            "file": 1
        },
        {  "regexp": "^\\s*$"  },
        {
            "regexp": "^line\\s(\\d+):\\s(.+)$",
            "line": 1,
            "message": 2,
            "loop": true
        }
    ]
    

    【讨论】:

    • 感谢 rioV8。我确实找到了有关循环的信息并按照建议进行了更改。文件名仍然不匹配。
    • @g0atm1lk 在文档中他们所有的正则表达式都带有^$ 所以我修改了答案
    • 问题在于 test.cr300 和第一条错误消息之间的空行。如果我捏造一些没有空行的输出,它会按预期匹配,只要我添加空行,它就会失败。不幸的是,我找不到解决方法,只需将 \n 添加到模式中是行不通的。有什么建议吗?
    • @g0atm1lk : 添加一个正则表达式来识别空行或带空格的行
    【解决方案2】:

    在将问题缩小到空白行后,下面的模式现在问题与编译输出匹配。事后看来,这似乎很明显。感谢@rioV8 的帮助。

    "pattern": [
                    {
                        "regexp": "^(.*\\.cr300) -- Compile Failed.*$",
                        "file": 1
                    },
                    {
                        "regexp": "^.*$"
                    },
                    {
                        "regexp": "^line\\s(\\d+):\\s(.+)$",
                        "line": 1,
                        "message": 2,
                        "loop": true
                    }
                ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多