示例#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)
}
示例#2
0
文件: parser.go 项目: imjerrybao/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
}