So this would ensure to catch any part of the field that contains a number followed by “s”, “m”, “h”, “d”, “s,”, “m,”, “h,”, or “d,”, and not catch anything else by mistake, then style it as I need:
\procedure timeparse(value)
<$list filter="[<value>split[ ]]" variable="seg" join=" ">
<% if [<seg>regexp[\d+s$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+s,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+m$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+m,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+h$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+h,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+d$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+d,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% else %>
<<seg>>
<% endif %>
</$list>
\end
However, if there is any shortcut macro call inside the field (like “<<macro value>>
”), those calls won’t work anymore and become litteral strings because they would be split at the space character, then reassembled by the list widget join
operator, which would also be an issue for me.
Edit: the idea below wouldn’t work because the angled brackets in the regexp will break it like brackets do, right? 
So my feeling is that before entering the list split, I have to test for the presence of any such macro shortcut, which could be achieved with <% if [<value>regexp[<<\w+\s.+>>$]] %>
(I’m pretty sure the field will never contain macros that have more than one parameter). Then I’d have to:
- replace the space in all the macro calls of the field string with a detectable but inoccuous character (like
?
perhaps), and pass that new string to the list widget
- in the last condition of the list widget, test the
<seg>
for the presence of double angle brackets with <% if [<seg>regexp[<<\w+.+>>$]] %>
- output the full macro again by substituting the now missing space with the “?”
The first one gives me pause; I have a feeling I could use search-replace
in regexp-mode to grab the macro shortcuts and replace the spaces with “#”. Then it becomes a bit humongous:
\procedure timeparse2(value)
<% if [<value>regexp[<<\w+\s.+>>$]]] %>
<$list filter="[search:<value>:regexp[<<\w+\s.+>>$]]" variable="macroshortcut">
<$let tempvalue={{{ [<macroshortcut>search-replace[ ],[?]] }}}>
<$list filter="[<tempvalue>split[ ]]" variable="seg" join=" ">
<% if [<seg>regexp[\d+s$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+s,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+m$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+m,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+h$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+h,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+d$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+d,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<%elseif [<seg>regexp[<<\w+.+>>$]] %>
{{{ [<seg>search-replace[?],[ ]] }}}
<% else %>
<<seg>>
<% endif %>
</$list>
</$let>
</$list>
<% else %>
<$list filter="[<value>split[ ]]" variable="seg" join=" ">
<% if [<seg>regexp[\d+s$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+s,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+m$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+m,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+h$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+h,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% elseif [<seg>regexp[\d+d$]] %>
<$macrocall $name="time" value=<<seg>>/>
<% elseif [<seg>regexp[\d+d,$]] %>
<$let segm={{{ [<seg>split[,]first[]] }}}>
<$macrocall $name="time" value=<<segm>>/>, </$let>
<% else %>
<<seg>>
<% endif %>
</$list>
<% endif %>
\end
I have yet to test this, but I’m opened to better ideas if you already have them.
Edit: the idea above wouldn’t work because the angled brackets in the regexp will break it like brackets do, right? 