Rearrange control expression parsing
This commit is contained in:
parent
84a888738a
commit
c0767bc386
19
Parser.cs
19
Parser.cs
@ -163,6 +163,25 @@ class Parser
|
||||
return ifExpr();
|
||||
}
|
||||
|
||||
private Expr control()
|
||||
{
|
||||
switch (peek().type)
|
||||
{
|
||||
case TokenType.If:
|
||||
advance();
|
||||
Expr condition = expression();
|
||||
consume(TokenType.Then, "Expect 'then' after condition.");
|
||||
Expr thenCase = expression();
|
||||
consume(TokenType.Else, "Expect 'else' after 'then' case.");
|
||||
Expr elseCase = expression();
|
||||
return new If { Condition = condition, Then = thenCase, Else = elseCase };
|
||||
case TokenType.When:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
return primary();
|
||||
}
|
||||
|
||||
private Expr ifExpr()
|
||||
{
|
||||
if (match(TokenType.If))
|
||||
|
Loading…
Reference in New Issue
Block a user