Skip to content

Commit 72ff912

Browse files
committed
add and set is_argv flag to node->call.args
so that we can add spaces as necessary when printing, and we can also handle arguments better for the soon to be coming argument tokenization changes
1 parent b91790c commit 72ff912

4 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/lib/unlang/xlat_alloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void _xlat_exp_set_type(NDEBUG_LOCATION_ARGS xlat_exp_t *node, xlat_type_t type)
120120
case XLAT_FUNC:
121121
case XLAT_FUNC_UNRESOLVED:
122122
node->call.args = _xlat_exp_head_alloc(NDEBUG_LOCATION_VALS node);
123+
node->call.args->is_argv = true;
123124
break;
124125

125126
case XLAT_BOX:
@@ -377,6 +378,8 @@ void xlat_exp_verify(xlat_exp_t const *node)
377378
return;
378379

379380
case XLAT_FUNC:
381+
fr_assert(node->call.args->is_argv);
382+
380383
xlat_exp_foreach(node->call.args, arg) {
381384
fr_assert(arg->type == XLAT_GROUP);
382385

src/lib/unlang/xlat_priv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ struct xlat_exp_s {
189189
struct xlat_exp_head_s {
190190
fr_dlist_head_t dlist;
191191
xlat_flags_t flags; //!< Flags that control resolution and evaluation.
192-
bool instantiated; //!< temporary flag until we fix more things
192+
uint8_t instantiated : 1; //!< temporary flag until we fix more things
193+
uint8_t is_argv : 1; //!< this thing holds function arguments
193194

194195
#ifndef NDEBUG
195196
char const * _CONST file; //!< File where the xlat was allocated.

src/lib/unlang/xlat_tokenize.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,11 +1041,7 @@ ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t
10411041
if (xlat_exp_next(head, node)) {
10421042
if (c) FR_SBUFF_IN_CHAR_RETURN(out, c);
10431043

1044-
/*
1045-
* This thing is %{...}, and we don't print a space between the last argument
1046-
* and the '}'.
1047-
*/
1048-
if (!node->flags.xlat) FR_SBUFF_IN_CHAR_RETURN(out, ' '); /* Add ' ' between args */
1044+
if (head->is_argv) FR_SBUFF_IN_CHAR_RETURN(out, ' '); /* Add ' ' between args */
10491045
}
10501046
goto done;
10511047

@@ -1531,6 +1527,7 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
15311527
}
15321528

15331529
MEM(head = xlat_exp_head_alloc(ctx));
1530+
head->is_argv = true;
15341531

15351532
/*
15361533
* skip spaces at the beginning as we don't want them to become a whitespace literal.

src/tests/unit/xlat/purify.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ match "hello 3 bob"
231231
# @todo - xlat_purify doesn't hoist results.
232232
#
233233
xlat_purify "hello %{1 + 2} bob"
234-
match "hello 3 bob"
234+
match "hello 3 bob"
235235

236236
#
237237
# New syntax!

0 commit comments

Comments
 (0)