Fix while, for only running one loop; fix do.

This complete resolves #104.
This commit is contained in:
Qi Xiao 2016-02-14 19:51:56 +01:00
parent f66b39e2ec
commit eda20bad02
2 changed files with 6 additions and 6 deletions

View File

@ -278,7 +278,7 @@ func (cp *compiler) control(n *parse.Control) Op {
// do nothing
} else if ex == Break {
break
} else {
} else if ex != nil {
throw(ex)
}
}
@ -297,7 +297,7 @@ func (cp *compiler) control(n *parse.Control) Op {
// do nothing
} else if ex == Break {
break
} else {
} else if ex != nil {
throw(ex)
}
}

View File

@ -151,10 +151,10 @@ func startsPipeline(r rune) bool {
// it starts a control block.
func findLeader(ps *parser) (string, bool) {
switch leader := ps.findPossibleLeader(); leader {
case "if", "while", "for", "do", "begin":
case "if", "while", "for", "begin":
// Starting leaders are always legal.
return leader, true
case "then", "elif", "else", "fi", "done", "end":
case "then", "elif", "else", "fi", "do", "done", "end":
return leader, false
default:
// There is no leader.
@ -324,6 +324,7 @@ func (ctrl *Control) parse(ps *parser, leader string) {
}
doElseDone := func() {
parseSpaces(ctrl, ps)
if consumeLeader() != "do" {
ps.error(errShouldBeDo)
}
@ -389,7 +390,6 @@ func (ctrl *Control) parse(ps *parser, leader string) {
default:
ps.error(errShouldBePipelineSep)
}
parseSpaces(ctrl, ps)
doElseDone()
case "begin":
ctrl.Kind = BeginControl
@ -398,7 +398,7 @@ func (ctrl *Control) parse(ps *parser, leader string) {
ps.error(errShouldBeEnd)
}
default:
ps.error(fmt.Errorf("unknown leader %q; parser error", leader))
ps.error(fmt.Errorf("unknown leader %q; parser bug", leader))
}
}