-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
The following definition of TokenKind.Generic would indicate that all tokens of TokenKind.Generic should be a StringToken. (or specifically either StringLiteral or StringExpandable)
PowerShell/src/System.Management.Automation/engine/parser/token.cs
Lines 65 to 72 in 22c6fb4
| /// <summary> | |
| /// A token that is only valid as a command name, command argument, function name, or configuration name. It may contain | |
| /// characters not allowed in identifiers. | |
| /// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.StringLiteralToken"/> | |
| /// or <see cref="System.Management.Automation.Language.StringExpandableToken"/> if the token contains variable | |
| /// references or subexpressions. | |
| /// </summary> | |
| Generic = 7, |
However, the method Token.SetIsCommandArgument does not guarantee that. This method is used to revert the TokenKind of special tokens when they appear as command names or arguments. Most all the special tokens that receive this treatment are not StringTokens.
PowerShell/src/System.Management.Automation/engine/parser/token.cs
Lines 1200 to 1208 in 22c6fb4
| internal void SetIsCommandArgument() | |
| { | |
| // Rather than expose the setter, we have an explicit method to change a token so that it is | |
| // considered a command argument. This prevent arbitrary changes to the kind which should be safer. | |
| if (_kind != TokenKind.Identifier) | |
| { | |
| _kind = TokenKind.Generic; | |
| } | |
| } |
Should the documentation above TokenKind.Generic be reworded?
Reference PR #10295.