Add range loops to entity

This commit is contained in:
Sasha Koshka
2024-03-14 22:28:50 -04:00
parent a7df436d77
commit cdc46f96aa
+35
View File
@@ -467,6 +467,41 @@ func (this *Loop) String () string {
return fmt.Sprint("loop ", this.Body)
}
var _ Expression = &For { }
// For is a special kind of loop that evaluates an expression for each element
// of an array or slice. It accepts an index declaration and an element
// declaration, which are scoped to the loop's body and are set to the index of
// the current element and the element itself respectively at the beginning of
// each iteration. The assignment rules of a for statement are identical to that
// of a normal loop.
type For struct {
// Syntax
Pos errors.Position
Index Expression
Element Expression
Over Expression
Body Expression
// Semantics
Ty Type
}
func (*For) expression(){}
func (this *For) Position () errors.Position { return this.Pos }
func (this *For) Type () Type { return this.Ty }
func (this *For) HasExplicitType () bool {
// this is as accurate as possible without doing a full analysis of the
// loop
return false
}
func (this *For) String () string {
out := "for"
if this.Index != nil {
out += " " + this.Index.String()
}
out += fmt.Sprint(" %v in %v %v", this.Element, this.Over, this.Body)
return out
}
var _ Expression = &Break { }
// Break allows breaking out of loops. It has no value and may not be assigned
// to anything. It is never a valid location expression.