+static bool tok_take_expr(struct parse_state *ps, const char *term)
+{
+ while (!tok_is(&ps->toks, term)) {
+ if (tok_take_if(&ps->toks, "(")) {
+ if (!tok_take_expr(ps, ")"))
+ return false;
+ } else if (tok_take_if(&ps->toks, "[")) {
+ if (!tok_take_expr(ps, "]"))
+ return false;
+ } else if (!tok_take(&ps->toks))
+ return false;
+ }
+ return tok_take(&ps->toks);
+}
+
+static char *tok_take_expr_str(const tal_t *ctx,
+ struct parse_state *ps,
+ const char *term)
+{
+ const struct token *start = tok_peek(&ps->toks);
+
+ if (!tok_take_expr(ps, term))
+ return NULL;
+
+ return string_of_toks(ctx, start, ps->toks - 1);
+}
+