Generic recursive-descent parser in Javascript