const struct macro *macro;
struct macro_tokens **args;
enum segmenter_mode segmenter_mode;
+ bool *expand;
};
/* Each argument to a macro function is one of:
macro_expand (const struct macro_tokens *, int nesting_countdown,
const struct macro_expander *, struct string_map *vars,
const struct macro_expansion_stack *stack,
- bool *expand, bool *break_,
- struct macro_tokens *exp);
+ bool *break_, struct macro_tokens *exp);
static bool
expand_macro_function (struct parse_macro_function_ctx *ctx,
.me = ctx->me,
.stack = ctx->stack,
.vars = ctx->vars,
- .expand = ctx->expand,
};
size_t subinput_consumed;
if (expand_macro_function (&subctx, farg, &subinput_consumed))
&(struct macro_expansion_stack) {
.name = "!EVAL",
.next = ctx->stack,
- }, ctx->expand, NULL, &exp);
+ }, NULL, &exp);
macro_tokens_to_representation (&exp, output, NULL, NULL);
macro_tokens_uninit (&exp);
macro_tokens_uninit (&mts);
const struct macro_expander *me;
const struct macro_expansion_stack *stack;
struct string_map *vars;
- bool *expand;
};
static char *macro_evaluate_or (const struct expr_context *ctx,
.me = ctx->me,
.stack = ctx->stack,
.vars = ctx->vars,
- .expand = ctx->expand,
};
struct string function_output = DS_EMPTY_INITIALIZER;
size_t function_consumed = parse_function_arg (&fctx, 0, &function_output);
int nesting_countdown,
const struct macro_expander *me,
const struct macro_expansion_stack *stack,
- struct string_map *vars, bool *expand)
+ struct string_map *vars)
{
const struct expr_context ctx = {
.nesting_countdown = nesting_countdown,
.me = me,
.stack = stack,
.vars = vars,
- .expand = expand,
};
return macro_evaluate_or (&ctx, tokens, *tokens + n_tokens);
}
int nesting_countdown,
const struct macro_expander *me,
const struct macro_expansion_stack *stack,
- struct string_map *vars,
- bool *expand, double *number)
+ struct string_map *vars, double *number)
{
char *s = macro_evaluate_expression (tokens, n_tokens, nesting_countdown,
- me, stack, vars, expand);
+ me, stack, vars);
if (!s)
return false;
int nesting_countdown, const struct macro_expander *me,
const struct macro_expansion_stack *stack,
struct string_map *vars,
- bool *expand, bool *break_, struct macro_tokens *exp)
+ bool *break_, struct macro_tokens *exp)
{
const struct macro_token *p = tokens;
const struct macro_token *end = tokens + n_tokens;
p++;
char *result = macro_evaluate_expression (&p, end - p, nesting_countdown,
- me, stack, vars, expand);
+ me, stack, vars);
if (!result)
return 0;
bool b = strcmp (result, "0");
.name = "!IF",
.next = stack,
},
- expand, break_, exp);
+ break_, exp);
}
return (end_if + 1) - tokens;
}
macro_parse_let (const struct macro_token *tokens, size_t n_tokens,
int nesting_countdown, const struct macro_expander *me,
const struct macro_expansion_stack *stack,
- struct string_map *vars, bool *expand)
+ struct string_map *vars)
{
const struct macro_token *p = tokens;
const struct macro_token *end = tokens + n_tokens;
p++;
char *value = macro_evaluate_expression (&p, end - p, nesting_countdown,
- me, stack, vars, expand);
+ me, stack, vars);
if (!value)
return 0;
macro_expand_do (const struct macro_token *tokens, size_t n_tokens,
int nesting_countdown, const struct macro_expander *me,
const struct macro_expansion_stack *stack,
- struct string_map *vars,
- bool *expand, struct macro_tokens *exp)
+ struct string_map *vars, struct macro_tokens *exp)
{
const struct macro_token *p = tokens;
const struct macro_token *end = tokens + n_tokens;
{
p++;
char *list = macro_evaluate_expression (&p, end - p, nesting_countdown,
- me, &next_stack, vars,
- expand);
+ me, &next_stack, vars);
if (!list)
return 0;
bool break_ = false;
macro_expand (&inner, nesting_countdown,
- me, vars, &next_stack, expand, &break_, exp);
+ me, vars, &next_stack, &break_, exp);
if (break_)
break;
}
p++;
double first;
if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- me, &next_stack, vars, expand, &first))
+ me, &next_stack, vars, &first))
return 0;
if (p >= end || p->token.type != T_MACRO_ID
double last;
if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- me, &next_stack, vars, expand, &last))
+ me, &next_stack, vars, &last))
return 0;
double by = 1.0;
{
p++;
if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- me, &next_stack, vars, expand, &by))
+ me, &next_stack, vars, &by))
return 0;
if (by == 0.0)
bool break_ = false;
macro_expand (&inner, nesting_countdown,
- me, vars, &next_stack, expand, &break_, exp);
+ me, vars, &next_stack, &break_, exp);
if (break_)
break;
}
macro_expand (const struct macro_tokens *mts, int nesting_countdown,
const struct macro_expander *me, struct string_map *vars,
const struct macro_expansion_stack *stack,
- bool *expand, bool *break_, struct macro_tokens *exp)
+ bool *break_, struct macro_tokens *exp)
{
if (nesting_countdown <= 0)
{
if (param)
{
const struct macro_tokens *arg = me->args[param - me->macro->params];
- if (*expand && param->expand_arg)
+ if (*me->expand && param->expand_arg)
{
struct macro_expander subme = {
.macros = me->macros,
.macro = NULL,
.args = NULL,
.segmenter_mode = me->segmenter_mode,
+ .expand = me->expand,
};
macro_expand (arg, nesting_countdown, &subme, NULL,
&(struct macro_expansion_stack) {
.name = param->name,
.next = stack,
- }, expand, break_, exp);
+ }, break_, exp);
}
else
for (size_t i = 0; i < arg->n; i++)
break;
const struct macro_tokens *arg = me->args[j];
- if (*expand && param->expand_arg)
+ if (*me->expand && param->expand_arg)
{
struct macro_expander subme = {
.macros = me->macros,
.macro = NULL,
.args = NULL,
.segmenter_mode = me->segmenter_mode,
+ .expand = me->expand,
};
macro_expand (arg, nesting_countdown, &subme, NULL,
&(struct macro_expansion_stack) {
.name = "!*",
.next = stack,
- }, expand, break_, exp);
+ }, break_, exp);
}
else
for (size_t k = 0; k < arg->n; k++)
size_t n = macro_expand_if (&mts->mts[i], mts->n - i,
nesting_countdown, me, stack,
- vars, expand, break_, exp);
+ vars, break_, exp);
if (n > 0)
{
i += n - 1;
}
}
- if (*expand)
+ if (*me->expand)
{
struct macro_call *submc;
int retval = macro_call_create (me->macros, token, &submc);
.macro = submc->macro,
.args = submc->args,
.segmenter_mode = me->segmenter_mode,
+ .expand = me->expand,
};
macro_expand (&submc->macro->body, nesting_countdown - 1,
&subme, NULL, &(struct macro_expansion_stack) {
.first_line = submc->macro->first_line,
.last_line = submc->macro->last_line,
.next = stack,
- }, expand, break_, exp);
+ }, break_, exp);
macro_call_destroy (submc);
continue;
}
.me = me,
.stack = stack,
.vars = vars,
- .expand = expand,
};
struct string function_output = DS_EMPTY_INITIALIZER;
size_t function_consumed;
size_t n = macro_parse_let (&mts->mts[i], mts->n - i,
nesting_countdown,
- me, stack, vars, expand);
+ me, stack, vars);
if (n > 0)
{
i += n - 1;
}
n = macro_expand_do (&mts->mts[i], mts->n - i, nesting_countdown, me,
- stack, vars, expand, exp);
+ stack, vars, exp);
if (n > 0)
{
i += n - 1;
}
if (ss_equals_case (token->string, ss_cstr ("!onexpand")))
- *expand = true;
+ *me->expand = true;
else if (ss_equals_case (token->string, ss_cstr ("!offexpand")))
- *expand = false;
+ *me->expand = false;
else
macro_tokens_add (exp, mt);
}
{
assert (mc->state == MC_FINISHED);
+ bool expand = true;
struct macro_expander me = {
.macros = mc->macros,
.macro = mc->macro,
.args = mc->args,
.segmenter_mode = segmenter_mode,
+ .expand = &expand,
};
- bool expand = true;
struct macro_expansion_stack stack = {
.name = mc->macro->name,
.file_name = mc->macro->file_name,
.last_line = mc->macro->last_line,
};
macro_expand (&mc->macro->body, settings_get_mnest (),
- &me, NULL, &stack, &expand, NULL, exp);
+ &me, NULL, &stack, NULL, exp);
}