The macrocall behaviour

53 views
Skip to first unread message

Mohammad

unread,
Dec 13, 2018, 5:24:17 AM12/13/18
to TiddlyWiki

See the below code comes from Thomas Elmiger [https://tid.li/tw5/hacks.html#Extract%20Macro]

\define checkRest(rest,start,end,prefix,suffix,limit,rmQuotes,mode)
<$set name="text" value="""$rest$""">
<$list variable="beforeStart" filter="""[<text>splitbefore[$start$]]""">
   <$set name="proceed" filter="""[<beforeStart>removesuffix[$start$]] +[addsuffix[ç-TestPassed-ç]]""" 
emptyValue="es">
   <$set name="proceedto" filter="""[<proceed>removesuffix[ç-TestPassed-ç]regexp[es]]""" emptyValue="extractSnippet">
   <$list variable="newRest" filter="""[<text>removeprefix<beforeStart>]""">
      <$macrocall $name=<<proceedto>> rest=<<newRest>> start="""$start$""" end="""$end$""" prefix="""$prefix$""" suffix="""$suffix$""" limit="$limit$" rmQuotes='$rmQuotes$' mode="$mode$"/>
   </$list> 
   </$set>
   </$set>
</$list>
</$set>
\end


As you can see the  is a variable and then it has been called as a macro again! See below part of above code:

<$set name="proceedto" filter="""[<proceed>removesuffix[ç-TestPassed-ç]regexp[es]]""" emptyValue="extractSnippet">
   <$list variable="newRest" filter="""[<text>removeprefix<beforeStart>]""">
      <$macrocall $name=<<proceedto>>


  1. How this is possible with TW5?
  2. Is this a valid TW5 syntax?

- Mohammad

Thomas Elmiger

unread,
Dec 13, 2018, 7:17:32 AM12/13/18
to TiddlyWiki
Hi Mohammad,

Glad to see sou found my macro :)

Maybe you can restate your questions, I am not sure what you would like to know or do ... so just a short comment for now.
(See below)

Cheers,
Thomas

As you can see the  is a variable and then it has been called as a macro again! See below part of above code:

<$set name="proceedto" filter="""[<proceed>removesuffix[ç-TestPassed-ç]regexp[es]]""" emptyValue="extractSnippet">
   <$list variable="newRest" filter="""[<text>removeprefix<beforeStart>]""">
      <$macrocall $name=<<proceedto>>


  1. How this is possible with TW5?
What it does (maybe in a not so elegant manner) is:
- evaluate the filter to decide about how to proceed
- call one of two macros named like the possible filter results

The goal is to loop through content extraction until there is no more (relevant) content and then take the exit. (One might call this recursion, I think.)

With TW version 5.1.18 we got the new else ~ option for filtering that would make a more elegant process possible.
  1. Is this a valid TW5 syntax?
Obviously, it works :)

Mohammad

unread,
Dec 13, 2018, 7:33:18 AM12/13/18
to TiddlyWiki
Hello Thomas,

 Okay I understood it is kind of decision making using filter. Seems it is a very clever code!
I learned a new concept! Macro name can be wrapped in a variable (create aliases). Thank you Thomas!


By the way I am trying to develop a small and simple to understand extract macro, I call it "mextract". I use it as a recursive macro, see below:
It displays each results for learning and experimenting purpose. P3 is the snippet it found.


\define mextract(text start, stop)

<$set name="fulltext"
  value
=<<__text__>>
>
''fulltext'': <$text text=<<fulltext>> /><br>

<$list variable="p1" filter="[<fulltext>splitbefore[$start$]]">
''p1'': <$text text=<<p1>> /
><br>

<$list variable="p2" filter="[<fulltext>removeprefix<p1>]">
''p2'': <$text text=<<p2>> /><br>

<$list variable="p3" filter="[<p2>splitbefore[$stop$]removesuffix[$stop$]]">
''p3'': <span style="color:red;"><$text text=<<p3>> /
></span><br>


<$macrocall $name="mextract"
  text
={{{[<p2>removeprefix<p3>removeprefix[$stop$]]}}}
  start
=<<__start__>>
  stop
=<<__stop__>>
/>

</
$list>
</$list>
</
$list>
</$set>
\end


Now I call it like below to find for example all words in bold face.

<$macrocall $name="mextract" 
  text={{newTest2!!text}} 
  start="''" 
  stop="''">>
/>


Where newTest2 is a sample tiddler to be processed for example to extract all word in bold or italic.

This is //italic// and //italic2//.

This is ''bold'' and this is ''bold2''

I am here to call it `code` and `code2`.

//Thomas//

 
You can simple test it on tiddlywiki.com

By the way I am not sure how much recursive macro is recommended in tiddlywiki and what is its performance effect.

-Mohammad
Reply all
Reply to author
Forward
0 new messages