From 93100a1c8f9773bd6e39d205e14f59e11ae93752 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Mon, 3 Oct 2022 14:39:45 +0100 Subject: [PATCH] Remove support for conditional definitions It was introduced for use cases associated with the global mechanism that was dropped in e3d13696c887ba849958c8980623d8ff45bb8a36 --- .../parsers/wikiparser/rules/fnprocdef.js | 19 ++++++------- .../parsers/wikiparser/rules/macrodef.js | 11 +++----- core/modules/widgets/setvariable.js | 28 ++++++++----------- .../tw5.com/tiddlers/widgets/SetWidget.tid | 14 ---------- 4 files changed, 24 insertions(+), 48 deletions(-) diff --git a/core/modules/parsers/wikiparser/rules/fnprocdef.js b/core/modules/parsers/wikiparser/rules/fnprocdef.js index c42691eda..0f6618292 100644 --- a/core/modules/parsers/wikiparser/rules/fnprocdef.js +++ b/core/modules/parsers/wikiparser/rules/fnprocdef.js @@ -35,7 +35,7 @@ Instantiate parse rule exports.init = function(parser) { this.parser = parser; // Regexp to match - this.matchRegExp = /^\\(\??)(function|procedure|widget)\s+([^(\s]+)(\(\s*([^)]*)\))?(\s*\r?\n)?/mg; + this.matchRegExp = /^\\(function|procedure|widget)\s+([^(\s]+)(\(\s*([^)]*)\))?(\s*\r?\n)?/mg; }; /* @@ -46,12 +46,12 @@ exports.parse = function() { this.parser.pos = this.matchRegExp.lastIndex; // Parse the parameters var params = []; - if(this.match[4]) { - params = $tw.utils.parseParameterDefinition(this.match[5]); + if(this.match[3]) { + params = $tw.utils.parseParameterDefinition(this.match[4]); } // Is this a multiline definition? var reEnd; - if(this.match[6]) { + if(this.match[5]) { // If so, the end of the body is marked with \end reEnd = /(\r?\n\\end[^\S\n\r]*(?:$|\r?\n))/mg; } else { @@ -78,21 +78,18 @@ exports.parse = function() { children: [], params: params }]; - $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"name",this.match[3]); + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"name",this.match[2]); $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"value",text); - if(this.match[2] === "function") { + if(this.match[1] === "function") { parseTreeNodes[0].isFunctionDefinition = true; - } else if(this.match[2] === "procedure") { + } else if(this.match[1] === "procedure") { parseTreeNodes[0].isProcedureDefinition = true; - } else if(this.match[2] === "widget") { + } else if(this.match[1] === "widget") { parseTreeNodes[0].isWidgetDefinition = true; } if(this.parser.configTrimWhiteSpace) { parseTreeNodes[0].configTrimWhiteSpace = true; } - if(this.match[1] === "?") { - $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"conditional","yes"); - } return parseTreeNodes; }; diff --git a/core/modules/parsers/wikiparser/rules/macrodef.js b/core/modules/parsers/wikiparser/rules/macrodef.js index fc37416fe..59e82433d 100644 --- a/core/modules/parsers/wikiparser/rules/macrodef.js +++ b/core/modules/parsers/wikiparser/rules/macrodef.js @@ -27,7 +27,7 @@ Instantiate parse rule exports.init = function(parser) { this.parser = parser; // Regexp to match - this.matchRegExp = /^\\(\??)define\s+([^(\s]+)\(\s*([^)]*)\)(\s*\r?\n)?/mg; + this.matchRegExp = /^\\define\s+([^(\s]+)\(\s*([^)]*)\)(\s*\r?\n)?/mg; }; /* @@ -37,7 +37,7 @@ exports.parse = function() { // Move past the macro name and parameters this.parser.pos = this.matchRegExp.lastIndex; // Parse the parameters - var paramString = this.match[3], + var paramString = this.match[2], params = []; if(paramString !== "") { var reParam = /\s*([A-Za-z0-9\-_]+)(?:\s*:\s*(?:"""([\s\S]*?)"""|"([^"]*)"|'([^']*)'|\[\[([^\]]*)\]\]|([^"'\s]+)))?/mg, @@ -56,7 +56,7 @@ exports.parse = function() { } // Is this a multiline definition? var reEnd; - if(this.match[4]) { + if(this.match[3]) { // If so, the end of the body is marked with \end reEnd = /(\r?\n\\end[^\S\n\r]*(?:$|\r?\n))/mg; } else { @@ -84,11 +84,8 @@ exports.parse = function() { params: params, isMacroDefinition: true }]; - $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"name",this.match[2]); + $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"name",this.match[1]); $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"value",text); - if(this.match[1] === "?") { - $tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"conditional","yes"); - } return parseTreeNodes; }; diff --git a/core/modules/widgets/setvariable.js b/core/modules/widgets/setvariable.js index 6f804ba78..f8e98f390 100755 --- a/core/modules/widgets/setvariable.js +++ b/core/modules/widgets/setvariable.js @@ -47,21 +47,17 @@ SetWidget.prototype.execute = function() { this.setIndex = this.getAttribute("index"); this.setValue = this.getAttribute("value"); this.setEmptyValue = this.getAttribute("emptyValue"); - this.setConditional = this.getAttribute("conditional","no") === "yes"; - // Ignore if this is a conditional assignment and the variable already has a value - if(!this.setConditional || this.getVariableInfo(this.setName).text === undefined) { - // Set context variable - if(this.parseTreeNode.isMacroDefinition) { - this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,true); - } else if(this.parseTreeNode.isFunctionDefinition) { - this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true}); - } else if(this.parseTreeNode.isProcedureDefinition) { - this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace}); - } else if(this.parseTreeNode.isWidgetDefinition) { - this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isWidgetDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace}); - } else { - this.setVariable(this.setName,this.getValue()); - } + // Set context variable + if(this.parseTreeNode.isMacroDefinition) { + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,true); + } else if(this.parseTreeNode.isFunctionDefinition) { + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isFunctionDefinition: true}); + } else if(this.parseTreeNode.isProcedureDefinition) { + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isProcedureDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace}); + } else if(this.parseTreeNode.isWidgetDefinition) { + this.setVariable(this.setName,this.getValue(),this.parseTreeNode.params,undefined,{isWidgetDefinition: true, configTrimWhiteSpace: this.parseTreeNode.configTrimWhiteSpace}); + } else { + this.setVariable(this.setName,this.getValue()); } // Construct the child widgets this.makeChildWidgets(); @@ -115,7 +111,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of */ SetWidget.prototype.refresh = function(changedTiddlers) { var changedAttributes = this.computeAttributes(); - if(changedAttributes.name || changedAttributes.filter || changedAttributes.select || changedAttributes.tiddler || (this.setTiddler && changedTiddlers[this.setTiddler]) || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes.emptyValue || changedAttributes.conditional || + if(changedAttributes.name || changedAttributes.filter || changedAttributes.select || changedAttributes.tiddler || (this.setTiddler && changedTiddlers[this.setTiddler]) || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes.emptyValue || (this.setFilter && this.getValue() != this.variables[this.setName].value)) { this.refreshSelf(); return true; diff --git a/editions/tw5.com/tiddlers/widgets/SetWidget.tid b/editions/tw5.com/tiddlers/widgets/SetWidget.tid index c01736e4c..dbd8f70b3 100644 --- a/editions/tw5.com/tiddlers/widgets/SetWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/SetWidget.tid @@ -23,7 +23,6 @@ The content of the `<$set>` widget is the scope for the value assigned to the va |filter |An optional filter to be evaluated and assigned to the variable (see "Filtered List Variable Assignment" below). The variable can be used with the <<.olink enlist>> operator | |select |<<.from-version "5.1.14">> An optional zero-based index of the item to return from the filter output (see below) | |emptyValue |The value to assign to the variable if the specified value is missing or empty (see below) | -|conditional |<<.from-version "5.3.0">> If set to "yes" then the assignment only occurs if the variable does not already have a value (defaults to "no") | <<.tip """If the value of your variable is enclosed in double square brackets this might indicate that you are returning a list of values from the filter. To use a single title from the filter output without the double square brackets see ''Filtered Item Variable Assignment'' below.""">> @@ -55,19 +54,6 @@ src='<$set name=anotherVariable value="myVariable"> <<< -!! Conditional Variable Assignment - -This form of the set variable widget chooses one of two specified values according to whether a filter evaluates to an empty list. Here's an example that sets a variable according to whether the current tiddler is called "myMagicTitle": - -<<< - -<$macrocall $name='wikitext-example-without-html' -src="""<$set name="myVariable" filter="[all[current]field:title[myMagicTitle]]" value="It's magic" emptyValue="It's not magic"> -<$text text=<>/> -""" /> - -<<< - !! Filtered List Variable Assignment This form of the set variable widget evaluates the filter and assigns the result to the variable as a space-separated list (using double square brackets for titles containing spaces).