Expand Gotlin language and tooling
This commit is contained in:
parent
8f4f858d86
commit
de1262b4cf
41 changed files with 6059 additions and 379 deletions
28
internal/lang/foreach.go
Normal file
28
internal/lang/foreach.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package lang
|
||||
|
||||
import "fmt"
|
||||
|
||||
func (p *parser) parseForEach() (Stmt, error) {
|
||||
if _, err := p.expect(tokenLParen, "expected '(' after 'for'"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name, err := p.expect(tokenIdent, "expected iteration variable")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := p.expect(tokenIn, "expected 'in' after iteration variable"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
source, err := p.parseExpr(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := p.expect(tokenRParen, "expected ')' after iteration source"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body, err := p.parseBlock()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid for body: %w", err)
|
||||
}
|
||||
return ForEachStmt{Name: name.lexeme, Source: source, Body: body}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue