static void pgf_bracket_lzn_symbol_token(PgfLinFuncs** funcs, PgfToken tok) { PgfBracketLznState* state = gu_container(funcs, PgfBracketLznState, funcs); JNIEnv* env = state->env; jstring jname = gu2j_string(env, tok); gu_buf_push(state->list, jobject, jname); }
bool gu_choice_advance(GuChoice* ch) { gu_assert(ch->path_idx <= gu_buf_length(ch->path)); while (gu_buf_length(ch->path) > ch->path_idx) { size_t last = gu_buf_pop(ch->path, size_t); if (last > 1) { gu_buf_push(ch->path, size_t, last-1); return true; } } return false; }
int gu_choice_next(GuChoice* ch, int n_choices) { gu_assert(n_choices >= 0); gu_assert(ch->path_idx <= gu_buf_length(ch->path)); if (n_choices == 0) { return -1; } int i = 0; if (gu_buf_length(ch->path) > ch->path_idx) { i = (int) gu_buf_get(ch->path, size_t, ch->path_idx); gu_assert(i <= n_choices); } else { gu_buf_push(ch->path, size_t, n_choices); i = n_choices; } int ret = (i == 0) ? -1 : n_choices - i; gu_debug("%p@%d: %d", ch, ch->path_idx, ret); ch->path_idx++; return ret; }
static void pgf_bracket_lzn_end_phrase(PgfLinFuncs** funcs, PgfCId cat, int fid, int lindex, PgfCId fun) { PgfBracketLznState* state = gu_container(funcs, PgfBracketLznState, funcs); JNIEnv* env = state->env; GuBuf* parent = gu_buf_pop(state->stack, GuBuf*); if (gu_buf_length(state->list) > 0) { jstring jcat = gu2j_string(env, cat); jstring jfun = gu2j_string(env, fun); size_t len = gu_buf_length(state->list); jobjectArray jchildren = (*env)->NewObjectArray(env, len, state->object_class, NULL); for (int i = 0; i < len; i++) { jobject obj = gu_buf_get(state->list, jobject, i); (*env)->SetObjectArrayElement(env, jchildren, i, obj); (*env)->DeleteLocalRef(env, obj); } jobject jbracket = (*env)->NewObject(env, state->bracket_class, state->bracket_constrId, jcat, jfun, fid, lindex, jchildren); (*env)->DeleteLocalRef(env, jchildren); (*env)->DeleteLocalRef(env, jfun); (*env)->DeleteLocalRef(env, jcat); gu_buf_push(parent, jobject, jbracket); } state->list = parent; }