enum segmenter_mode segmenter_mode;
struct stringi_map *vars;
bool *expand;
+ int nesting_countdown;
};
/* Each argument to a macro function is one of:
{
const struct macro_token *input;
size_t n_input;
- int nesting_countdown;
const struct macro_expander *me;
const struct macro_expansion_stack *stack;
bool *expand;
};
static void
-macro_expand (const struct macro_tokens *, int nesting_countdown,
- const struct macro_expander *,
+macro_expand (const struct macro_tokens *, const struct macro_expander *,
const struct macro_expansion_stack *stack,
bool *break_, struct macro_tokens *exp);
struct parse_macro_function_ctx subctx = {
.input = &ctx->input[i],
.n_input = ctx->n_input - i,
- .nesting_countdown = ctx->nesting_countdown,
.me = ctx->me,
.stack = ctx->stack,
};
macro_tokens_from_string__ (&mts, ss_cstr (args.strings[0]),
ctx->me->segmenter_mode, ctx->stack);
struct macro_tokens exp = { .n = 0 };
- macro_expand (&mts, ctx->nesting_countdown - 1, ctx->me,
+ macro_expand (&mts, ctx->me,
&(struct macro_expansion_stack) {
.name = "!EVAL",
.next = ctx->stack,
struct expr_context
{
- int nesting_countdown;
const struct macro_expander *me;
const struct macro_expansion_stack *stack;
};
struct parse_macro_function_ctx fctx = {
.input = p,
.n_input = end - p,
- .nesting_countdown = ctx->nesting_countdown,
.me = ctx->me,
.stack = ctx->stack,
};
static char *
macro_evaluate_expression (const struct macro_token **tokens, size_t n_tokens,
- int nesting_countdown,
const struct macro_expander *me,
const struct macro_expansion_stack *stack)
{
const struct expr_context ctx = {
- .nesting_countdown = nesting_countdown,
.me = me,
.stack = stack,
};
static bool
macro_evaluate_number (const struct macro_token **tokens, size_t n_tokens,
- int nesting_countdown,
const struct macro_expander *me,
const struct macro_expansion_stack *stack,
double *number)
{
- char *s = macro_evaluate_expression (tokens, n_tokens, nesting_countdown,
- me, stack);
+ char *s = macro_evaluate_expression (tokens, n_tokens, me, stack);
if (!s)
return false;
static size_t
macro_expand_if (const struct macro_token *tokens, size_t n_tokens,
- int nesting_countdown, const struct macro_expander *me,
+ const struct macro_expander *me,
const struct macro_expansion_stack *stack,
bool *break_, struct macro_tokens *exp)
{
return 0;
p++;
- char *result = macro_evaluate_expression (&p, end - p, nesting_countdown,
- me, stack);
+ char *result = macro_evaluate_expression (&p, end - p, me, stack);
if (!result)
return 0;
bool b = strcmp (result, "0");
.mts = CONST_CAST (struct macro_token *, start),
.n = n,
};
- macro_expand (&mts, nesting_countdown, me,
- &(struct macro_expansion_stack) {
+ macro_expand (&mts, me, &(struct macro_expansion_stack) {
.name = "!IF",
.next = stack,
},
static size_t
macro_parse_let (const struct macro_token *tokens, size_t n_tokens,
- int nesting_countdown, const struct macro_expander *me,
+ const struct macro_expander *me,
const struct macro_expansion_stack *stack)
{
const struct macro_token *p = tokens;
}
p++;
- char *value = macro_evaluate_expression (&p, end - p, nesting_countdown,
- me, stack);
+ char *value = macro_evaluate_expression (&p, end - p, me, stack);
if (!value)
return 0;
static size_t
macro_expand_do (const struct macro_token *tokens, size_t n_tokens,
- int nesting_countdown, const struct macro_expander *me,
+ const struct macro_expander *me,
const struct macro_expansion_stack *stack,
struct macro_tokens *exp)
{
&& ss_equals_case (p->token.string, ss_cstr ("!IN")))
{
p++;
- char *list = macro_evaluate_expression (&p, end - p, nesting_countdown,
- me, &next_stack);
+ char *list = macro_evaluate_expression (&p, end - p, me, &next_stack);
if (!list)
return 0;
ss_xstrdup (items.mts[i].representation));
bool break_ = false;
- macro_expand (&inner, nesting_countdown,
- me, &next_stack, &break_, exp);
+ macro_expand (&inner, me, &next_stack, &break_, exp);
if (break_)
break;
}
{
p++;
double first;
- if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- me, &next_stack, &first))
+ if (!macro_evaluate_number (&p, end - p, me, &next_stack, &first))
return 0;
if (p >= end || p->token.type != T_MACRO_ID
p++;
double last;
- if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- me, &next_stack, &last))
+ if (!macro_evaluate_number (&p, end - p, me, &next_stack, &last))
return 0;
double by = 1.0;
&& ss_equals_case (p->token.string, ss_cstr ("!BY")))
{
p++;
- if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- me, &next_stack, &by))
+ if (!macro_evaluate_number (&p, end - p, me, &next_stack, &by))
return 0;
if (by == 0.0)
xstrdup (index_s));
bool break_ = false;
- macro_expand (&inner, nesting_countdown,
- me, &next_stack, &break_, exp);
+ macro_expand (&inner, me, &next_stack, &break_, exp);
if (break_)
break;
}
}
static void
-macro_expand (const struct macro_tokens *mts, int nesting_countdown,
+macro_expand (const struct macro_tokens *mts,
const struct macro_expander *me,
const struct macro_expansion_stack *stack,
bool *break_, struct macro_tokens *exp)
{
- if (nesting_countdown <= 0)
+ if (me->nesting_countdown <= 0)
{
macro_error (stack, NULL, _("Maximum nesting level %d exceeded. "
"(Use SET MNEST to change the limit.)"),
.segmenter_mode = me->segmenter_mode,
.expand = me->expand,
.vars = &vars,
+ .nesting_countdown = me->nesting_countdown,
};
- macro_expand (arg, nesting_countdown, &subme,
- &(struct macro_expansion_stack) {
+ macro_expand (arg, &subme, &(struct macro_expansion_stack) {
.name = param->name,
.next = stack,
}, break_, exp);
.segmenter_mode = me->segmenter_mode,
.expand = me->expand,
.vars = &vars,
+ .nesting_countdown = me->nesting_countdown,
};
- macro_expand (arg, nesting_countdown, &subme,
+ macro_expand (arg, &subme,
&(struct macro_expansion_stack) {
.name = "!*",
.next = stack,
continue;
}
- size_t n = macro_expand_if (&mts->mts[i], mts->n - i,
- nesting_countdown, me, stack,
+ size_t n = macro_expand_if (&mts->mts[i], mts->n - i, me, stack,
break_, exp);
if (n > 0)
{
.segmenter_mode = me->segmenter_mode,
.expand = me->expand,
.vars = &vars,
+ .nesting_countdown = me->nesting_countdown - 1,
};
- macro_expand (&submc->macro->body, nesting_countdown - 1,
- &subme, &(struct macro_expansion_stack) {
+ macro_expand (&submc->macro->body, &subme,
+ &(struct macro_expansion_stack) {
.name = submc->macro->name,
.file_name = submc->macro->file_name,
.first_line = submc->macro->first_line,
struct parse_macro_function_ctx ctx = {
.input = &mts->mts[i],
.n_input = mts->n - i,
- .nesting_countdown = nesting_countdown,
.me = me,
.stack = stack,
};
continue;
}
- size_t n = macro_parse_let (&mts->mts[i], mts->n - i,
- nesting_countdown,
- me, stack);
+ size_t n = macro_parse_let (&mts->mts[i], mts->n - i, me, stack);
if (n > 0)
{
i += n - 1;
continue;
}
- n = macro_expand_do (&mts->mts[i], mts->n - i, nesting_countdown, me,
- stack, exp);
+ n = macro_expand_do (&mts->mts[i], mts->n - i, me, stack, exp);
if (n > 0)
{
i += n - 1;
.segmenter_mode = segmenter_mode,
.expand = &expand,
.vars = &vars,
+ .nesting_countdown = settings_get_mnest (),
};
struct macro_expansion_stack stack = {
.first_line = mc->macro->first_line,
.last_line = mc->macro->last_line,
};
- macro_expand (&mc->macro->body, settings_get_mnest (),
- &me, &stack, NULL, exp);
+ macro_expand (&mc->macro->body, &me, &stack, NULL, exp);
stringi_map_destroy (&vars);
}