Parse elseif
This commit is contained in:
parent
94c2d75ad8
commit
5e8a1a0abe
@ -450,5 +450,20 @@ namespace Parser.Tests
|
|||||||
Assert.AreEqual(text, actual.FullText);
|
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());
|
elseKeyword = Factory.Token(EatToken());
|
||||||
elseBody = ParseStatements();
|
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"));
|
var endKeyword = Factory.Token(EatIdentifier("end"));
|
||||||
return Factory.IfStatement(
|
return Factory.IfStatement(
|
||||||
@ -903,6 +918,10 @@ namespace Parser
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else if (CurrentToken.PureToken.LiteralText == "elseif")
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
else if (CurrentToken.PureToken.LiteralText == "end")
|
else if (CurrentToken.PureToken.LiteralText == "end")
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -483,10 +483,18 @@ namespace Parser
|
|||||||
if (elseKeyword != null)
|
if (elseKeyword != null)
|
||||||
{
|
{
|
||||||
children.Add(elseKeyword);
|
children.Add(elseKeyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elseBody != null)
|
||||||
|
{
|
||||||
children.Add(elseBody);
|
children.Add(elseBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (endKeyword != null)
|
||||||
|
{
|
||||||
children.Add(endKeyword);
|
children.Add(endKeyword);
|
||||||
|
}
|
||||||
|
|
||||||
var result = new IfStatementNode(
|
var result = new IfStatementNode(
|
||||||
children,
|
children,
|
||||||
ifKeyword,
|
ifKeyword,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user