Parse elseif
This commit is contained in:
parent
94c2d75ad8
commit
5e8a1a0abe
@ -450,5 +450,20 @@ namespace Parser.Tests
|
||||
Assert.AreEqual(text, actual.FullText);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseElseif()
|
||||
{
|
||||
var text = @"if a == 1
|
||||
f()
|
||||
elseif a == 2
|
||||
g()
|
||||
elseif a == 3
|
||||
h()
|
||||
end";
|
||||
var sut = CreateParser(text);
|
||||
var actual = sut.ParseStatement();
|
||||
Assert.IsInstanceOf<IfStatementNode>(actual);
|
||||
Assert.AreEqual(text, actual.FullText);
|
||||
}
|
||||
}
|
||||
}
|
@ -811,6 +811,21 @@ namespace Parser
|
||||
elseKeyword = Factory.Token(EatToken());
|
||||
elseBody = ParseStatements();
|
||||
}
|
||||
if (CurrentToken.Kind == TokenKind.Identifier
|
||||
&& CurrentToken.PureToken.LiteralText == "elseif")
|
||||
{
|
||||
elseKeyword = null;
|
||||
var ifStatement = ParseIfStatement();
|
||||
elseBody = Factory.StatementList(new List<SyntaxNode> { ifStatement });
|
||||
return Factory.IfStatement(
|
||||
ifKeyword,
|
||||
condition,
|
||||
body,
|
||||
null,
|
||||
elseBody,
|
||||
null,
|
||||
commas);
|
||||
}
|
||||
|
||||
var endKeyword = Factory.Token(EatIdentifier("end"));
|
||||
return Factory.IfStatement(
|
||||
@ -903,6 +918,10 @@ namespace Parser
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (CurrentToken.PureToken.LiteralText == "elseif")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (CurrentToken.PureToken.LiteralText == "end")
|
||||
{
|
||||
return null;
|
||||
|
@ -483,10 +483,18 @@ namespace Parser
|
||||
if (elseKeyword != null)
|
||||
{
|
||||
children.Add(elseKeyword);
|
||||
}
|
||||
|
||||
if (elseBody != null)
|
||||
{
|
||||
children.Add(elseBody);
|
||||
}
|
||||
|
||||
children.Add(endKeyword);
|
||||
if (endKeyword != null)
|
||||
{
|
||||
children.Add(endKeyword);
|
||||
}
|
||||
|
||||
var result = new IfStatementNode(
|
||||
children,
|
||||
ifKeyword,
|
||||
|
Loading…
x
Reference in New Issue
Block a user