Esempio n. 1
0
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)
}
Esempio n. 2
0
File: parser.go Progetto: se77en/c6
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
}