Implemented loop iterators
This commit is contained in:
parent
144810c6c8
commit
ac03657307
17 changed files with 147 additions and 35 deletions
|
@ -1,6 +1,9 @@
|
|||
package ast
|
||||
|
||||
import "git.akyoto.dev/cli/q/src/expression"
|
||||
|
||||
// Loop represents a block of repeatable statements.
|
||||
type Loop struct {
|
||||
Head *expression.Expression
|
||||
Body AST
|
||||
}
|
||||
|
|
|
@ -40,8 +40,15 @@ func parseKeyword(tokens token.List, source []byte, nodes AST) (Node, error) {
|
|||
return nil, err
|
||||
|
||||
case token.Loop:
|
||||
_, _, body, err := block(tokens, source)
|
||||
return &Loop{Body: body}, err
|
||||
blockStart, _, body, err := block(tokens, source)
|
||||
head := tokens[1:blockStart]
|
||||
|
||||
loop := &Loop{
|
||||
Head: expression.Parse(head),
|
||||
Body: body,
|
||||
}
|
||||
|
||||
return loop, err
|
||||
|
||||
case token.Return:
|
||||
if len(tokens) == 1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue