func AssertTokenType(t *testing.T, tokenType ast.TokenType, token *ast.Token) { assert.NotNil(t, token) if tokenType != token.Type { OutputRed(t, "not ok - expecting %s. Got %s '%s'", tokenType.String(), token.Type.String(), token.Str) } else { OutputGreen(t, "ok - expecting %s. Got %s '%s'", tokenType.String(), token.Type.String(), token.Str) } assert.Equal(t, tokenType, token.Type) }
func (parser *Parser) expect(tokenType ast.TokenType) *ast.Token { var tok = parser.next() if tok != nil && tok.Type != tokenType { parser.backup() panic(SyntaxError{ Reason: tokenType.String(), ActualToken: tok, File: parser.File, }) } return tok }