Powershell:引号解析不一致/奇怪的行为?

2024-01-03

全部!我正在尝试使用 PowerShell 编译程序,但该命令的解析方式很奇怪。 此命令在 cmd.exe 中正确执行:

dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d" "src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d" -D -O -release

但 PowerShell 将其执行为:(blue, navy, purplePowerShell ISE 中显示的文本)

DMD


我相信这应该可以解决问题(添加换行符只是为了清楚起见,并删除额外的引号):

dmd '-od"bin"' '-of"bin\convHull.exe"' '-I"src"'
    src\concSort.d src\fileParser.d src\main.d src\pointLogic.d src\quickHull.d src\stupidHull.d
    -D -O -release

请注意,在引号 (") 的情况下作为论证本身的一部分传递,我用单引号 (') 将整个参数括起来。从下面的实验可以看出only -of"..."需要有关它的报价。

快乐编码。


我找不到关于这个确切产生的好的参考,但是请注意以下解析:


-x"w."   ->  error: " expected (last " is special)
-x"w.""  ->  -x"w and ."" (the . starts a new token and the " in that starts
                           a quote; however, the quotes are not removed)
'-x"w."' ->  -x"w." (extra quote fine, neither special)
-x"w"    ->  -x"w"  (no . and " not special)
-x"w""   ->  -x"w"" (no . and " not special)
a".b"    ->  a.b    (didn't start with `-`, quotes removed)
a".b     ->  error: " expected (" is special)  

所以这看起来确实与. and -组合(并且可能不是排他性的)。从上面我相信一个以- does not包括.字符作为令牌中的有效字符,因此词法分析器终止所述令牌并启动一个新令牌——可以使用良好的 EBNF 参考轻松证明,而我没有。


我能找到的最好的是附录 C:PowerShell 语法 http://www.manning.com/payette/AppCexcerpt.pdf:

ParameterToken 规则用于匹配 cmdlet 参数,例如 -foo 或 - 布尔属性: .注意,这条规则也会匹配 --foobar,所以这条规则有 在 --token 规则之前检查。

<ParameterToken> = -[:letter:]+[:]{0 |1}

然而,这充其量是不完整的,甚至不包括“字母”的定义。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Powershell:引号解析不一致/奇怪的行为? 的相关文章

随机推荐