gpt4 book ai didi

parsing - Powershell:引用解析的不一致/奇怪行为?

转载 作者:行者123 更新时间:2023-12-04 00:24:04 24 4
gpt4 key购买 nike

全部!我正在尝试使用 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 将其执行为:(bluenavpurple 文本,因为它们出现在 PowerShell ISE 中)

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

这会吐出以下错误:

The string starting:
At line:1 char:147
+ 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
is missing the terminator: ".
At line:1 char:163

所以它似乎将句号解释为引号。这是奇特的。还有其他人在使用 PowerShell 时遇到过这个问题吗?

我尝试过的事情:

  1. 转义引号
  2. 确保所有引号都是“直引号”而不是斜引号
  3. 在引号前放置一个空格(解析正确,但程序不理解参数。)

谢谢,查尔斯。

最佳答案

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

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

请注意,在引号 (") 作为参数本身的一部分传递 的情况下,我用单引号 (') 将整个参数括起来。从下面的实验中可以可见只有 -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)

So it does indeed appear to have something to do with the . and - combination (and it might not be exclusive). From the above I believe that a token starting with - does not include the . character as a valid character in the token so the lexer terminates said token and starts a new token -- easily provable with a good EBNF reference, which I don't have.


The best I can find is Appendix C: The PowerShell Grammar:

The ParameterToken rule is used to match cmdlet parameters such as -foo or - boolProp: . Note that this rule will also match --foobar, so this rule has to be checked before the --token rule.

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

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

关于parsing - Powershell:引用解析的不一致/奇怪行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6880187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com