From 37bb75f0cf446d62eb45d07b9f9b0aa14814a43f Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 10 Jun 2019 17:54:20 +0100 Subject: [PATCH] Add support for `=` prefix for filter runs that doesn't remove duplicates --- core/modules/filters.js | 6 +++++- editions/tw5.com/tiddlers/concepts/Dominant Append.tid | 6 +++++- .../tiddlers/filters/syntax/Filter Expression.tid | 10 ++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/core/modules/filters.js b/core/modules/filters.js index a1c4d8750..b00082bd1 100644 --- a/core/modules/filters.js +++ b/core/modules/filters.js @@ -119,7 +119,7 @@ exports.parseFilter = function(filterString) { p = 0, // Current position in the filter string match; var whitespaceRegExp = /(\s+)/mg, - operandRegExp = /((?:\+|\-|~)?)(?:(\[)|(?:"([^"]*)")|(?:'([^']*)')|([^\s\[\]]+))/mg; + operandRegExp = /((?:\+|\-|~|=)?)(?:(\[)|(?:"([^"]*)")|(?:'([^']*)')|([^\s\[\]]+))/mg; while(p < filterString.length) { // Skip any whitespace whitespaceRegExp.lastIndex = p; @@ -248,6 +248,10 @@ exports.compileFilter = function(filterString) { return function(results,source,widget) { $tw.utils.pushTop(results,operationSubFunction(source,widget)); }; + case "=": // The results of the operation are pushed into the result without deduplication + return function(results,source,widget) { + Array.prototype.push.apply(results,operationSubFunction(source,widget)); + }; case "-": // The results of this operation are removed from the main result return function(results,source,widget) { $tw.utils.removeArrayEntries(results,operationSubFunction(source,widget)); diff --git a/editions/tw5.com/tiddlers/concepts/Dominant Append.tid b/editions/tw5.com/tiddlers/concepts/Dominant Append.tid index ed0eb8544..59e79d6c7 100644 --- a/editions/tw5.com/tiddlers/concepts/Dominant Append.tid +++ b/editions/tw5.com/tiddlers/concepts/Dominant Append.tid @@ -1,5 +1,5 @@ created: 20150123220223000 -modified: 20150917193646675 +modified: 20190610165255223 tags: Filters title: Dominant Append type: text/vnd.tiddlywiki @@ -9,3 +9,7 @@ type: text/vnd.tiddlywiki This is done in such a way that, if a title would be duplicated, the earlier copy of that title is discarded. The titles being appended are dominant. For example, if a selection contains `Andrew Becky Clara Daniel` and `Andrew Barney Clara Daisy` is then appended to it, the result is `Becky Daniel Andrew Barney Clara Daisy`. + +This behaviour can cause unexpected results when working with [[Mathematics Operators]]. For example, `1 2 3 +[sum[]]` evaluates to `6`, as expected. But `1 1 1 +[sum[]]` evaluates to `1`. Removing the `+[sum[]]` from each filter reveals the problem: `1 2 3` evaluates to the list `1`, `2`, `3`, while `1 1 1` evaluates to the single item `1` due to de-duplication. + +In such situations, the `=` prefix can be used to disable the de-duplication. For example, `=1 =1 =1 +[sum[]]` evaluates to `3` as expected. Alternatively, the [[split Operator]] can be used: `[[1,1,1]split[,]sum[]]`. diff --git a/editions/tw5.com/tiddlers/filters/syntax/Filter Expression.tid b/editions/tw5.com/tiddlers/filters/syntax/Filter Expression.tid index 8550fa394..a01aa56ec 100644 --- a/editions/tw5.com/tiddlers/filters/syntax/Filter Expression.tid +++ b/editions/tw5.com/tiddlers/filters/syntax/Filter Expression.tid @@ -1,5 +1,5 @@ created: 20150124182421000 -modified: 20181120125803533 +modified: 20190610165329062 tags: [[Filter Syntax]] title: Filter Expression type: text/vnd.tiddlywiki @@ -7,7 +7,7 @@ type: text/vnd.tiddlywiki <$railroad text=""" [{: [: [[whitespace|"Filter Whitespace"]] ] - ("+"|"~"|:-|"-") + ("+"|"~"|:-|"-"|"=") [[run|"Filter Run"]] }] """/> @@ -17,6 +17,7 @@ A <<.def "filter expression">> is the outermost level of the [[filter syntax|Fil If a run has: * no prefix, its output titles are [[dominantly appended|Dominant Append]] to the filter's output +* <<.from-version "5.1.20">> the prefix `=`, output titles are appended to the filter's output without de-duplication * the prefix `-`, output titles are <<.em removed>> from the filter's output (if such tiddlers exist) * the prefix `+`, it receives the filter output so far as its input; its output then <<.em "replaces">> all filter ouput so far and forms the input for the next run * <<.from-version "5.1.18">> the prefix `~`, if the filter output so far is an empty list then the output titles of the run are [[dominantly appended|Dominant Append]] to the filter's output. If the filter output so far is not an empty list then the run is ignored @@ -24,7 +25,8 @@ If a run has: In technical / logical terms: |!Run |!Interpretation |!Output | -|`run` |union of sets |... OR run | +|`run` |de-duplicated union of sets |... OR run | +|`=run` |union of sets without de-duplication |... OR run | |`+run` |intersection of sets |... AND run | |`-run` |difference of sets |... AND NOT run | |`~run` |else |... ELSE run | @@ -32,7 +34,7 @@ In technical / logical terms: The input of a run is normally a list of all the non-[[shadow|ShadowTiddlers]] tiddler titles in the wiki (in no particular order). But the `+` prefix can change this: |Prefix|Input|h -|`-`, `~` or none| <$link to="all Operator">`[all[]]` tiddler titles, unless otherwise determined by the first [[filter operator|Filter Operators]]| +|`-`, `~`, `=` or none| <$link to="all Operator">`[all[]]` tiddler titles, unless otherwise determined by the first [[filter operator|Filter Operators]]| |`+`|the filter output of all previous runs so far| Precisely because of varying inputs, be aware that both prefixes `-` and `+` do not behave inverse to one another!