/*
 * call-seq: generate(obj)
 *
 * Generates a valid JSON document from object +obj+ and returns the
 * result. If no valid JSON document can be created this method raises a
 * GeneratorError exception.
 */
static VALUE cState_generate(VALUE self, VALUE obj)
{
    VALUE result = cState_partial_generate(self, obj);
    VALUE re, args[2];
    GET_STATE(self);
    if (!state->quirks_mode) {
        args[0] = rb_str_new2("\\A\\s*(?:\\[.*\\]|\\{.*\\})\\s*\\Z");
        args[1] = CRegexp_MULTILINE;
        re = rb_class_new_instance(2, args, rb_cRegexp);
        if (NIL_P(rb_funcall(re, i_match, 1, result))) {
            rb_raise(eGeneratorError, "only generation of JSON objects or arrays allowed");
        }
    }
    return result;
}