Repository navigation
[WIP] Support ListExpression '@[]' in PowerShell - #5762
Dongbo Wang (daxian-dbw) wants to merge 3 commits into
Conversation
|
You could consider 2 character tokens. For example, F# uses this syntax for an array literal: [| 1; 2 |]There are other possibilities that probably aren't breaking changes, e.g. The key here is to use a second character that can't be in a command name. |
|
Jason Shirk (@lzybkr) that's a good idea! I didn't think in that way. It would be great if we can have |
|
The proposal now is to use a type accelerator |
PR Summary
Another attempt to address #5643
This design is to add the
ListExpression '@[]'to PowerShell, which is similar toArrayExpression '@()'but always returns aList<object>.Please review with #5761 as a comparison, where list is supported as a
ListLiteralExpression, similar toArrayLiteralExpression.A blocking issue
@[]has aSubExpressionlike'@()'and'$()'. However, unlike the closing parenthesis character')', the closing bracket character']'doesn't always force to start a new token, and it can be included in a generic token, meaning that']'can appear in a command name, argument, or function name. This makes it impossible for@[dir]to determine the ending of the list expression becausedir]will be treated as a single generic token.This PR adds the property
InListSubExpressiontoTokenizer, and makes']'a force-to-start-new-token character when_tokenizer.InListSubExpressionis set. This approach solves the most common UX problem but is by no way perfect, for example, comparing to@(funcHas[]inName)or@(dir has[]inpath),@[funcHas[]inName]and@[dir has[]inpath]won't work because the first']'will force the command name to end.I couldn't find a less hacky solution without breaking changes (make
'['and']'always not included byGenericToken). So I started to think what if we support list in PowerShell like theArrayLiteralExpressioninstead of@(). In that case, a list can only containExpressionelements and hence command name, arguments, and function names won't be a problem for the ending bracket. #5761 was also submitted to support list as aListLiteralExpression.Example
PR Checklist
Note: Please mark anything not applicable to this PR
NA.[feature]if the change is significant or affectes feature testsWIP:to the beginning of the title and remove the prefix when the PR is ready.