Parse loops

This commit is contained in:
Sasha Koshka 2024-02-07 18:11:12 -05:00
parent 78050694d6
commit 790f1ca6be

View File

@ -62,8 +62,8 @@ func (this *Parser) parseExpressionRootIdent () (entity.Expression, error) {
switch name {
case "true", "false": return this.parseLiteralBoolean ()
case "nil": return this.parseLiteralNil()
case "if": // TODO
case "loop": // TODO
case "if": return this.parseIfElse()
case "loop": return this.parseLoop()
default: return this.parseVariableOrDeclaration()
}
panic(this.bug())
@ -111,3 +111,23 @@ func (this *Parser) parseVariableOrDeclaration () (entity.Expression, error) {
return variable, nil
}
}
func (this *Parser) parseIfElse () (*entity.IfElse, error) {
// TODO
panic(this.bug())
}
func (this *Parser) parseLoop () (*entity.Loop, error) {
err := this.expectDesc("Loop", lexer.Ident)
if err != nil { return nil, err }
pos := this.pos()
this.next()
body, err := this.parseExpression()
if err != nil { return nil, err }
return &entity.Loop {
Position: pos,
Body: body,
}, nil
}