Slice support.

This commit is contained in:
Alec Thomas
2018-05-17 19:39:48 +10:00
parent cb88963909
commit b9d002b746
6 changed files with 149 additions and 68 deletions
+2 -9
View File
@@ -1,7 +1,6 @@
package kong
import (
"fmt"
"strconv"
)
@@ -19,12 +18,6 @@ const (
PositionalArgumentToken // <arg>
)
type TokenAssertionError struct{ err error }
func (t TokenAssertionError) Error() string {
return t.err.Error()
}
type Token struct {
Value string
Type TokenType
@@ -84,11 +77,11 @@ func (s *Scanner) Pop() Token {
return arg
}
// PopValue or panic with TokenAssertionError.
// PopValue or panic with Error.
func (s *Scanner) PopValue(context string) string {
t := s.Pop()
if !t.IsValue() {
panic(TokenAssertionError{fmt.Errorf("expected %s value but got %s", context, t)})
fail("expected %s value but got %s", context, t)
}
return t.Value
}