Skip to content

Argument-mode parsing: Why is a subexpression at the start of an unquoted token treated differently than a variable reference? #3217

@mklement0

Description

@mklement0

This is a primarily a design rationale question:

The issue is that the rules are hard to remember, and perhaps knowing why they are the way they are helps with that.

If these work:

$a = 4
Write-Output $a/H         # -> '4/H'
Write-Output H/$a         # -> 'H/4'
Write-Output H/$(2 + 2)   # -> 'H/4'

why shouldn't Write-Output $(2 + 2)/H expand to '4/H' too, instead of being treated as 2 arguments, 4 and '/H'?

Why is a subexpression at the start treated differently than a variable reference?

Also, why is Write-Output .$HOME treated as 2 arguments (only happens if the . is directly followed by a $)?

For a full discussion, please see this Stack Overflow question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.WG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions