[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using recfmt with curly-brace markup
From: |
Jose E. Marchesi |
Subject: |
Re: Using recfmt with curly-brace markup |
Date: |
Thu, 20 Jan 2022 15:43:21 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> I'm trying to use recfmt to generate LaTeX code snippets from records.
> The current implementation results in a fatal error ("invalid
> expression in a template slot") when straightforwardly attempting to
> wrap recfmt's template syntax in another pair of braces. This has
> somewhat been discussed in a related use case in Guix, which would be
> to get BibTeX records from package descriptions [1].
>
> I attached a patch, which excludes opening braces from the internals of
> a template slot. This makes it so that only the inner-most template
> pairs are matched and the resulting SEX compiles correctly.
Very nice :)
Applied the patch on your behalf.
Thanks!
> [1] https://lists.gnu.org/archive/html/guix-devel/2021-12/msg00070.html
>
> From 297cfb622c62e90753463692386551449179c008 Mon Sep 17 00:00:00 2001
> From: Liliana Marie Prikler <liliana.prikler@ist.tugraz.at>
> Date: Thu, 20 Jan 2022 11:21:37 +0100
> Subject: [PATCH] recfmt: Allow curly-brace markup in template.
>
> 2022-01-20 Liliana Marie Prikler <liliana.prikler@ist.tugraz.at>
>
> * utils/recfmt.c (recfmt_apply_template): Add open brace as excluded
> character in regexp.
> * torture/utils/recfmt.sh (recfmt-curly): New test.
> ---
> torture/utils/recfmt.sh | 11 +++++++++++
> utils/recfmt.c | 2 +-
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/torture/utils/recfmt.sh b/torture/utils/recfmt.sh
> index 9acdc40..f127408 100755
> --- a/torture/utils/recfmt.sh
> +++ b/torture/utils/recfmt.sh
> @@ -127,6 +127,17 @@ value21 value22value23
> value31 value32value33
> '
>
> +# Apply a template containing curly-brace markup.
> +test_tool recfmt-curly ok \
> + recfmt \
> + '"\def\field1{{{field1}}}
> +"' \
> + multiple-records \
> +'\def\field1{value11}
> +\def\field1{value21}
> +\def\field1{value31}
> +'
> +
> # Try to apply an empty slot.
> test_tool recfmt-empty-slot xfail \
> recfmt \
> diff --git a/utils/recfmt.c b/utils/recfmt.c
> index 7c0b5fa..082e0f5 100644
> --- a/utils/recfmt.c
> +++ b/utils/recfmt.c
> @@ -174,7 +174,7 @@ recfmt_apply_template (rec_record_t record,
> slot with the empty string.
> */
>
> - if (regcomp (®exp, "\\{\\{" "[^}]*" "\\}\\}", REG_EXTENDED) != 0)
> + if (regcomp (®exp, "\\{\\{" "[^{}]*" "\\}\\}", REG_EXTENDED) != 0)
> recutl_fatal (_("recfmt_apply_template: error compiling regexp.\
> Please report this.\n"));