Re: Advanced RapaGUI techniques
Posted: Wed Feb 24, 2021 10:53 pm
Now for a major update:
The first draft of the macro substitution engine!
It's a 3 stage pipeline process. FIrst it generates all of the locale strings from the catalog file, next it substitutes all of the macros but internally to the macro substitution, it also macro substitutes the prefix and enumeration to each id="idname" string to create id="prefix_idname_1" for each ID. The fanciest part of the macro engine is that each substitution is supplied as an XML comment so there is never a clash between XML and the macros or locale strings. On down the road, I'll add support for this code into the editor.
The first draft of the macro substitution engine!
Code: Select all
/*
** Template macro library
**
** By Samuel D. Crow
*/
; NOTE: ALL TEMPLATE DEFINITIONS MUST BE INCLUDED AFTER THIS FILE
Global template={}
Global template["macro$"]={}
/*
** Pattern Pipeline
**
** Does all pattern substitutions between an XML input and src$ table
**
** The following XML comment strings are interpreted as macros by the engine:
** <!--localestr[number][default$]--> is a locale string substitution
** <!--macro[name$][enumeration]--> is a macro substitution for macro$[name$]
** applying then enumeration number Keep track of the enumeration because
** it will be used to differentiate between multiple instances of events.
*/
Function template:PatternPipeline$(xml$, prefix$)
;define source as UTF8 compliant XML after catalog substitution first
Local src$=PatternReplaceStr(xml$,
"<!--%s*localestr%s*%[(%d+)%]%s*%[([^%]]*)]%s*-->", GetCatalogString)
Local out$=PatternReplaceStr(src$,
"<!--%s*macro%s*%[(%w+)%]%s*%[(%d+)%]%s*-->",
Function(name$, count$)
; fetch template
Local temp$=self.macro$[name$]
; add prefix and enumeration to all id assignments
Return(PatternReplaceStr(temp$, "id%s*=%s*\"(%w+)\"",
"id=\""..prefix$.."_%1_"..count$.."\""))
EndFunction)
Return(out$)
EndFunction