Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ List<CompletionResult> ExecuteGetCommandCommand(bool useModulePrefix)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-macos
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /Users/vsts/agent/2.155.1/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /Users/vsts/agent/2.155.1/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-windows
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\PowerShellGet\PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\PowerShellGet\PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-linux
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-macos
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /Users/vsts/agent/2.155.1/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /Users/vsts/agent/2.155.1/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-linux
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-windows
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\PowerShellGet\PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\PowerShellGet\PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-linux
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-windows
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\PowerShellGet\PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\PowerShellGet\PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-macos
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /Users/runner/runners/2.158.0/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /Users/runner/runners/2.158.0/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-linux
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-macos
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /Users/runner/runners/2.165.2/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, /Users/runner/runners/2.165.2/work/1/s/test/powershell/Modules/PowerShellGet/PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirkMunro, your last commit had 2 failures in PowerShell-CI-windows
PowerShellGet - Script tests (Admin).Should install a script correctly to the required location with AllUsers scope

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\PowerShellGet\PowerShellGet.Tests.ps1: line 234
234:         $installedScriptInfo | Should -Not -BeNullOrEmpty

PowerShellGet - Script tests.Should install a script correctly to the required location with default CurrentUser scope

Expected a value, but got $null or empty.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\PowerShellGet\PowerShellGet.Tests.ps1: line 207
207:         $installedScriptInfo | Should -Not -BeNullOrEmpty


private static readonly HashSet<string> s_keywordsToExcludeFromAddingAmpersand
= new HashSet<string>(StringComparer.OrdinalIgnoreCase) { TokenKind.InlineScript.ToString(), TokenKind.Configuration.ToString() };
= new HashSet<string>(StringComparer.OrdinalIgnoreCase) { TokenKind.Configuration.ToString() };
internal static CompletionResult GetCommandNameCompletionResult(string name, object command, bool addAmpersandIfNecessary, string quote)
{
string syntax = name, listItem = name;
Expand Down
127 changes: 35 additions & 92 deletions src/System.Management.Automation/engine/parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,6 @@ private StatementAst StatementRule()
break;
case TokenKind.Function:
case TokenKind.Filter:
case TokenKind.Workflow:
statement = FunctionDeclarationRule(token);
break;
case TokenKind.Return:
Expand All @@ -2044,17 +2043,25 @@ private StatementAst StatementRule()
case TokenKind.Data:
statement = DataStatementRule(token);
break;
case TokenKind.Parallel:
case TokenKind.Sequence:
statement = BlockStatementRule(token);
break;
case TokenKind.Configuration:
statement = ConfigurationStatementRule(attributes != null ? attributes.OfType<AttributeAst>() : null, token);
break;
case TokenKind.Workflow:
case TokenKind.Parallel:
case TokenKind.Sequence:
case TokenKind.InlineScript:
ReportError(
token.Extent,
nameof(ParserStrings.DeprecatedKeywordNotAllowed),
ParserStrings.DeprecatedKeywordNotAllowed,
token.Kind.Text());
statement = new ErrorStatementAst(token.Extent);
break;
case TokenKind.From:
case TokenKind.Define:
case TokenKind.Var:
ReportError(token.Extent,
ReportError(
token.Extent,
nameof(ParserStrings.ReservedKeywordNotAllowed),
ParserStrings.ReservedKeywordNotAllowed,
token.Kind.Text());
Expand Down Expand Up @@ -2104,7 +2111,8 @@ private StatementAst StatementRule()
case TokenKind.Using:
statement = UsingStatementRule(token);
// Report an error - usings must appear before anything else in the script, but parse it anyway
ReportError(statement.Extent,
ReportError(
statement.Extent,
nameof(ParserStrings.UsingMustBeAtStartOfScript),
ParserStrings.UsingMustBeAtStartOfScript);
break;
Expand Down Expand Up @@ -2326,45 +2334,6 @@ private StatementAst BlockStatementRule(Token kindToken)
return new BlockStatementAst(ExtentOf(kindToken, body), kindToken, body);
}

/// <summary>
/// Handle the InlineScript syntax in the script workflow.
/// </summary>
/// <param name="inlineScriptToken"></param>
/// <param name="elements"></param>
/// <returns>
/// true -- InlineScript parsing successful
/// false -- InlineScript parsing unsuccessful
/// </returns>
private bool InlineScriptRule(Token inlineScriptToken, List<CommandElementAst> elements)
{
// G Command
// G InlineScript scriptblock-expression

Diagnostics.Assert(elements != null && elements.Count == 0, "The CommandElement list should be empty");
var commandName = new StringConstantExpressionAst(inlineScriptToken.Extent, inlineScriptToken.Text, StringConstantType.BareWord);
inlineScriptToken.TokenFlags |= TokenFlags.CommandName;
elements.Add(commandName);

SkipNewlines();
Token lCurly = NextToken();

if (lCurly.Kind != TokenKind.LCurly)
{
// ErrorRecovery: If there is no opening curly, assume it hasn't been entered yet and don't consume anything.

UngetToken(lCurly);
ReportIncompleteInput(After(inlineScriptToken),
nameof(ParserStrings.MissingStatementAfterKeyword),
ParserStrings.MissingStatementAfterKeyword,
inlineScriptToken.Text);
return false;
}

var expr = ScriptBlockExpressionRule(lCurly);
elements.Add(expr);
return true;
}

private StatementAst IfStatementRule(Token ifToken)
{
// G if-statement:
Expand Down Expand Up @@ -5233,7 +5202,7 @@ private StatementAst MethodDeclarationRule(Token functionNameToken, string class
SetTokenizerMode(TokenizerMode.Command);
ScriptBlockAst scriptBlock = ScriptBlockRule(lCurly, false, baseCtorCallStatement);
var result = new FunctionDefinitionAst(ExtentOf(functionNameToken, scriptBlock),
/*isFilter:*/false, /*isWorkflow:*/false, functionNameToken, parameters, scriptBlock);
/*isFilter:*/false, functionNameToken, parameters, scriptBlock);

return result;
}
Expand All @@ -5248,7 +5217,6 @@ private StatementAst FunctionDeclarationRule(Token functionToken)
// G function-statement:
// G 'function' new-lines:opt function-name function-parameter-declaration:opt '{' script-block '}'
// G 'filter' new-lines:opt function-name function-parameter-declaration:opt '{' script-block '}'
// G 'workflow' new-lines:opt function-name function-parameter-declaration:opt '{' script-block '}'
// G
// G function-name:
// G command-argument
Expand Down Expand Up @@ -5320,26 +5288,12 @@ private StatementAst FunctionDeclarationRule(Token functionToken)
}

bool isFilter = functionToken.Kind == TokenKind.Filter;
bool isWorkflow = functionToken.Kind == TokenKind.Workflow;

bool oldTokenizerWorkflowContext = _tokenizer.InWorkflowContext;
try
{
_tokenizer.InWorkflowContext = isWorkflow;

ScriptBlockAst scriptBlock = ScriptBlockRule(lCurly, isFilter);
var functionName = (functionNameToken.Kind == TokenKind.Generic)
? ((StringToken)functionNameToken).Value
: functionNameToken.Text;
ScriptBlockAst scriptBlock = ScriptBlockRule(lCurly, isFilter);

FunctionDefinitionAst result = new FunctionDefinitionAst(ExtentOf(functionToken, scriptBlock),
isFilter, isWorkflow, functionNameToken, parameters, scriptBlock);
return result;
}
finally
{
_tokenizer.InWorkflowContext = oldTokenizerWorkflowContext;
}
FunctionDefinitionAst result = new FunctionDefinitionAst(ExtentOf(functionToken, scriptBlock),
isFilter, functionNameToken, parameters, scriptBlock);
return result;
}

