Support cumulative positional arguments.

This commit is contained in:
Alec Thomas
2018-05-17 20:16:12 +10:00
parent b9d002b746
commit 31fe51f9d8
5 changed files with 49 additions and 8 deletions
+16
View File
@@ -86,6 +86,22 @@ func (s *Scanner) PopValue(context string) string {
return t.Value
}
// PopWhile predicate returns true.
func (s *Scanner) PopWhile(predicate func(Token) bool) (values []string) {
for predicate(s.Peek()) {
values = append(values, s.Pop().Value)
}
return
}
// PopUntil predicate returns true.
func (s *Scanner) PopUntil(predicate func(Token) bool) (values []string) {
for !predicate(s.Peek()) {
values = append(values, s.Pop().Value)
}
return
}
func (s *Scanner) Peek() Token {
if len(s.args) == 0 {
return Token{Type: EOLToken}