aboutsummaryrefslogtreecommitdiff
path: root/syntax/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'syntax/parse.go')
-rw-r--r--syntax/parse.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/syntax/parse.go b/syntax/parse.go
index 6bc12b3..08a40e3 100644
--- a/syntax/parse.go
+++ b/syntax/parse.go
@@ -111,6 +111,8 @@ func (p *parser) parseStmt(stmts []Stmt) []Stmt {
return append(stmts, p.parseIfStmt())
} else if p.tok == FOR {
return append(stmts, p.parseForStmt())
+ } else if p.tok == WHILE {
+ return append(stmts, p.parseWhileStmt())
}
return p.parseSimpleStmt(stmts)
}
@@ -182,6 +184,18 @@ func (p *parser) parseForStmt() Stmt {
}
}
+func (p *parser) parseWhileStmt() Stmt {
+ whilepos := p.nextToken() // consume WHILE
+ cond := p.parseTest()
+ p.consume(COLON)
+ body := p.parseSuite()
+ return &WhileStmt{
+ While: whilepos,
+ Cond: cond,
+ Body: body,
+ }
+}
+
// Equivalent to 'exprlist' production in Python grammar.
//
// loop_variables = primary_with_suffix (COMMA primary_with_suffix)* COMMA?