Parse optional comma(s) after switch expression
This commit is contained in:
parent
ffb8b3009d
commit
ddd52f169d
@ -594,6 +594,15 @@ namespace Parser
|
|||||||
{
|
{
|
||||||
var switchKeyword = EatIdentifier("switch");
|
var switchKeyword = EatIdentifier("switch");
|
||||||
var expression = ParseExpression();
|
var expression = ParseExpression();
|
||||||
|
var commas = new List<TokenNode>();
|
||||||
|
while (CurrentToken.Kind == TokenKind.Comma)
|
||||||
|
{
|
||||||
|
commas.Add(Factory.Token(EatToken()));
|
||||||
|
}
|
||||||
|
if (commas.Count == 0)
|
||||||
|
{
|
||||||
|
commas = null;
|
||||||
|
}
|
||||||
var casesList = new List<SwitchCaseNode>();
|
var casesList = new List<SwitchCaseNode>();
|
||||||
while (CurrentToken.Kind == TokenKind.Identifier
|
while (CurrentToken.Kind == TokenKind.Identifier
|
||||||
&& CurrentToken.PureToken.LiteralText == "case")
|
&& CurrentToken.PureToken.LiteralText == "case")
|
||||||
@ -606,7 +615,8 @@ namespace Parser
|
|||||||
Factory.Token(switchKeyword),
|
Factory.Token(switchKeyword),
|
||||||
expression,
|
expression,
|
||||||
casesList,
|
casesList,
|
||||||
Factory.Token(endKeyword));
|
Factory.Token(endKeyword),
|
||||||
|
commas);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpressionStatementNode ParseExpressionStatement()
|
public ExpressionStatementNode ParseExpressionStatement()
|
||||||
|
@ -123,9 +123,15 @@ namespace Parser
|
|||||||
ExpressionNode switchExpression,
|
ExpressionNode switchExpression,
|
||||||
List<SwitchCaseNode> cases,
|
List<SwitchCaseNode> cases,
|
||||||
TokenNode endKeyword,
|
TokenNode endKeyword,
|
||||||
|
List<TokenNode> optionalCommasAfterExpression,
|
||||||
TokenNode semicolonOrComma = null)
|
TokenNode semicolonOrComma = null)
|
||||||
{
|
{
|
||||||
var children = new List<SyntaxNode> { switchKeyword, switchExpression };
|
var children = new List<SyntaxNode> { switchKeyword, switchExpression };
|
||||||
|
if (optionalCommasAfterExpression != null)
|
||||||
|
{
|
||||||
|
children.AddRange(optionalCommasAfterExpression);
|
||||||
|
}
|
||||||
|
|
||||||
children.AddRange(cases);
|
children.AddRange(cases);
|
||||||
children.Add(endKeyword);
|
children.Add(endKeyword);
|
||||||
if (semicolonOrComma != null)
|
if (semicolonOrComma != null)
|
||||||
@ -139,7 +145,8 @@ namespace Parser
|
|||||||
switchExpression,
|
switchExpression,
|
||||||
cases,
|
cases,
|
||||||
endKeyword,
|
endKeyword,
|
||||||
semicolonOrComma);
|
semicolonOrComma,
|
||||||
|
optionalCommasAfterExpression);
|
||||||
SetParent(result);
|
SetParent(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -219,6 +219,7 @@ namespace Parser
|
|||||||
{
|
{
|
||||||
public TokenNode SwitchKeyword { get; }
|
public TokenNode SwitchKeyword { get; }
|
||||||
public ExpressionNode SwitchExpression { get; }
|
public ExpressionNode SwitchExpression { get; }
|
||||||
|
public List<TokenNode> OptionalCommasAfterExpression { get; }
|
||||||
public List<SwitchCaseNode> Cases { get; }
|
public List<SwitchCaseNode> Cases { get; }
|
||||||
public TokenNode EndKeyword { get; }
|
public TokenNode EndKeyword { get; }
|
||||||
|
|
||||||
@ -228,11 +229,13 @@ namespace Parser
|
|||||||
ExpressionNode switchExpression,
|
ExpressionNode switchExpression,
|
||||||
List<SwitchCaseNode> cases,
|
List<SwitchCaseNode> cases,
|
||||||
TokenNode endKeyword,
|
TokenNode endKeyword,
|
||||||
TokenNode semicolonOrComma
|
TokenNode semicolonOrComma,
|
||||||
|
List<TokenNode> optionalCommasAfterExpression = null
|
||||||
) : base(children, semicolonOrComma)
|
) : base(children, semicolonOrComma)
|
||||||
{
|
{
|
||||||
SwitchKeyword = switchKeyword;
|
SwitchKeyword = switchKeyword;
|
||||||
SwitchExpression = switchExpression;
|
SwitchExpression = switchExpression;
|
||||||
|
OptionalCommasAfterExpression = optionalCommasAfterExpression;
|
||||||
Cases = cases;
|
Cases = cases;
|
||||||
EndKeyword = endKeyword;
|
EndKeyword = endKeyword;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user