Pash-Project / Pash

An Open Source reimplementation of Windows PowerShell, for Mono.
https://groups.google.com/group/pash-project
BSD 3-Clause "New" or "Revised" License
517 stars 54 forks source link

Leading dot as part of command name #218

Open ForNeVeR opened 10 years ago

ForNeVeR commented 10 years ago

Currently Pash refuses to properly parse the following command:

./file.exe

For some reason it parses the input as a dot followed by /file.exe. Obviously, /file.exe is not the same file as the ./file.exe.

There are two tests in ShellExecutionTest marked as "Ignored because of bug in command parser." due to this problem.

I've traced the problem down to the Irony tokenizer. I think there is an error in our grammar.

sburnicki commented 10 years ago

So the problem is that the leading dot is interpreted as an invocation operator, like in ".{write-host 'foo'}", so Pash currently treats "../file.exe" as "exeucte ./file.exe in this scope". We'd need to distinguish between the dot as invocation operator and as the part of a name. invocations are a dot before a quote (. "./script.ps1"), dollar (. $a) and brace (. {}), I think. However, I'm not sure if I missed something.

I think the grammar would need to differentiate between one of the mentioned cases and all other cases, which should then be regular names/strings. But I don't know the grammar enough to do this ;)

JayBazuzi commented 10 years ago

I invite you to create a Pull Request with a new unit test for this case. That's my favorite kind of bug report. :-)

Jaykul commented 10 years ago

Also parenthesis.

Actually, you can use a* dot followed by a space* in front of anything that can be (or can return) a command: . Get-Something . ../script.ps1 . .\windowspaths.ps1 . $CommandInAVariable . FunctionName . ScriptInMyPathName . (nested code which returns a command)

But you can put it without the space in front of single or double quotes, parenthesis, dollar, curly braces... ."Get-Command" .'Get-Command' .$CommandInAVariable .${CommandInAVariable} .(get-command ls) # executes get-childitem .$(get-command ls) # executes get-childitem .(ls .ps1 -recurse | select -first 1) .("ls") .(get-module PoshCode) { Get-Variable -Scope Script } *# this invokes the scriptblock in the module scope .{ <#script#> }

There are probably other cases I haven't thought of... but I can't think of them ;-) The same rules apply for the call operator "&"

Joel "Jaykul" Bennett http://HuddledMasses.org http://PowerShellGroup.org

On Sat, May 24, 2014 at 11:32 AM, sburnicki notifications@github.com wrote:

So the problem is that the leading dot is interpreted as an invocation operator, like in ".{write-host 'foo'}", so Pash currently treats "../file.exe" as "exeucte ./file.exe in this scope". We'd need to distinguish between the dot as invocation operator and as the part of a name. invocations are a dot before a quote (. "./script.ps1"), dollar (. $a) and brace (. {}), I think. However, I'm not sure if I missed something.

I think the grammar would need to differentiate between one of the mentioned cases and all other cases, which should then be regular names/strings. But I don't know the grammar enough to do this ;)

— Reply to this email directly or view it on GitHub https://github.com/Pash-Project/Pash/issues/218#issuecomment-44090650.