Skip to content

Commit

Permalink
case regex: operator
Browse files Browse the repository at this point in the history
  • Loading branch information
CarpeDiemKopi committed Sep 23, 2019
1 parent ace7ed0 commit 14f03e0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
30 changes: 27 additions & 3 deletions core/modules/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ function parseFilterOperation(operators,filterString,p) {
// The raw suffix for older filters
operator.suffix = operator.operator.substring(colon + 1);
operator.operator = operator.operator.substring(0,colon) || "field";
if (operator.operator == "regexp") {
// Cd.K
console.log("filter.js 51 operator 'regexp'")
}
// The processed suffix for newer filters
operator.suffixes = [];
$tw.utils.each(operator.suffix.split(":"),function(subsuffix) {
Expand All @@ -71,6 +75,11 @@ function parseFilterOperation(operators,filterString,p) {
break;
case "[": // Square brackets
nextBracketPos = filterString.indexOf("]",p);
// Cd.K
if (operator.operator == "regexp") {
// Cd.K
nextBracketPos = filterString.lastIndexOf("]]");
}
break;
case "<": // Angle brackets
operator.variable = true;
Expand Down Expand Up @@ -117,9 +126,17 @@ exports.parseFilter = function(filterString) {
filterString = filterString || "";
var results = [], // Array of arrays of operator nodes {operator:,operand:}
p = 0, // Current position in the filter string
match;
match,
matchregexp;
var whitespaceRegExp = /(\s+)/mg,
operandRegExp = /((?:\+|\-|~|=)?)(?:(\[)|(?:"([^"]*)")|(?:'([^']*)')|([^\s\[\]]+))/mg;
operandRegExp = /((?:\+|\-|~|=)?)(?:(\[)|(?:"([^"]*)")|(?:'([^']*)')|([^\s\[\]]+))/mg,
// Cd.K check regex:
regexpRegExp = /\[regexp:/mg;
// ?=? several regexp: conditions with or and possible??
if (regexpRegExp.exec(filterString)) {
console.log("Cd.K 'regexp:' in filter case");
}

while(p < filterString.length) {
// Skip any whitespace
whitespaceRegExp.lastIndex = p;
Expand All @@ -132,7 +149,14 @@ exports.parseFilter = function(filterString) {
operandRegExp.lastIndex = p;
match = operandRegExp.exec(filterString);
if(!match || match.index !== p) {
throw $tw.language.getString("Error/FilterSyntax");
// Cd.K
matchregexp = regexpRegExp.exec(filterString);
if (!matchregexp) {
throw $tw.language.getString("Error/FilterSyntax");
}
else {
console.log("Cd.K found regexp: condition in filter")
}
}
var operation = {
prefix: "",
Expand Down
15 changes: 14 additions & 1 deletion editions/_branch/tiddlywiki.info
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,18 @@
"build": {
"index": [
"--rendertiddler","$:/core/save/all","escape.html","text/plain"],
}
"empty": [
"--rendertiddler","$:/core/save/all","empty.html","text/plain",
"--rendertiddler","$:/core/save/all","empty.hta","text/plain"],
"externalimages": [
"--savetiddlers","[is[image]]","images",
"--setfield","[is[image]]","_canonical_uri","$:/core/templates/canonical-uri-external-image","text/plain",
"--setfield","[is[image]]","text","","text/plain",
"--rendertiddler","$:/core/save/all","externalimages.html","text/plain"],
"static": [
"--rendertiddler","$:/core/templates/static.template.html","static.html","text/plain",
"--rendertiddler","$:/core/templates/alltiddlers.template.html","alltiddlers.html","text/plain",
"--rendertiddlers","[!is[system]]","$:/core/templates/static.tiddler.html","static","text/plain",
"--rendertiddler","$:/core/templates/static.template.css","static/static.css","text/plain"]
}
}

2 comments on commit 14f03e0

@TiddlyTweeter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as a fork to leverage simpler usage of JS regex in filters I like it.

Regarding whether it shoulf be in core see my comment here: Jermolene#4267 (comment)

@CarpeDiemKopi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bug in core. See my answer to your comment here: TW #4267

Please sign in to comment.