Split named arguments before evaluation #14
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The
#ueswitch
parser function and various list parser functions accept named arguments. Arguments are provided to the parser functions as preprocessor nodes, and all these functions analyze an argument nodeN
the same way:N
into a string"k=v"
, then"k=v"
into a key and value.Then, both of these values may be trimmed, unescaped, or post-processed in any other way.
The
#switch
parser function analyze an argument nodeN
the other way around:N
a key nodeK
and value nodeV
.K
andV
into strings.Benefits of the
#ueswitch
approach=
escapingWith the
#ueswitch
approach, the full key/value pair can be the result of a single computation, e.g. the following expressions give the same result:It can be useful to simplify expressions in some edge cases, but I assume this is a pretty niche usage.
Benefits of the
#switch
approach=
escapingAssume both
#switch
and#ueswitch
are given a casea {{=}} b = c
.Because the
#switch
approach relies on the preprocessor tree to split argument names from values,#switch
assumes the key isa = b
and the value isc
, while#ueswitch
splits evaluated argument strings and assumes the key isa
and the value isb = c
.This may be seen as a strange inconsistency for the
#ueswitch
function since keys can be any wikitext, but on the other hand this is not a real issue with list functions since parameter keys are known strings (and none of these contain any=
symbol).Laziness
With the
#switch
approach, after splitting we get a key nodeK
and value nodeV
, so we can evaluate the key node without evaluating the value one. This allows (and is necessary) to lazily evaluate keys and values of named parameters, as introduced for#ueswitch
in #3.Proposed changes
Change the way
#ueswitch
and the list parser functions (withParserPower::arrangeParams
) analyze their arguments to use the same approach as#switch
.This PR does not propose to change which parameters are lazily evaluated, only the evaluation process, so the
=
escaping differences listed above should be the only end-user differences and breaking changes of this PR.What other extensions do
In other parser function extensions, both approaches are used, but the ParserPower one is mostly used in extensions (I am aware of) that manage named arguments.
#switch
approach (like GeoData, RandomSelection, or ReplaceSet), but they mostly do not use any laziness.