Skip to content

Handle special characters in variable names. #49

Open

Description

@daviwil

From Steve Lee (@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

Activity

  1. omniomi commented on May 21, 2018

    @omniomi
    Contributor

    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.

  2. changed the title [-]Syntax highlighting for variables incorrect where ? is treated as token separator[/-] [+]Handle special characters in variable names.[/+] on May 21, 2018
  3. TylerLeonhardt commented on May 21, 2018

    @TylerLeonhardt
    Member
  4. daxian-dbw commented on May 21, 2018

    @daxian-dbw
    Member

    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
    
  5. SteveL-MSFT commented on May 22, 2018

    @SteveL-MSFT
    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.

  6. omniomi commented on May 22, 2018

    @omniomi
    Contributor

    Thanks Steve Lee (@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.

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

  7. SteveL-MSFT commented on May 22, 2018

    @SteveL-MSFT
    Member

    Nick James (@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.

  8. omniomi commented on May 22, 2018

    @omniomi
    Contributor

    Steve Lee (@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions