Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle special characters in variable names. #49

Open
daviwil opened this issue May 17, 2017 · 7 comments
Open

Handle special characters in variable names. #49

daviwil opened this issue May 17, 2017 · 7 comments
Labels
Milestone

Comments

@daviwil
Copy link
Contributor

daviwil commented May 17, 2017

From @SteveL-MSFT on May 17, 2017 22:58

$foo?bar = 1

"$foo?bar"

only $foo is highlighted as a variable, this causes confusion to the customer as PowerShell treats $foo?bar as the variable (which is allowed)

PSReadline highlights correctly

Copied from original issue: PowerShell/vscode-powershell#759

@omniomi
Copy link
Contributor

omniomi commented May 21, 2018

Is there a list of special characters that don't require ${ } anywhere? Ie, $Foo*bar is allowed but you need to use ${Foo*bar}. I assume it's every special character that isn't an operator or keyword but I could be wrong.

@omniomi omniomi changed the title Syntax highlighting for variables incorrect where ? is treated as token separator Handle special characters in variable names. May 21, 2018
@TylerLeonhardt
Copy link
Member

Hmm I think @JamesWTruher, @daxian-dbw, or @SteveL-MSFT might know the answer to that.

@daxian-dbw
Copy link
Member

daxian-dbw commented May 21, 2018

one more instance I know of is $a:b. There are a few well-known prefixes like $private:, $script:, $global:, but this syntax applies to more scenarios beyond, such as

$function:SayHello = {"Hello"}
SayHello
> Hello

$f:myfile = "content for my file"
$f:myfile
> content for my file
cat F:\myfile
> content for my file

$f:myfile:alternateDataStream = "hidden content"
$f:myfile:alternateDataStream
> hidden content
cat F:\myfile:alternateDataStream
> hidden content

@SteveL-MSFT
Copy link
Member

You can look at the tokenizer code to see what characters are valid. Basically almost anything and if you use a brace, pretty much anything (including whitespace) until a closing brace.

@omniomi
Copy link
Contributor

omniomi commented May 22, 2018

Thanks @SteveL-MSFT.

Will need to give some thought to the best way to tackle variables. With so many ways to PowerShell a cat I want to cover all of the variable variants in as concise a manner as possible. The current definitions are not great.

@daxian-dbw, part of me hates that those are real... part of me thinks that's super cool lol.

@SteveL-MSFT
Copy link
Member

@omniomi It seems that the main set of characters is [A-z0-9_?:]. However, if it's a colon followed by another colon, it's a static member and not part of the variable name like $a::b. And if a brace follows the $, then anything until the closing brace is part of the variable name.

@omniomi
Copy link
Contributor

omniomi commented May 22, 2018

@SteveL-MSFT that works and should probably cover most cases.

I just need to figure out the best way to split everything in the repository so that it can be logically included in other places. How things are highlighted on their own, in strings, in sub-expressions, etc adds to the complexity. Can't just have one variable definition and use it everywhere. Splatting adds to complexity as well since Get-Something @Splat is a variable but $ByLine = "Author: @omniomi" is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants