Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
38c0889
support continuance with pipe at beginning of line
KirkMunro Feb 19, 2019
f71a592
token management logic changed to fix highlighting
KirkMunro Feb 20, 2019
9157e3f
Merge branch 'master' into line-continuance-with-pipe
KirkMunro Feb 20, 2019
10c4780
cleaned up new comments
KirkMunro Feb 20, 2019
7092a36
added pester tests
KirkMunro Feb 21, 2019
51c73e2
CodeFactor changes
KirkMunro Feb 21, 2019
7e0a0e4
Removed legacy V3 code that did nothing
KirkMunro Feb 21, 2019
ad12433
updated pester tests
KirkMunro Feb 21, 2019
0de4529
Merge branch 'master' into line-continuance-with-pipe
KirkMunro Mar 4, 2019
ec4761f
made whitespace at end of line intentional
KirkMunro Mar 4, 2019
f3d2f49
refactored for performance and to fix syntax highlighting
KirkMunro Apr 3, 2019
2e5b590
Merge branch 'master' into line-continuance-with-pipe
KirkMunro Apr 3, 2019
ff03acc
CodeFactor changes
KirkMunro Apr 3, 2019
642d6a3
removing unnecessary/unintentional change
KirkMunro Apr 3, 2019
afe2853
Add argument qualifier to make code more readable
iSazonov Apr 5, 2019
92ced39
Add argument qualifier to make code more readable
iSazonov Apr 5, 2019
cc06b3b
refactor based on PR feedback
KirkMunro Apr 5, 2019
9268e2f
automatic continuance requires contiguous code
KirkMunro Apr 8, 2019
4029ab7
Merge branch 'master' into line-continuance-with-pipe
KirkMunro Apr 8, 2019
0610221
Merge branch 'master' into line-continuance-with-pipe
KirkMunro Apr 26, 2019
b31ec46
CodeFactor changes
KirkMunro Apr 26, 2019
633a904
Merge branch 'master' into line-continuance-with-pipe
KirkMunro May 7, 2019
ad15226
changes for PR feedback; added some Pester tests
KirkMunro May 7, 2019
8f6bb2a
Code review change
KirkMunro May 13, 2019
6580a94
Code review change
KirkMunro May 13, 2019
71395f8
Code review change
KirkMunro May 13, 2019
f7f3938
Code review change
KirkMunro May 13, 2019
01543db
Code review change
KirkMunro May 13, 2019
090cfb7
Code review change
KirkMunro May 13, 2019
29ce0a7
Code review change
KirkMunro May 13, 2019
ea1a80c
Code review change
KirkMunro May 13, 2019
9dc6040
Code review change
KirkMunro May 13, 2019
6b95db2
Merge branch 'master' into line-continuance-with-pipe
KirkMunro May 13, 2019
b4e1a8b
changes for code review
KirkMunro May 13, 2019
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
68 changes: 28 additions & 40 deletions src/System.Management.Automation/engine/parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public sealed class Parser
private bool _inConfiguration;
private ParseMode _parseMode;

// private bool _v3FeatureUsed;
internal string _fileName;
internal bool ProduceV2Tokens { get; set; }

Expand Down Expand Up @@ -340,8 +339,6 @@ internal void SetPreviousFirstLastToken(ExecutionContext context)
}
}

// public bool V3FeatureUsed { get { return _v3FeatureUsed; } }

internal List<ParseError> ErrorList { get; }

#region Utilities
Expand All @@ -351,18 +348,7 @@ private void SkipNewlines()
if (_ungotToken == null || _ungotToken.Kind == TokenKind.NewLine)
{
_ungotToken = null;
_tokenizer.SkipNewlines(false, false);
}
}

// Same as SkipNewlines, but remembers is used when we skip lines differently in
// V3.
private void V3SkipNewlines()
{
if (_ungotToken == null || _ungotToken.Kind == TokenKind.NewLine)
{
_ungotToken = null;
_tokenizer.SkipNewlines(false, true);
_tokenizer.SkipNewlines(skipSemis: false);
}
}

Expand All @@ -371,7 +357,7 @@ private void SkipNewlinesAndSemicolons()
if (_ungotToken == null || _ungotToken.Kind == TokenKind.NewLine || _ungotToken.Kind == TokenKind.Semi)
{
_ungotToken = null;
_tokenizer.SkipNewlines(true, false);
_tokenizer.SkipNewlines(skipSemis: true);
}
}

Expand Down Expand Up @@ -431,7 +417,7 @@ private void SyncOnError(bool consumeClosingToken, params TokenKind[] syncTokens
break;

case TokenKind.EndOfInput:
// Never consume <EOF>, but return it so caller
// Never consume <EOF>, but return it to caller
UngetToken(token);
return;
}
Expand Down Expand Up @@ -567,11 +553,6 @@ private static bool IsSpecificParameter(Token token, string parameter)
return parameter.StartsWith(paramToken.ParameterName, StringComparison.OrdinalIgnoreCase);
}

internal void NoteV3FeatureUsed()
{
// _v3FeatureUsed = true;
}

internal void RequireStatementTerminator()
{
var terminatorToken = PeekToken();
Expand Down Expand Up @@ -1086,7 +1067,7 @@ private AttributeBaseAst AttributeRule()
return null;
}

V3SkipNewlines();
SkipNewlines();

Token firstTypeNameToken;
ITypeName typeName = TypeNameRule(allowAssemblyQualifiedNames: true, firstTypeNameToken: out firstTypeNameToken);
Expand Down Expand Up @@ -1229,7 +1210,6 @@ private void AttributeArgumentsRule(ICollection<ExpressionAst> positionalArgumen
// and record that it was defaulted for better error messages.
expr = new ConstantExpressionAst(name.Extent, true);
expressionOmitted = true;
NoteV3FeatureUsed();
}
}
else
Expand Down Expand Up @@ -1361,7 +1341,7 @@ private ITypeName FinishTypeNameRule(Token typeName, bool unBracketedGenericArg

// Array or generic
SkipToken();
V3SkipNewlines();
SkipNewlines();
token = NextToken();
switch (token.Kind)
{
Expand Down Expand Up @@ -1465,14 +1445,14 @@ private ITypeName GenericTypeArgumentsRule(Token genericTypeName, Token firstTok
Token token;
while (true)
{
V3SkipNewlines();
SkipNewlines();
commaOrRBracketToken = NextToken();
if (commaOrRBracketToken.Kind != TokenKind.Comma)
{
break;
}

V3SkipNewlines();
SkipNewlines();

token = PeekToken();
if (token.Kind == TokenKind.Identifier || token.Kind == TokenKind.LBracket)
Expand Down Expand Up @@ -4274,7 +4254,8 @@ private StatementAst ClassDefinitionRule(List<AttributeBaseAst> customAttributes
if (rCurly.Kind != TokenKind.RCurly)
{
UngetToken(rCurly);
ReportIncompleteInput(After(lCurly),
ReportIncompleteInput(
After(lCurly),
rCurly.Extent,
nameof(ParserStrings.MissingEndCurlyBrace),
ParserStrings.MissingEndCurlyBrace);
Expand Down Expand Up @@ -5709,13 +5690,12 @@ private PipelineBaseAst PipelineRule()
// G expression assignment-operator statement
// G
// G pipeline-tail:
// G '|' new-lines:opt command
// G '|' new-lines:opt command pipeline-tail
// G new-lines:opt '|' new-lines:opt command pipeline-tail:opt

var pipelineElements = new List<CommandBaseAst>();
IScriptExtent startExtent = null;

Token pipeToken = null;
Token nextToken = null;
bool scanning = true;
bool background = false;
while (scanning)
Expand Down Expand Up @@ -5821,15 +5801,23 @@ private PipelineBaseAst PipelineRule()
// If the first pipe element is null, the position points to the pipe (ideally it would
// point before, but the pipe could be the first character), otherwise the empty element
// is after the pipe character.
IScriptExtent errorPosition = pipeToken != null ? After(pipeToken) : PeekToken().Extent;
IScriptExtent errorPosition = nextToken != null ? After(nextToken) : PeekToken().Extent;
ReportIncompleteInput(errorPosition,
nameof(ParserStrings.EmptyPipeElement),
ParserStrings.EmptyPipeElement);
}

pipeToken = PeekToken();
nextToken = PeekToken();

switch (pipeToken.Kind)
// Skip newlines before pipe tokens to support (pipe)line continuance when pipe
// tokens start the next line of script
if (nextToken.Kind == TokenKind.NewLine && _tokenizer.IsPipeContinuance(nextToken.Extent))
{
SkipNewlines();
nextToken = PeekToken();
}

switch (nextToken.Kind)
{
case TokenKind.Semi:
case TokenKind.NewLine:
Expand All @@ -5849,7 +5837,7 @@ private PipelineBaseAst PipelineRule()
if (PeekToken().Kind == TokenKind.EndOfInput)
{
scanning = false;
ReportIncompleteInput(After(pipeToken),
ReportIncompleteInput(After(nextToken),
nameof(ParserStrings.EmptyPipeElement),
ParserStrings.EmptyPipeElement);
}
Expand All @@ -5860,10 +5848,10 @@ private PipelineBaseAst PipelineRule()
// Parse in a manner similar to a pipe, but issue an error (for now, but should implement this for V3.)
SkipToken();
SkipNewlines();
ReportError(pipeToken.Extent,
ReportError(nextToken.Extent,
nameof(ParserStrings.InvalidEndOfLine),
ParserStrings.InvalidEndOfLine,
pipeToken.Text);
nextToken.Text);
if (PeekToken().Kind == TokenKind.EndOfInput)
{
scanning = false;
Expand All @@ -5874,10 +5862,10 @@ private PipelineBaseAst PipelineRule()
default:
// ErrorRecovery: don't eat the token, assume it belongs to something else.

ReportError(pipeToken.Extent,
ReportError(nextToken.Extent,
nameof(ParserStrings.UnexpectedToken),
ParserStrings.UnexpectedToken,
pipeToken.Text);
nextToken.Text);
scanning = false;
break;
}
Expand Down Expand Up @@ -6901,7 +6889,7 @@ private ExpressionAst CheckPostPrimaryExpressionOperators(Token token, Expressio
while (token != null)
{
// To support fluent style programming, allow newlines after the member access operator.
V3SkipNewlines();
SkipNewlines();

if (token.Kind == TokenKind.Dot || token.Kind == TokenKind.ColonColon)
{
Expand Down
Loading