即使子表达式是平衡的,Powershell也会报告MissingEndParenthesisInExpression

问题描述 投票:3回答:1

这是我的子表达式:

    """$((($l -split " """)[1] -split """ ")[0])"""

我检查过,发现没有不成对的括号。然而,powershell坚持在表达中说“缺少关闭”)。有趣的是,表达

    $((($l -split " """)[1] -split """ ")[0])

工作良好。

以前有没有类似的经历?这是Powershell的错误吗?

powershell
1个回答
3
投票

这个..真的很有趣,是的,至少到目前为止,我认为这是一个bug。

这是一个更简单的repro:

"$("`"")"
"$("""")"

这似乎是由于在可扩展字符串内使用双引号转义(反引号或双引号),在子表达式内部引起的。

它似乎也是错误,直到解析器本身:

$sb = @'
"$("`"")"
'@

$tokens = $null
$er = $null

$ast = [System.Management.Automation.Language.Parser]::ParseInput($sb, [ref]$tokens, [ref]$er)

$ast.EndBlock.Statements[0].PipelineElements[0].Expression.NestedExpressions

$tokens[0].NestedTokens

它找到的嵌套标记/表达式不正确。

我在WLS上使用Windows PowerShell 5.1和PowerShell Core 6.0.0-rc.2进行了测试。

Relevant Issues

© www.soinside.com 2019 - 2024. All rights reserved.