|go text: || - project - [ technical ] - examples - links -
||topics: || - reasoning - two passes - still tiny - sitemaps - [ variables ] - accessibility -

Variable Expansion

Originally I was using a simple scheme of <!--varname--> to express variable references that shall be expanded into the text. And later I discovered it would be good that it can overwrite some text in the sourcefile so that it was expanded to cut out any filename-like text directly following this text. And even more later I did want to have a lowercased and parenthesed variant which was selectable by choosing the variant name <!--varname?-->.

This "simplevars" style will be discontinued now in the near future. It was a necessary construction when using sed -e snippets directly in a makefile since the natural syntax is much harder to create - where one would escape a "$" standing in front of each varname. That escaping however might add up to 15x"\" (i.e. "\\\\\\\\\\\\\\$") for a fact just to get to expand a simple <!--$varname--> in the actual sourecfile text. With the upbringing of a shell script with loops and shell functions there is no need anymore to try to get around this. That's why it does exist now - and the oldstyle "simplevars" is left in as an explicit option but warned about strongly.

The recommended style is therefore <!--$varname--> to expand the value of $varname in the place of this hot comment. If you want to cut away some text following this $varname expansion then add a trailing ":=" to the varname, i.e. <!--$varname:=-->. This is almost the way the oldstyle simplevars were working up to on default. (it does now scan to the next "<", e.g. <wbr>). The alternate form can be selected by <!--$varname:?-->

Additionally you can prefix the $varname now with some extra text like <!-- generated $today--> which makes a lot of expansion code look nicer and lifts away the need to invent too many flavours of variables all with some extra formatting. Atleast this simple addition gives lots of opportunities for nice visualisations.

And since sometimes people need to paste variable expansions inside of markups (without removing the markup itself) we have yet another format of variable referencing: <...${today:=defaulttext}...> will be either the variable value (if the variable exists) or just the defaulttext as seen (if not existing). The alternate form can be selected by ${today:?defaulttext}. This syntax follows the habits of shell variables.

sourcefile reference resulting text
<!--$modified-->+xxxx 2005-01-30+xxxx
<!--$modified:=-->+xxxx 2005-01-30
<!--$modified?-->+xxxx (modified 2005-01-30)+xxxx
<!--$modified:?-->+xxxx (modified 2005-01-30)
<!-- changed $modified-->+xxxx changed 2005-01-30+xxxx
<!-- changed $modified:=-->+xxxx changed 2005-01-30
<!--modified-->+xxxx
<!--modified?-->+xxxx
+xxxx
+xxxx
and a warning message during formatting

Hint, variables can be also set via commandline: just use the option style --option=value. If the option name contains "-" then it is also going to be another meta variable else it is just a plain text variable.