private List<ParameterAst> FunctionParameterDeclarationRule(out IScriptExtent endErrorStatement, out Token rParen)
Expand Down Expand Up @@ -6624,42 +6578,31 @@ internal Ast CommandRule(bool forDynamicKeyword)
break;

default:
if (token.Kind == TokenKind.InlineScript && context == CommandArgumentContext.CommandName)
{
scanning = InlineScriptRule(token, elements);
Diagnostics.Assert(elements.Count >= 1, "We should at least have the command name: inlinescript");
endExtent = elements.Last().Extent;
var ast = GetCommandArgument(context, token);

if (!scanning) { continue; }
}
else
// If this is the special verbatim argument syntax, look for the next element
StringToken argumentToken = token as StringToken;
if ((argumentToken != null) && string.Equals(argumentToken.Value, VERBATIM_ARGUMENT, StringComparison.OrdinalIgnoreCase))
{
var ast = GetCommandArgument(context, token);
elements.Add(ast);
endExtent = ast.Extent;

// If this is the special verbatim argument syntax, look for the next element
StringToken argumentToken = token as StringToken;
if ((argumentToken != null) && string.Equals(argumentToken.Value, VERBATIM_ARGUMENT, StringComparison.OrdinalIgnoreCase))
var verbatimToken = GetVerbatimCommandArgumentToken();
if (verbatimToken != null)
{
foundVerbatimArgument = true;
scanning = false;
ast = new StringConstantExpressionAst(verbatimToken.Extent, verbatimToken.Value, StringConstantType.BareWord);
elements.Add(ast);
endExtent = ast.Extent;

var verbatimToken = GetVerbatimCommandArgumentToken();
if (verbatimToken != null)
{
foundVerbatimArgument = true;
scanning = false;
ast = new StringConstantExpressionAst(verbatimToken.Extent, verbatimToken.Value, StringConstantType.BareWord);
elements.Add(ast);
endExtent = ast.Extent;
}

break;
}

endExtent = ast.Extent;
elements.Add(ast);
break;
}

endExtent = ast.Extent;
elements.Add(ast);

break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,6 @@ public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst fun
CheckForDuplicateParameters(functionDefinitionAst.Parameters);
}

if (functionDefinitionAst.IsWorkflow)
{
_parser.ReportError(functionDefinitionAst.Extent,
nameof(ParserStrings.WorkflowNotSupportedInPowerShellCore),
ParserStrings.WorkflowNotSupportedInPowerShellCore);
}

return AstVisitAction.Continue;
}

Expand Down Expand Up @@ -1143,11 +1136,6 @@ public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst

public override AstVisitAction VisitBlockStatement(BlockStatementAst blockStatementAst)
{
if (blockStatementAst.IsInWorkflow())
{
return AstVisitAction.Continue;
}

_parser.ReportError(blockStatementAst.Kind.Extent,
nameof(ParserStrings.UnexpectedKeyword),
ParserStrings.UnexpectedKeyword,
Expand Down Expand Up @@ -2363,8 +2351,8 @@ public override AstVisitAction VisitBlockStatement(BlockStatementAst blockStatem
{
// Keyword blocks are not allowed
ReportError(blockStatementAst,
nameof(ParserStrings.ParallelAndSequenceBlockNotSupportedInDataSection),
ParserStrings.ParallelAndSequenceBlockNotSupportedInDataSection);
nameof(ParserStrings.BlockStatementNotSupportedInDataSection),
ParserStrings.BlockStatementNotSupportedInDataSection);

return AstVisitAction.Continue;
}
Expand Down
Loading