\f
/* Macro expander. */
-enum me_state
+enum mc_state
{
/* Error state. */
- ME_ERROR,
+ MC_ERROR,
- /* Accumulating tokens in me->params toward the end of any type of
+ /* Accumulating tokens in mc->params toward the end of any type of
argument. */
- ME_ARG,
+ MC_ARG,
/* Expecting the opening delimiter of an ARG_ENCLOSE argument. */
- ME_ENCLOSE,
+ MC_ENCLOSE,
/* Expecting a keyword for a keyword argument. */
- ME_KEYWORD,
+ MC_KEYWORD,
/* Expecting an equal sign for a keyword argument. */
- ME_EQUALS,
+ MC_EQUALS,
/* Macro fully parsed and ready for expansion. */
- ME_FINISHED,
+ MC_FINISHED,
};
-/* Macro expander.
-
- Macro expansion has two phases. Phase 1 uses an FSM driven by
- macro_expander_create() and macro_expander_add() to identify the macro being
- called and obtain its arguments. 'state' identifies the FSM state.
-
- Phase 2 is macro expansion via macro_expander_get_expansion(). */
-struct macro_expander
+/* Parsing macro calls. This is a FSM driven by macro_call_create() and
+ macro_call_add() to identify the macro being called and obtain its
+ arguments. 'state' identifies the FSM state. */
+struct macro_call
{
- /* Phases 1 and 2. */
const struct macro_set *macros;
const struct macro *macro;
struct macro_tokens **args;
- /* Phase 1 only. */
- enum me_state state;
+ enum mc_state state;
size_t n_tokens;
const struct macro_param *param; /* Parameter currently being parsed. */
- /* Phase 2 only. */
enum segmenter_mode segmenter_mode;
};
/* Completes macro expansion by initializing arguments that weren't supplied to
their defaults. */
static int
-me_finished (struct macro_expander *me)
+mc_finished (struct macro_call *mc)
{
- me->state = ME_FINISHED;
- for (size_t i = 0; i < me->macro->n_params; i++)
- if (!me->args[i])
- me->args[i] = &me->macro->params[i].def;
- return me->n_tokens;
+ mc->state = MC_FINISHED;
+ for (size_t i = 0; i < mc->macro->n_params; i++)
+ if (!mc->args[i])
+ mc->args[i] = &mc->macro->params[i].def;
+ return mc->n_tokens;
}
static int
-me_next_arg (struct macro_expander *me)
+mc_next_arg (struct macro_call *mc)
{
- if (!me->param)
+ if (!mc->param)
{
- assert (!me->macro->n_params);
- return me_finished (me);
+ assert (!mc->macro->n_params);
+ return mc_finished (mc);
}
- else if (me->param->positional)
+ else if (mc->param->positional)
{
- me->param++;
- if (me->param >= &me->macro->params[me->macro->n_params])
- return me_finished (me);
+ mc->param++;
+ if (mc->param >= &mc->macro->params[mc->macro->n_params])
+ return mc_finished (mc);
else
{
- me->state = (!me->param->positional ? ME_KEYWORD
- : me->param->arg_type == ARG_ENCLOSE ? ME_ENCLOSE
- : ME_ARG);
+ mc->state = (!mc->param->positional ? MC_KEYWORD
+ : mc->param->arg_type == ARG_ENCLOSE ? MC_ENCLOSE
+ : MC_ARG);
return 0;
}
}
else
{
- for (size_t i = 0; i < me->macro->n_params; i++)
- if (!me->args[i])
+ for (size_t i = 0; i < mc->macro->n_params; i++)
+ if (!mc->args[i])
{
- me->state = ME_KEYWORD;
+ mc->state = MC_KEYWORD;
return 0;
}
- return me_finished (me);
+ return mc_finished (mc);
}
}
static int
-me_error (struct macro_expander *me)
+mc_error (struct macro_call *mc)
{
- me->state = ME_ERROR;
+ mc->state = MC_ERROR;
return -1;
}
static int
-me_add_arg (struct macro_expander *me, const struct macro_token *mt)
+mc_add_arg (struct macro_call *mc, const struct macro_token *mt)
{
- const struct macro_param *p = me->param;
+ const struct macro_param *p = mc->param;
const struct token *token = &mt->token;
if ((token->type == T_ENDCMD || token->type == T_STOP)
&& p->arg_type != ARG_CMDEND)
{
msg (SE, _("Unexpected end of command reading argument %s "
- "to macro %s."), me->param->name, me->macro->name);
+ "to macro %s."), mc->param->name, mc->macro->name);
- return me_error (me);
+ return mc_error (mc);
}
- me->n_tokens++;
+ mc->n_tokens++;
- struct macro_tokens **argp = &me->args[p - me->macro->params];
+ struct macro_tokens **argp = &mc->args[p - mc->macro->params];
if (!*argp)
*argp = xzalloc (sizeof **argp);
struct macro_tokens *arg = *argp;
{
macro_tokens_add (arg, mt);
if (arg->n >= p->n_tokens)
- return me_next_arg (me);
+ return mc_next_arg (mc);
return 0;
}
else if (p->arg_type == ARG_CMDEND)
{
if (token->type == T_ENDCMD || token->type == T_STOP)
- return me_next_arg (me);
+ return mc_next_arg (mc);
macro_tokens_add (arg, mt);
return 0;
}
const struct token *end
= p->arg_type == ARG_CHAREND ? &p->charend : &p->enclose[1];
if (token_equal (token, end))
- return me_next_arg (me);
+ return mc_next_arg (mc);
macro_tokens_add (arg, mt);
return 0;
}
}
static int
-me_expected (struct macro_expander *me, const struct macro_token *actual,
+mc_expected (struct macro_call *mc, const struct macro_token *actual,
const struct token *expected)
{
const struct substring actual_s
msg (SE, _("Found `%.*s' while expecting `%s' reading argument %s "
"to macro %s."),
(int) actual_s.length, actual_s.string, expected_s,
- me->param->name, me->macro->name);
+ mc->param->name, mc->macro->name);
free (expected_s);
- return me_error (me);
+ return mc_error (mc);
}
static int
-me_enclose (struct macro_expander *me, const struct macro_token *mt)
+mc_enclose (struct macro_call *mc, const struct macro_token *mt)
{
const struct token *token = &mt->token;
- me->n_tokens++;
+ mc->n_tokens++;
- if (token_equal (&me->param->enclose[0], token))
+ if (token_equal (&mc->param->enclose[0], token))
{
- me->state = ME_ARG;
+ mc->state = MC_ARG;
return 0;
}
- return me_expected (me, mt, &me->param->enclose[0]);
+ return mc_expected (mc, mt, &mc->param->enclose[0]);
}
static const struct macro_param *
}
static int
-me_keyword (struct macro_expander *me, const struct macro_token *mt)
+mc_keyword (struct macro_call *mc, const struct macro_token *mt)
{
const struct token *token = &mt->token;
if (token->type != T_ID)
- return me_finished (me);
+ return mc_finished (mc);
- const struct macro_param *p = macro_find_parameter_by_name (me->macro,
+ const struct macro_param *p = macro_find_parameter_by_name (mc->macro,
token->string);
if (p)
{
- size_t arg_index = p - me->macro->params;
- me->param = p;
- if (me->args[arg_index])
+ size_t arg_index = p - mc->macro->params;
+ mc->param = p;
+ if (mc->args[arg_index])
{
msg (SE,
_("Argument %s multiply specified in call to macro %s."),
- p->name, me->macro->name);
- return me_error (me);
+ p->name, mc->macro->name);
+ return mc_error (mc);
}
- me->n_tokens++;
- me->state = ME_EQUALS;
+ mc->n_tokens++;
+ mc->state = MC_EQUALS;
return 0;
}
- return me_finished (me);
+ return mc_finished (mc);
}
static int
-me_equals (struct macro_expander *me, const struct macro_token *mt)
+mc_equals (struct macro_call *mc, const struct macro_token *mt)
{
const struct token *token = &mt->token;
- me->n_tokens++;
+ mc->n_tokens++;
if (token->type == T_EQUALS)
{
- me->state = ME_ARG;
+ mc->state = MC_ARG;
return 0;
}
- return me_expected (me, mt, &(struct token) { .type = T_EQUALS });
+ return mc_expected (mc, mt, &(struct token) { .type = T_EQUALS });
}
/* If TOKEN is the first token of a call to a macro in MACROS, create a new
- macro expander, initializes *MEP to it. Returns 0 if more tokens are needed
- and should be added via macro_expander_add() or 1 if the caller should next
- call macro_expander_get_expansion().
+ macro expander, initializes *MCP to it. Returns 0 if more tokens are needed
+ and should be added via macro_call_add() or 1 if the caller should next call
+ macro_call_get_expansion().
- If TOKEN is not the first token of a macro call, returns -1 and sets *MEP to
+ If TOKEN is not the first token of a macro call, returns -1 and sets *MCP to
NULL. */
int
-macro_expander_create (const struct macro_set *macros,
- const struct token *token,
- struct macro_expander **mep)
+macro_call_create (const struct macro_set *macros,
+ const struct token *token,
+ struct macro_call **mcp)
{
const struct macro *macro = (token->type == T_ID || token->type == T_MACRO_ID
? macro_set_find (macros, token->string.string)
: NULL);
if (!macro)
{
- *mep = NULL;
+ *mcp = NULL;
return -1;
}
- struct macro_expander *me = xmalloc (sizeof *me);
- *me = (struct macro_expander) {
+ struct macro_call *mc = xmalloc (sizeof *mc);
+ *mc = (struct macro_call) {
.macros = macros,
.macro = macro,
.n_tokens = 1,
- .state = (!macro->n_params ? ME_FINISHED
- : !macro->params[0].positional ? ME_KEYWORD
- : macro->params[0].arg_type == ARG_ENCLOSE ? ME_ENCLOSE
- : ME_ARG),
- .args = macro->n_params ? xcalloc (macro->n_params, sizeof *me->args) : NULL,
+ .state = (!macro->n_params ? MC_FINISHED
+ : !macro->params[0].positional ? MC_KEYWORD
+ : macro->params[0].arg_type == ARG_ENCLOSE ? MC_ENCLOSE
+ : MC_ARG),
+ .args = macro->n_params ? xcalloc (macro->n_params, sizeof *mc->args) : NULL,
.param = macro->params,
};
- *mep = me;
+ *mcp = mc;
- return me->state == ME_FINISHED ? 1 : 0;
+ return mc->state == MC_FINISHED ? 1 : 0;
}
void
-macro_expander_destroy (struct macro_expander *me)
+macro_call_destroy (struct macro_call *mc)
{
- if (!me)
+ if (!mc)
return;
- for (size_t i = 0; i < me->macro->n_params; i++)
+ for (size_t i = 0; i < mc->macro->n_params; i++)
{
- struct macro_tokens *a = me->args[i];
- if (a && a != &me->macro->params[i].def)
+ struct macro_tokens *a = mc->args[i];
+ if (a && a != &mc->macro->params[i].def)
{
macro_tokens_uninit (a);
free (a);
}
}
- free (me->args);
- free (me);
+ free (mc->args);
+ free (mc);
}
-/* Adds TOKEN to the collection of tokens in ME that potentially need to be
+/* Adds TOKEN to the collection of tokens in MC that potentially need to be
macro expanded.
Returns -1 if the tokens added do not actually invoke a macro. The caller
Returns 0 if the macro expander needs more tokens, for macro arguments or to
decide whether this is actually a macro invocation. The caller should call
- macro_expander_add() again with the next token.
+ macro_call_add() again with the next token.
Returns a positive number to indicate that the returned number of tokens
invoke a macro. The number returned might be less than the number of tokens
added because it can take a few tokens of lookahead to determine whether the
macro invocation is finished. The caller should call
- macro_expander_get_expansion() to obtain the expansion. */
+ macro_call_get_expansion() to obtain the expansion. */
int
-macro_expander_add (struct macro_expander *me, const struct macro_token *mt)
+macro_call_add (struct macro_call *mc, const struct macro_token *mt)
{
- switch (me->state)
+ switch (mc->state)
{
- case ME_ERROR:
+ case MC_ERROR:
return -1;
- case ME_ARG:
- return me_add_arg (me, mt);
+ case MC_ARG:
+ return mc_add_arg (mc, mt);
- case ME_ENCLOSE:
- return me_enclose (me, mt);
+ case MC_ENCLOSE:
+ return mc_enclose (mc, mt);
- case ME_KEYWORD:
- return me_keyword (me, mt);
+ case MC_KEYWORD:
+ return mc_keyword (mc, mt);
- case ME_EQUALS:
- return me_equals (me, mt);
+ case MC_EQUALS:
+ return mc_equals (mc, mt);
default:
NOT_REACHED ();
size_t n_input;
int nesting_countdown;
const struct macro_set *macros;
- const struct macro_expander *me;
+ const struct macro_call *mc;
const struct macro_expansion_stack *stack;
struct string_map *vars;
bool *expand;
static void
macro_expand (const struct macro_tokens *, int nesting_countdown,
const struct macro_set *,
- const struct macro_expander *, struct string_map *vars,
+ const struct macro_call *, struct string_map *vars,
const struct macro_expansion_stack *stack,
bool *expand, bool *break_,
struct macro_tokens *exp);
if (token->type == T_MACRO_ID)
{
const struct macro_param *param = macro_find_parameter_by_name (
- ctx->me->macro, token->string);
+ ctx->mc->macro, token->string);
if (param)
{
- size_t param_idx = param - ctx->me->macro->params;
- const struct macro_tokens *marg = ctx->me->args[param_idx];
+ size_t param_idx = param - ctx->mc->macro->params;
+ const struct macro_tokens *marg = ctx->mc->args[param_idx];
for (size_t i = 0; i < marg->n; i++)
{
if (i)
if (is_bang_star (ctx->input, ctx->n_input, i))
{
- for (size_t i = 0; i < ctx->me->macro->n_params; i++)
+ for (size_t i = 0; i < ctx->mc->macro->n_params; i++)
{
- if (!ctx->me->macro->params[i].positional)
+ if (!ctx->mc->macro->params[i].positional)
break;
- const struct macro_tokens *marg = ctx->me->args[i];
+ const struct macro_tokens *marg = ctx->mc->args[i];
for (size_t j = 0; j < marg->n; j++)
{
if (i || j)
.n_input = ctx->n_input - i,
.nesting_countdown = ctx->nesting_countdown,
.macros = ctx->macros,
- .me = ctx->me,
+ .mc = ctx->mc,
.stack = ctx->stack,
.vars = ctx->vars,
.expand = ctx->expand,
input_consumed))
{
for (size_t i = 0; i < args.n; i++)
- if (!unquote_string (args.strings[i], ctx->me->segmenter_mode, output))
+ if (!unquote_string (args.strings[i], ctx->mc->segmenter_mode, output))
ds_put_cstr (output, args.strings[i]);
}
else if (parse_macro_function (ctx, &args, ss_cstr ("!HEAD"), 1, 1,
{
struct string tmp;
const char *s = unquote_string_in_place (args.strings[0],
- ctx->me->segmenter_mode, &tmp);
+ ctx->mc->segmenter_mode, &tmp);
struct macro_tokens mts = { .n = 0 };
- macro_tokens_from_string__ (&mts, ss_cstr (s), ctx->me->segmenter_mode,
+ macro_tokens_from_string__ (&mts, ss_cstr (s), ctx->mc->segmenter_mode,
ctx->stack);
if (mts.n > 0)
ds_put_substring (output, mts.mts[0].representation);
else if (parse_macro_function (ctx, &args, ss_cstr ("!QUOTE"), 1, 1,
input_consumed))
{
- if (unquote_string (args.strings[0], ctx->me->segmenter_mode, NULL))
+ if (unquote_string (args.strings[0], ctx->mc->segmenter_mode, NULL))
ds_put_cstr (output, args.strings[0]);
else
{
{
struct string tmp;
const char *s = unquote_string_in_place (args.strings[0],
- ctx->me->segmenter_mode, &tmp);
+ ctx->mc->segmenter_mode, &tmp);
struct macro_tokens mts = { .n = 0 };
- macro_tokens_from_string__ (&mts, ss_cstr (s), ctx->me->segmenter_mode,
+ macro_tokens_from_string__ (&mts, ss_cstr (s), ctx->mc->segmenter_mode,
ctx->stack);
if (mts.n > 1)
{
else if (parse_macro_function (ctx, &args, ss_cstr ("!UNQUOTE"), 1, 1,
input_consumed))
{
- if (!unquote_string (args.strings[0], ctx->me->segmenter_mode, output))
+ if (!unquote_string (args.strings[0], ctx->mc->segmenter_mode, output))
ds_put_cstr (output, args.strings[0]);
}
else if (parse_macro_function (ctx, &args, ss_cstr ("!UPCASE"), 1, 1,
{
struct string tmp;
const char *s = unquote_string_in_place (args.strings[0],
- ctx->me->segmenter_mode, &tmp);
+ ctx->mc->segmenter_mode, &tmp);
char *upper = utf8_to_upper (s);
ds_put_cstr (output, upper);
free (upper);
{
struct macro_tokens mts = { .n = 0 };
macro_tokens_from_string__ (&mts, ss_cstr (args.strings[0]),
- ctx->me->segmenter_mode, ctx->stack);
+ ctx->mc->segmenter_mode, ctx->stack);
struct macro_tokens exp = { .n = 0 };
macro_expand (&mts, ctx->nesting_countdown - 1,
- ctx->macros, ctx->me, ctx->vars,
+ ctx->macros, ctx->mc, ctx->vars,
&(struct macro_expansion_stack) {
.name = "!EVAL",
.next = ctx->stack,
{
int nesting_countdown;
const struct macro_set *macros;
- const struct macro_expander *me;
+ const struct macro_call *mc;
const struct macro_expansion_stack *stack;
struct string_map *vars;
bool *expand;
.n_input = end - p,
.nesting_countdown = ctx->nesting_countdown,
.macros = ctx->macros,
- .me = ctx->me,
+ .mc = ctx->mc,
.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);
struct string unquoted = DS_EMPTY_INITIALIZER;
- if (unquote_string (ds_cstr (&function_output), ctx->me->segmenter_mode,
+ if (unquote_string (ds_cstr (&function_output), ctx->mc->segmenter_mode,
&unquoted))
{
ds_swap (&function_output, &unquoted);
}
struct string lhs_tmp, rhs_tmp;
- int cmp = strcmp (unquote_string_in_place (lhs, ctx->me->segmenter_mode,
+ int cmp = strcmp (unquote_string_in_place (lhs, ctx->mc->segmenter_mode,
&lhs_tmp),
- unquote_string_in_place (rhs, ctx->me->segmenter_mode,
+ unquote_string_in_place (rhs, ctx->mc->segmenter_mode,
&rhs_tmp));
ds_destroy (&lhs_tmp);
ds_destroy (&rhs_tmp);
macro_evaluate_expression (const struct macro_token **tokens, size_t n_tokens,
int nesting_countdown,
const struct macro_set *macros,
- const struct macro_expander *me,
+ const struct macro_call *mc,
const struct macro_expansion_stack *stack,
struct string_map *vars, bool *expand)
{
const struct expr_context ctx = {
.nesting_countdown = nesting_countdown,
.macros = macros,
- .me = me,
+ .mc = mc,
.stack = stack,
.vars = vars,
.expand = expand,
macro_evaluate_number (const struct macro_token **tokens, size_t n_tokens,
int nesting_countdown,
const struct macro_set *macros,
- const struct macro_expander *me,
+ const struct macro_call *mc,
const struct macro_expansion_stack *stack,
struct string_map *vars,
bool *expand, double *number)
{
char *s = macro_evaluate_expression (tokens, n_tokens, nesting_countdown,
- macros, me, stack, vars, expand);
+ macros, mc, stack, vars, expand);
if (!s)
return false;
struct macro_tokens mts = { .n = 0 };
- macro_tokens_from_string__ (&mts, ss_cstr (s), me->segmenter_mode, stack);
+ macro_tokens_from_string__ (&mts, ss_cstr (s), mc->segmenter_mode, stack);
if (mts.n != 1 || !token_is_number (&mts.mts[0].token))
{
macro_error (stack, mts.n > 0 ? &mts.mts[0] : NULL,
static size_t
macro_expand_if (const struct macro_token *tokens, size_t n_tokens,
int nesting_countdown, const struct macro_set *macros,
- const struct macro_expander *me,
+ const struct macro_call *mc,
const struct macro_expansion_stack *stack,
struct string_map *vars,
bool *expand, bool *break_, struct macro_tokens *exp)
p++;
char *result = macro_evaluate_expression (&p, end - p,
nesting_countdown,
- macros, me,
+ macros, mc,
stack, vars, expand);
if (!result)
return 0;
.mts = CONST_CAST (struct macro_token *, start),
.n = n,
};
- macro_expand (&mts, nesting_countdown, macros, me, vars,
+ macro_expand (&mts, nesting_countdown, macros, mc, vars,
&(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_set *macros,
- const struct macro_expander *me,
+ const struct macro_call *mc,
const struct macro_expansion_stack *stack,
struct string_map *vars, bool *expand)
{
}
const struct substring var_name = p->token.string;
if (is_macro_keyword (var_name)
- || macro_find_parameter_by_name (me->macro, var_name))
+ || macro_find_parameter_by_name (mc->macro, var_name))
{
macro_error (stack, p < end ? p : NULL,
_("Cannot use argument name or macro keyword "
p++;
char *value = macro_evaluate_expression (&p, end - p, nesting_countdown,
- macros, me, stack, vars, expand);
+ macros, mc, stack, vars, expand);
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_set *macros,
- const struct macro_expander *me,
+ const struct macro_call *mc,
const struct macro_expansion_stack *stack,
struct string_map *vars,
bool *expand, struct macro_tokens *exp)
}
const struct substring var_name = p->token.string;
if (is_macro_keyword (var_name)
- || macro_find_parameter_by_name (me->macro, var_name))
+ || macro_find_parameter_by_name (mc->macro, var_name))
{
macro_error (stack, p, _("Cannot use argument name or macro "
"keyword as !DO variable."));
{
p++;
char *list = macro_evaluate_expression (&p, end - p, nesting_countdown,
- macros, me, &next_stack, vars,
+ macros, mc, &next_stack, vars,
expand);
if (!list)
return 0;
struct macro_tokens items = { .n = 0 };
- macro_tokens_from_string__ (&items, ss_cstr (list), me->segmenter_mode,
+ macro_tokens_from_string__ (&items, ss_cstr (list), mc->segmenter_mode,
stack);
free (list);
bool break_ = false;
macro_expand (&inner, nesting_countdown, macros,
- me, vars, &next_stack, expand, &break_, exp);
+ mc, vars, &next_stack, expand, &break_, exp);
if (break_)
break;
}
p++;
double first;
if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- macros, me, &next_stack,
+ macros, mc, &next_stack,
vars, expand, &first))
return 0;
double last;
if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- macros, me, &next_stack,
+ macros, mc, &next_stack,
vars, expand, &last))
return 0;
{
p++;
if (!macro_evaluate_number (&p, end - p, nesting_countdown,
- macros, me, &next_stack,
+ macros, mc, &next_stack,
vars, expand, &by))
return 0;
bool break_ = false;
macro_expand (&inner, nesting_countdown,
- macros, me, vars, &next_stack, expand, &break_,
+ macros, mc, vars, &next_stack, expand, &break_,
exp);
if (break_)
break;
static void
macro_expand (const struct macro_tokens *mts, int nesting_countdown,
const struct macro_set *macros,
- const struct macro_expander *me, struct string_map *vars,
+ const struct macro_call *mc, struct string_map *vars,
const struct macro_expansion_stack *stack,
bool *expand, bool *break_, struct macro_tokens *exp)
{
{
const struct macro_token *mt = &mts->mts[i];
const struct token *token = &mt->token;
- if (token->type == T_MACRO_ID && me)
+ if (token->type == T_MACRO_ID && mc)
{
const struct macro_param *param = macro_find_parameter_by_name (
- me->macro, token->string);
+ mc->macro, token->string);
if (param)
{
- const struct macro_tokens *arg = me->args[param - me->macro->params];
+ const struct macro_tokens *arg = mc->args[param - mc->macro->params];
if (*expand && param->expand_arg)
macro_expand (arg, nesting_countdown,
macros, NULL, NULL,
if (is_bang_star (mts->mts, mts->n, i))
{
- for (size_t j = 0; j < me->macro->n_params; j++)
+ for (size_t j = 0; j < mc->macro->n_params; j++)
{
- const struct macro_param *param = &me->macro->params[j];
+ const struct macro_param *param = &mc->macro->params[j];
if (!param->positional)
break;
- const struct macro_tokens *arg = me->args[j];
+ const struct macro_tokens *arg = mc->args[j];
if (*expand && param->expand_arg)
macro_expand (arg, nesting_countdown,
macros, NULL, NULL,
size_t n = macro_expand_if (&mts->mts[i], mts->n - i,
nesting_countdown,
- macros, me, stack,
+ macros, mc, stack,
vars, expand, break_, exp);
if (n > 0)
{
if (value)
{
macro_tokens_from_string__ (exp, ss_cstr (value),
- me->segmenter_mode, stack);
+ mc->segmenter_mode, stack);
continue;
}
}
if (*expand)
{
- struct macro_expander *subme;
- int retval = macro_expander_create (macros, token, &subme);
+ struct macro_call *subme;
+ int retval = macro_call_create (macros, token, &subme);
for (size_t j = 1; !retval; j++)
{
const struct macro_token endcmd = { .token = { .type = T_ENDCMD } };
- retval = macro_expander_add (
+ retval = macro_call_add (
subme, i + j < mts->n ? &mts->mts[i + j] : &endcmd);
}
if (retval > 0)
.last_line = subme->macro->last_line,
.next = stack,
}, expand, break_, exp);
- macro_expander_destroy (subme);
+ macro_call_destroy (subme);
continue;
}
- macro_expander_destroy (subme);
+ macro_call_destroy (subme);
}
if (token->type != T_MACRO_ID)
.n_input = mts->n - i,
.nesting_countdown = nesting_countdown,
.macros = macros,
- .me = me,
+ .mc = mc,
.stack = stack,
.vars = vars,
.expand = expand,
i += function_consumed - 1;
macro_tokens_from_string__ (exp, function_output.ss,
- me->segmenter_mode, stack);
+ mc->segmenter_mode, stack);
ds_destroy (&function_output);
continue;
size_t n = macro_parse_let (&mts->mts[i], mts->n - i,
nesting_countdown,
- macros, me, stack, vars, expand);
+ macros, mc, stack, vars, expand);
if (n > 0)
{
i += n - 1;
}
n = macro_expand_do (&mts->mts[i], mts->n - i,
- nesting_countdown, macros, me, stack,
+ nesting_countdown, macros, mc, stack,
vars, expand, exp);
if (n > 0)
{
}
void
-macro_expander_get_expansion (struct macro_expander *me,
- enum segmenter_mode segmenter_mode,
- struct macro_tokens *exp)
+macro_call_expand (struct macro_call *mc, enum segmenter_mode segmenter_mode,
+ struct macro_tokens *exp)
{
- assert (me->state == ME_FINISHED);
- me->segmenter_mode = segmenter_mode;
+ assert (mc->state == MC_FINISHED);
+ mc->segmenter_mode = segmenter_mode;
bool expand = true;
struct macro_expansion_stack stack = {
- .name = me->macro->name,
- .file_name = me->macro->file_name,
- .first_line = me->macro->first_line,
- .last_line = me->macro->last_line,
+ .name = mc->macro->name,
+ .file_name = mc->macro->file_name,
+ .first_line = mc->macro->first_line,
+ .last_line = mc->macro->last_line,
};
- macro_expand (&me->macro->body, settings_get_mnest (),
- me->macros, me, NULL, &stack, &expand, NULL, exp);
+ macro_expand (&mc->macro->body, settings_get_mnest (),
+ mc->macros, mc, NULL, &stack, &expand, NULL, exp);
}