Kierkegaard gives a theory in Concluding Unscientific Postscript to Philosophical Fragments. I don't remember the details very well, but it has something to do with contradiction. I seem to remember near the end he offers some way to distinguish between the ironic and the comic.